Obstacle avoidance for indoor drone flight!

Recently we evaluated performance of indoor obstacle avoidance on a quacopter with Pixhawk running ArduPilot and equipped with a TeraRanger Tower and TeraRanger Evo distance sensor for drones. This report presents our setup and the results.

Parts used:

Obstacle avoidance indoor drone

Drone object avoidance in Arducopter

In version 3.5, ArduCopter introduced object avoidance in Loiter and AltHold modes. By using TeraRanger Tower you can implement the object avoidance feature on your aircraft.

In both Loiter and AltHold modes the area around the vehicle is divided into 8 sectors, with sector 0 pointing forward by default:

Obstacle avoidance for indoor drone flight - 8 detection areas

When setting up the TeraRanger Tower on the drone it is important to make sure that the sensor labeled on the TeraRanger Hub PCB board as TR0 is the one that is pointing forward.

TeraRanger Tower setup

When mounting the tower on the drone it is important to take into account the 3 degrees Field of View of the TeraRanger sensors and their emitted light to ensure that the Field of View is not obstructed by the aircraft frame or propellers. For safety, we usually mount the sensors with about 15 degrees clearance (see picture below).

drone collision avoidance - field of view

If you are not sure if your propellers are in the Field of View of the sensor you can perform a static test using the TeraRangerHub GUI and manually change propeller positions to see if the readings are affected.

We connected the Tower to Pixhawk following this diagram (make sure you are connected to U3 port on the TeraRanger Hub board):

Drone obstacle avoidance Pixhawk - hub connection

To provide power to the board we made a connection between the drone power distribution board and the U1 port on the TeraRanger Hub PCB. With this setup we are using unregulated battery power (10-20V is the accepted voltage of TeraRanger Hub). Since we are using 3S LiPo batteries the voltage provided to the board is within range (~12.60V when the battery is fully charged).

TeraRanger Evo – Altimeter setup

In our setup we use a TeraRanger Evo as an altimeter. At the time of writing, the Evo drivers hadn’t made it to the official ArduCopeter 3.5 release, however, they are supported on the development branch (instructions on getting the development version can be found in chapter 3.2 of our connection instructions).

Obstacle avoidance Pixhawk - Evo connection

Evo i2c backboard pins Pixhawk i2c port pins
1 Tx
2 Rx
3 GND
4 SDA 3 SDA
5 SCL 2 SCL
6
7 VCC 1 VCC
8 GND 4 GND
9

Obstacle Avoidance in Loiter mode

We originally showed object avoidance in Loiter mode in our video last year: 

In Loiter mode, thanks to sensor data filtering and position information from GPS, the autopilot has high-quality information on it’s speed and acceleration with respect to the ground (groundspeed and groundacceleration). By using a sensor array system, such as TeraRanger Tower, the autopilot can get information on how far away it is from obstacles that are in the sensors fields of view. Knowing how fast the multirotor is travelling towards the obstacle, and having precise distance information from said obstacle, allows the autopilot to request a horizontal acceleration in time to stop the drone at a predefined distance from the obstacle. Since this mode is highly dependent on position information (usually obtained from the GPS) it will not work if GPS is not available, but could potentially harness other positioning systems like an optical flow camera, or motion capture system.

Drone obstacle avoidance in Altitude Hold

Things get very interesting with Altitude Hold mode. Since there is no position reference system (e.g. GPS) we don’t have precise information about where our drone is and in which direction it is actually flying.

Imagine flying a multirotor in a mode in which you have full control over thrust and roll and pitch angle. Let’s say that with 50% thrust you can keep your multirotor level at a fixed height, in such a case the generated thrust is in equilibrium with the aircraft weight. As soon as our aircraft has some roll angle, assuming you don’t increase thrust, your aircraft will start descending as the upward component of the thrust vector is not in equilibrium with the aircraft weight. The remaining thrust component will make the drone fly in the direction of roll. This concept is illustrated on the figure below.

obstacle avoidance sensor

By using altitude hold for indoor drone obstacle avoidance ArduCopter developers can ensure that the appropriate thrust is applied by the motor, so when the multirotor is banking or pitching we can be sure that the autopilot will do it’s best to keep the aircraft at the requested height. You can use a barometer for this task, however by using a TeraRanger rangefinder you will see much better performance in holding a fixed height.

As mentioned earlier in this case, the Pixhawk obstacle avoidance does not know how fast the drone is travelling but it can keep the fixed height. The obstacle avoidance has been solved by ArduCopter developers by creating a pitch/roll request based on the distance measurements received from all the sensors. The largest positive and negative roll and pitch angles are found and combined together resulting in a final roll/pitch angle. Those combined roll/pitch values are then fused with the pilot input. [Source: http://ardupilot.org/dev/docs/code-overview-object-avoidance.html#avoidance-in-althold].

At the time of our tests, the object avoidance library can request a lean angle of 75% of the maximum allowed lean angle (If you were to set ANGLE_MAX to 1000 centidegrees than the maximum transmitter stick input will translate to 10 degrees, while the input from the avoidance library will not be larger than 7.5 degrees). That means that, if you asked for a 75% roll command, thoeretically the aircraft should be level at the minimum distance set from the obstacle. This is not necessarily good! As discussed earlier, since the autopilot has no precise information on aircraft speed, your aircraft might be perfectly level but still have velocity in a horizontal direction! That is why we advise you, if you want to test the obstacle avoidance drone in Altitude Hold, to take it slow and build trust in the system first.

Usually, when AltHold mode is concerned, we advise our customers to set the AVOID_ANGLE_MAX and ANGLE_MAX to relatively low values. AVOID_ANGLE_MAX is the maximum angle that might be requested by the Object Avoidance library and ANGLE_MAX is the maximum lean angle in all flight modes.

Highlight of parameters of Altitude Hold mode

Here is a short highlight of the parameters we set on the Pixhawk that you see in the original video:

  • ANGLE_MAX: 1000
  • AVOID_ENABLE: 3
  • AVOID_DIST_MAX: 3.0
  • AVOID_ANGLE_MAX: 500
  • RNGFND_TYPE: 14
  • RNGFND_MAX_CM: 60000
  • RNGFND_ADDR: 49
  • SERIAL4_PROTOCOL: 11
  • SERIAL4_BAUD: 921

You can get our parameter file here.

Conclusions

TeraRanger Tower and TeraRanger Evo, when combined with Pixhawk running ArduCopter firmware, provide a strong solution for drone object avoidance in GPS-denied environments. The system is easy to set up and integrate. We advise any integrator to start tuning the system by setting small values of AVOID_DIST_MAX and ANGLE_MAX parameters, to get a good feel for the functionality, before making the system more aggressive.

Links:

Arducopter Object Avoidance wiki: http://ardupilot.org/dev/docs/code-overview-object-avoidance.html

TeraRanger Tower Avoidance wiki: http://ardupilot.org/copter/docs/common-teraranger-tower-objectavoidance.html

TeraRanger One Rangefinder wiki: http://ardupilot.org/copter/docs/common-teraranger-one-rangefinder.html

TeraRanger Evo Pixhawk instructions: https://www.terabee.com/connection-to-pixhawk-autopilots-teraranger-evo/