Low cost and well performing object avoidance

object avoidance is always one of the interesting option in multirotors and now we can see this option in DJI Phantom series.
but most of the time they are expensive for example one of them are TeraRanger Tower Evo starting from 445 $
in this post we will make an object avoidance system with 5 HC-SR04 ultrasonic sensor and one arduino nano.

LARGE
As shown above, five inexpensive ultrasonic sensors HC-SR04 were used for object detection in the front, right, rear, left and down direction. Arduino microcontroller acts as the processor for the receiving sensor data and generate responses accordingly. Arduino Nano was used because of its small size and relatively lighter weight. The Arduino connections with all sensors were sketched and the complete circuit diagram was drawn.


the system was connected to the FC through the telemetry serial port. 5V and ground completes the supply circuit to power the Arduino Nano, while Transmitter (TX) pin of the FC was connected to Receiver (RX) pin of Arduino Nano. Similarly, RX pin of the FC was connected to TX pin at the Arduino.

Connection points required were being precisely and tightly soldered on a copper board. Jumpers were used to ease out connections and female header pins were soldered on place for the installation of ultrasonic sensors in each direction, as shown below. capacitors and resistors were added to improve consistency of each sensor.


The software of the object avoidance system was built with the Arduino Software (IDE). For distance measurement, NewPing library was used to retrieve raw sensor data directly in centimetre. To improve overall sensor data consistency, averaged value of 5 sensor readings were taken. It was learnt that sonar outputting zero distance is not uncommon. It happens when the distance of the object is out of the detection range, or when there is a directional uncertainty. To avoid the average values getting affected by such errors, only average values with at least 4 non-zero readings are taken, otherwise discarded.

Pitch and roll responses can be realised by sending mavlink pakages containing signals to override the existing roll and pitch value. From the data flash logs, the input RC channel shows a value nearing 1500 for both pitch and roll values when the quadcopter is stable. When the quadcopter pitches nose down, the value drops below 1500, whereas when pitched up, the value rises above 1500 in the pitch channel. Likewise, when the quadcopter tilts to the right, it rises above 1500, in the roll channel, and vice versa.

This piece of information is vital because the Mavlink messages that were sent from the Arduino microcontroller to the FC will be the messages to override those values in the respective radio channels. The Arduino software was coded in a way that the change in roll-pitch values increase when the nearest distance detected reduces.

source code
video

9 Likes

Why use the Mavlink Override when the newest copter version supports obstacle avoidance sensors via Mavlink?
http://ardupilot.org/copter/docs/copter-object-avoidance.html#copter-object-avoidance

we are using Mavlink Override because of we want to it usable on all boards with any version of Ardupilot like Navio , apm and ā€¦

Unless if you are using the old apm board, all others are supporting avoidance and proximity lib !
Override are pretty unsafe as you are doing open loop control.
Implementing the distance sensor or distance obstacle message would be safer and permit to use the build with the new pathplanning lib that we made !
But be careful with those sonar, they arenā€™t very reliable.
Thanks you for sharing anyway ! That is very nicely done and written !

Thanks for advice and feedback
I will work on an update to make it safer

1 Like

Have you done any more work on this project - changes to make it safer or more reliable?

Those cheap ultrasonic sensors are more trouble than they are worth in my opinion. And thatā€™s saying a lot when they are $5ā€¦

They are even cheaper than that - I can get 5 of them for US$7 including shipping ā€¦ :open_mouth:

By ā€œtroubleā€ do you mean functionality or outright reliability?

Do you have a reccommendation for a better alternative that doesnā€™t cost the earth - this is just a hobby for me, so I donā€™t need commercial standard performance, but it does need to be reliable.

Functionality. I have tried them on Copter and Rover and it was more an annoyance than a help for avoidance. I havenā€™t tried another device but it would be Lidar if I did.

unfortunately still no
they are not arenā€™t very reliable as @khancyr and @dkemxr said, and as i tested you can use them indoor area with few objects around

What are the parameters that you changed on the mission planner to be able to see all the 5 distances on the mission planner?
IN arduino IDE I can see the values of the sensor measures but when I want to see them on mission planner , I can only see one of them working.
@hosein_gh

Hi, i m trying to Compiling/upload the code but i get errors (C:\Users\shaof\OneDrive\Apuntes\4 Grado\2 Semestre\TFG\Arduino\libraries\mavlink\common\mavlink.h: No such file or directory
) but if i uncomment that line then i get these errors (variable or field ā€˜RCOverrideā€™ declared void) and this message gets highlighted (RCOverride(mavlink_message_t *msg, uint16_t len, uint8_t *buf, uint16_t PitchOut, uint16_t RollOut) {) can you plz send me a code that has no errors. plus the schematics you posted is not visible properly. m totally new to this projectā€¦ please help. thanks.

Hi @SajidRahim84
in arduino IDE go to Tools > Manage Libraries then search for mavlink and install it

I already installed mavlink. But for some reason m not able to compile the code. I dont know what to do.

please share console windows messages while its faild

hi, attached is the screen shot of the failed codeā€¦

Hi below is the attached screen shot of the error m getting.

It seems that its a path problem
After installing mavlink simply import it like <mavlink.h>

and how should i do that?

ok i guess i figured it out and the code compiledā€¦ the file path was wrong in the code as you saidā€¦ i set the file path to where mavlink.h was saved and now i am able to compile the codeā€¦

1 Like