Obstacle Avoidance for Quadcopter using Ultrasonic Sensor

An obstacle avoidance system is being proposed. The system will combine available flight controller with a proposed avoidance method as a proof of concept. Quadcopter as a UAV is integrated with the system which consist of several modes in order to do avoidance. As the previous study, obstacle will be determined using ultrasonic sensor and servo. As result, the quadcopter will move according to its mode and successfully avoid obstacle.


Introduction
Application of obstacle avoidance in UAV is highly needed nowadays since it grows rapidly. The avoiding system consist of two main parts which consist of detecting obstacle within a safe operation range and determining a safe flightpath in avoiding the obstacle [3].
Several flight controllers have been used widely but none of them include an obstacle avoidance system. Previous paper discussed the obstacle detection using ultrasonic sensor [1] and this paper discussed about its implementation in quadcopter. The detected obstacle will be used as a data to construct an ellipsoid restricted zone to determine the avoidance path. Figure 1 illustrate the ellipsoid restricted zone which will be used to generate a contact point as the guidance. It use an optimal path between the heading angle, flight velocity, ellipsoid shape, and clearance [5]. The method is in default used for a fixed wing type of aircraft. Since this research uses quadcopter, some adjustment to the flight manoeuvre and a simpler contact point algorithm is used. 2. Hardware Designed system should be able to avoid the obstacle using on board processing. Flight between waypoints will be provided by the flight controller and the avoidance will be performed by microcontroller. All the hardware mentioned on previous section combined as shown in Figure 3.

Arduino
Arduino UNO is a microcontroller using ATMmega328. It provides 14 digital input/output pins (including 6 PWM output pins), 6 analog pins, USB connection, and a power connector [6]. It will be used to receive information from sensor, communicate with ground station, and control another device to perform obstacle avoidance.

Pixhawk
Pixhawk is an open source autopilot or flight controller developed by Computer Vision and Geometry Lab of ETH Zurich and Autonomous System Lab with collaboration from other researchers. Developed from 3DRobotics and ArduPilot Group, Pixhawk mainly used for hobby, academic, and industrial purposes.
On this research, quadcopter firmware is used to match the platform. User input comes with a pulse-position modulation (PPM) signal and the output is pulse-width modulation (PWM) signals. Since Arduino as the microcontroller only provides PWM signal output, PWM to PPM converter module is used to match the communication.

Ultrasonic Sensor
HRLV-MaxSonar-EZ Products is an ultrasonic sensor provided by MaxBotix. The sensor capable of 1 mm resolution with maximum range of 5000 mm. Object closer than 30 cm will be counted as 30 cm. Another specification is the output signal comes in various form such as analog voltage, RS232 or TTL serial, and pulse-width. The sensor operates from 2.5V to 5.5V. With all the specification and its small and light weight criteria, the sensor is suitable for research application yet comes within affordable price.

Servo Gimbal
Servo gimbal used in this research is a 2-axis gimbal, in pan and tilt axis. Pan axis used in obstacle detection by using it to rotate ultrasonic sensor within defined angle. The tilt axis function as a stabilizer so the ultrasonic will always pointed frontward.

Telemetry
Several data such as distance to obstacle, time stamp, mode, and user input need to be recorded so further analysis can be done. Telemetry is the easiest way to record the data. All those variables inside microcontroller will be sent to laptop via Arduino IDE Serial Monitor. The data stored in excel file and being processed later.

Airframe
Quadcopter is chosen as the airframe. First consideration is this type of airframe have the ability to hover so lower computing ability of microcontroller is acceptable. Another one is the control requirement is relatively simple as user command directly turns into a non-coupling movement of the quadcopter. All the components have been mounted to the aircraft as shown in figure 3.

Microcontroller Algorithm 3.1. Obstacle Avoiding Algorithm
The main mission of this algorithm is to enable the quadcopter fly between predefined waypoints and to avoid obstacle between those waypoint if it exist. There are 5 mode for the algorithm from the quadcopter starts to take-off manually, fly autonomously, and avoiding the obstacle. Several parameters are made as switch between modes. First parameter is clear distance, defined as the minimum distance the quadcopter can fly autonomously. Another one is safe distance as the minimum distance the quadcopter can start scanning. On the avoidance mode where quadcopter aimed to fly forward and side at the same time, the distance to obstacle should've decreased. So another parameter is defined that is clear to avoid distance, which the quadcopter should not move any closer than this distance when avoiding the obstacle. Illustration of the parameters is shown in Figure 4. Position Hold, or generally known as PosHold, is a flight mode which designed to maintain a constant location, heading, and altitude by utilizing data from inertial measurement unit (IMU), GPS module, and compass. This flight mode is preferable rather than others since it provide a natural control sense by directly control vehicle's lean angle based on pilot stick inputs [7].
To control horizontal position on the ground, roll and pitch control stich is utilized with default maximum lean angle of 45 degrees. It means when the stick hit the maximum position on the remote control, the command will be interpreted as attitude reference to keep lean angle at that position. This maximum lean angle can be adjusted with ANGLE_MAX parameter using ground station control [7].
Autonomous mode, known as Auto, is a flight mode which enabled the quadcopter to follow a pre-programmed mission script which is stored in the flight controller by setting waypoints as the navigation command and some other action command [ardupilot.org]. Since this flight mode combine altitude hold (AltHold) and Loiter to control altitude and position, an attempt of those flight mode should be done before utilizing this Auto. As well as the positon hold, Auto flight mode require the same conditions applied before it can take-off.
Keep distance mode is a part of avoidance mode which prevent the quadcopter from hitting the obstacle. This mode is activated whenever the quadcopter distance to obstacle is less than safe distance. Autonomous mode will be switch to position hold mode and microcontroller will send signal to flight controller to fly backwards based on measured distance to the obstacle. The rate of quadcopter fly backwards decreases as the distance to obstacle increases. The avoiding process will be start from scanning the obstacle first during scanning mode. Since ultrasonic sensor only capable of measuring distance for a single point, it will be rotated by using servo. Rotating ultrasonic is in limited angle since reflection angle higher than 25 degree will not be detected [2]. These data later will be quantified into an elliptical shape obstacle and a contact point will be resulted as path planning method result. Figure 5 shows the relation between autonomous flight and the avoidance procedure. Keep distance, scanning, and avoidance mode is represented by fly backwards block, start scanning, and execute avoidance manoeuvre respectively. All these mode is depended on the sensor measurement.
After the contact point is obtained, the quadcopter changes to avoiding mode. In this mode, microcontroller send PWM signal to pitch and roll channel based on the planned path. Quadcopter will change to waypoint following mode after the obstacle is already passed. It happens when the measured distance is more than the clear distance. Since quadcopter needs to approach the obstacle first, it is possible that the quadcopter fly too close to the obstacle. Therefore, the flying mode will switch to keep distance.

