Object avoidance

This is one of the most interesting features that you want for your autonomous robot. If your ATTLER is still using CUBE pilot and running on Ardupilot firmware, I highly recommend you to go check out this documentation first

https://ardupilot.org/rover/docs/common-object-avoidance-landing-page.html

If you have followed that instruction and success, you may don’t need to read mine after this 🙂

This time, I would like to try use the object avoidance feature which called “Bendy-Ruler” and “Simple avoidance”. Simple avoidance is a basic avoidance that will make the rover stop when it found out an obstacle in the range, and will slightly go backward and lean to one side to try get rid of that obstacle out of the range. Bendy ruler will make the desired path bending around the obstacle by looking to an open space. These are just an algorithm that can be applied to any of distance sensor as you wish, it could be depth camera, TOF sensor, LIDAR, range finder or anything.  

Hardware

In this tutorial, we are using 360 LIDAR 2D scanner from the company YDLIDAR https://www.ydlidar.com with TG30 model. It’s quite cheap and has nice SDK to work with and they also have a ROS package for that. But in our case, we will use just their SDK and some of our python code.

Ardupilot also has a list of supported hardware for a proximity sensor that they already made a driver in their firmware. But we can still use any of sensor for a detection as we want by making our own driver and send the MAVLink message back to the CUBE. So we will use Jetson Nano as a companion computer to make a driver for the YDLIDAR and send it those information back to the flight controller. In order to do that we need to have a board call USB-to-UART converter, which will allow us to let the Jetson Nano talks to CUBE. I am using this kind of board https://www.digikey.com/catalog/en/partgroup/pmodusbuart-reference-board/73013 , but there is a bunch of different converter that works the same thing. So you can try use any of what you can find.

And it would be much better that you can provide yourself a precise position system when you are testing this feature. I found that when I first tested this with Here3 (M8P) GPS, with the base station for RTK-GPS, it was rarely got RTK-fixed and the rover was jumping around. That’s really hard to understand the problem during tuning the parameters, because the accuracy of GPS was poor :(. So this time I changed GPS to F9P and also extended the pole a bit higher, that helps me a lot to get an accurate position and the rover didn’t jump anymore. 

These are three basic components that I have modified for this test, other than that is pretty much same as first time set up on ATTLER basic.

Parameters

  • GPS_TYPE = 1                        (AUTO, I am using F9P)
  • SERIAL2_PROTOCOL = 2     (for MAVLINK 2)
  • SERIAL2_BAUD = 921          (this should be same on our code) 
  • OA_TYPE = 1                         (for Bendy ruler algorithm)
  • OA_MARGIN_MAX = 0.7.    (rover will stay away with object with this value in meter)
  • OA_DB_OUTPUT = 3           (send all items to visible on the map)
  • OA_BR_LOOKAHEAD = 2    (look ahead up to 2 meters)
  • OA_DB_EXPIRE = 2              (object in data base will disappear in 2 second)
  • AVOID_ENABLE = 2             (Use only proximity sensor, for simple avoidance)
  • AVOID_MARGIN = 1            (simple avoidance will start to work when object is close to this distance, in meters)
  • PRX_TYPE = 2                        (to use proximity sensor from MAVLINK message)
This is just some guide line that will help you what you need to change. But of course you may need to adjust it to match with your rover avoiding performance. WP_SPEED is also one of the key because if your rover is faster than the sensor to detect things in front of it, it will end up that the rover will hit the object. 
If you would like to use Bendy-Ruler and Simple avoidance in the same time like me, please be careful on OA_BR_LOOKAHEAD, OA_MARGIN_MAX and AVOID_MARGIN. Some time your rover will end up like doing just simple avoidance and never had a chance to do Bendy-Ruler, so you may need to adjust the distance parameters properly.  

Codes

If you just want to see the codes I am using, just go check out on my GitHub repo here

https://github.com/rasheeddo/testYDLidar

https://github.com/rasheeddo/ATCart-AP-lidar

The first one testYDLidar is sample code that I got from YDLidar SDK, and modified it to send 72 distances data out to the second script AP_object_avoidance.py . This script will communicating with CUBE via UART2 (TELEM2) with that USB-UART converter mentioned above.  The information of 72 distances is packed in the MAVLink message under OBSTACLE_DISTANCE and there are some parameters that we need to specify like max_distance, min_distance, offset_angle, increment and etc. You can check more detail on AP_object_avoidance.py , I think the code itself is explaining everything.