Signal Processing Algorithm
The quadcopter used ultrasonic as a sensor to measure distance and the data will be used to trigger the avoidance mode. During flight, the measurement experience noise which will disturb the flight mode. Therefore, a filter should be applied to reduce those noise.
Filter used in this research is a moving median. This filter have a purpose to remove an outlier in the data which can be interpreted as noise. For instance, there are six data to be computed its median and there is one data which is relatively high than the others. This data will be sorted to the end of the window set and never used as data [8].  Figure 6 shows the result of these median filter with 11 data window applied to a moving quadcopter. It is noticed that some noise successfully reduced as in 18 seconds in sub-figure (a) and in 12 second in sub-figure (b). This noise can cause the quadcopter directly switched to keep distance mode but fortunately stay at autonomous mode because of the filter.

Results and Discussion
Two avoiding scenarios being tested, which result all flight mode being tested. Firstly, the quadcopter's waypoint navigation speed is at 75 cm/s and the second one is at 60 cm/s. The distance parameters interval is set at constant which is 210 to 140 cm to available for scanning. Gain for the avoidance maneuver is set to be 40 value which will affect the speed during avoiding.  Figure 7 and 8 show roll and pitch command during flight test. From around 3.5 to 5 seconds the signal goes low in a constant value for roll and decreasing value for pitch which shows the quadcopter is moving to left and near the obstacle to avoid it. While 5 to 6 seconds is the keep distance maneuver which is shown by a positive pitch which means the quadcopter is fly backwards.   Figure 9 shows the measured distance and the flight mode as shown by Arduino. It is shown that the quadcopter slowly reduces it distance and successfully avoid the obstacle when the measurement is raising to about 500 cm. The rest shows a constant reading except for an error which does not change the flight mode.  Figure 10 shows the elliptical quantification result from the Arduino. The blue point, which shows the contact point is not located in the ellipsoid due to a roundup error. The blue-star is the indicator of measured obstacle in front of it which is acceptable since the quadcopter is in fact do not fly perpendicular to the obstacle when it start to scan. Figure 11 shows the trajectory of quadcopter which successfully follow this guidance but then it fly too close to the obstacle and switch to keep distance mode to avoid crash.   Figure 14 shows the distance is decreased start from 5 to the next 2.5 seconds. It is the measurement when the quadcopter fly near the obstacle. Next is the sudden raise which shows the obstacle is avoided and the flight mode changed to autonomous mode until it completes the whole mission.  Figure 15 shows the elliptical quantification in this second test flight. As the previous case, the quadcopter tend to turn left as it is the most optimal path for this method. The trajectory, as shown in figure 16, shows the quadcopter successfully follow the guidance and keep it from hitting the obstacle before finally turn to autonomous mode again. In the early maneuver of avoidance mode, the quadcopter fly in combination command between roll and pitch and the next maneuver mostly consist only in roll direction since the quadcopter keep it distance to the obstacle. As a comparison, different waypoint navigation speed lead to different measured distance when the quadcopter enter the scanning mode. A faster velocity means closer obstacle when it start to avoid. This can be an adjustment when the quadcopter fly at a higher speed that the clear distance can be reduced.

Conclusion
The implementation of obstacle avoidance for quadcopter using ultrasonic sensor have been done. The result shows that quadcopter successfully change mode to avoiding mode or keep distance mode when 13 1234567890 ''"" the obstacle's distance is less than defined distance parameter. The quadcopter then switch to scanning mode and result a set of distance from rotating ultrasonic. When obstacle is not detected, the quadcopter will switch to autonomous mode and continue waypoint following.
All flight command, attitude, and trajectories have proven the quadcopter can avoid the obstacle. An additional evidence of the measured distance also have been shown with its flight mode. Though, a more various flight speed and avoiding speed should be conducted.