A drone synthetic environment development project based on Ardupilot, Gazebo & ROS.
https://github.com/yanhwee/ardupilot-gazebo-ros-guide
From the terminal:
wget -O - https://raw.githubusercontent.com/yanhwee/helium/master/docs/install.bash | bash
This installation script is modified based on the installation from https://github.com/yanhwee/ardupilot-gazebo-ros-guide. Refer to it for more details. It installs the following prerequisites and setups this repository. Note that this repository is a catkin package. Please restart after the installation.
- ArduPilot (Modified)
- ArduPilot Gazebo Plugin (Modified)
- Gazebo 9
- ROS Melodic
- MAVROS
- Catkin Workspace & Helium Package
- QGroundControl (QGC)
- Google Protobufs
- Generate Python Bindings for Gazebo Protobuf Messages
- Python Libraries
- pymavlink
- protobuf
- Open four terminals in the home directory (Tip: Ctrl-Alt-T + Ctrl-Shift-T x4)
- In each:
- roslaunch Gazebo world
roslaunch helium hills_lidar.launch
- Start ArduPilot SITL
sim_vehicle.py -v ArduCopter -f gazebo-iris
- Will need to compile (for first time)
- Wait for
APM: EKF2 IMU1 tilt alignment complete
before continuing to step 3 - Initialisation is completed when
APM: EKF2 IMU1 is using GPS
- Then you can start sending MAVLink commands & interface with MAVProxy
- Start MAVROS
roslaunch helium apm.launch
- Start QGroundControl
./QGroundControl.AppImage
- roslaunch Gazebo world
Note: Run it via the gnome terminal.
- Start:
bash run.bash
- Stop:
ctrl-c
- docs
- Contains documentation, diagrams, installation script, code examples
- launch
- Contains ROS launch files
apm.launch
starts MAVROS- The rest starts Gazebo worlds within ROS
- models
- Contains Gazebo models
- worlds
- Contains Gazebo worlds
- src
- Contains SITL Code
mavdrone.py
- Module for communicating with the drone via MAVLink
- Uses pymavlink beneath to handle MAVLink messages.
gazebo.py
- Module for retrieving Gazebo topic messages.
- Uses protobuf to parse
gztopic
text formatted messages.
time_mission.py
- Code example for uploading and timing drone missions
multi_drone.py
- Code example for multi_drone simulation
setup.bash
- Is sourced in
.bashrc
- Setups Gazebo world and model paths
- Is sourced in
- To change directory to helium quickly:
roscd helium
- During a mission land command, if terrain following is enabled, the drone will keep flying higher.
For ArduCopter Version: 4.0.4-dev
In Forked Repositories:
-
ArduPilot
https://github.com/yanhwee/ardupilot -
ArduPilot Gazebo Plugin (khancyr)
https://github.com/yanhwee/ardupilot_gazebo
-
References
-
Walk-through
-
SIM_Gazebo
- Modify the FDM Packet to receive the rangefinder value.
- Then, moidfy the function that updates the range value (in SIM_Gazebo) using the received rangefinder value.
-
ArduPilotPlugin.hh/.cc
- Modify the FDM Packet to take in the rangefinder value.
- Use Gazebo transport node to read laser topic messages published by laser ray model.
-
Gazebo
- Create a model file for Lidar.
- Use ray sensors with one laser.
- Add this lidar model to iris_with_ardupilot, using links and joints.
- Laser topic messages is automatically published.
-
-
ArduPilot Parameters
- References
- By QGroundControl or MAVProxy
- TERRAIN_ENABLE = 1 (Default)
-
Test
-
QGroundControl
- Select MAVLink Inspector
- Find Distance Sensor
- Plot, 60 secs (optional)
-
MAVProxy (Alternatively, less preferred way)
- https://ardupilot.org/dev/docs/using-sitl-for-ardupilot-testing.html#adding-a-virtual-rangefinder
- Don't
param set
anything - Just load the graph
-
-
References
-
Walk-through
-
Gazebo
- Create model file for 360 lidar.
- Ensure the lasers are setup in a "circular" manner
- Actually clockwise or not it doesn't matter
- Rather, ArduPilot parameter,
PRX_ORIENT
, controls the orientation of the proximity sensors
- Rather, ArduPilot parameter,
- Just ensure that
min_angle
starts from 0 - Don't overlap the first and last laser
<samples>n</samples> <min_angle>0</min_angle> <max_angle>-x<max_angle> <!-- where x = 2pi / n * (n - 1) -->
- Actually clockwise or not it doesn't matter
- Ensure the lasers are setup in a "circular" manner
- But this time, publish laser messages via MAVROS.
- Use a Gazebo Plugin, "libgazebo_ros_laser.so".
- Set publish topic target directly to "/mavros/obstacle/send".
- It is a mavros rostopic that takes in Gazebo laser messages.
- Put lidar model on top of the iris_with_ardupilot using links and joints.
- Create model file for 360 lidar.
-
Catkin Workspace
- Use roslaunch to run Gazebo. Create a launch file for that.
- This is for "libgazebo_ros_laser.so", to be able to publish laser messages to rostopic.
- Use roslaunch to run Gazebo. Create a launch file for that.
-
-
ArduPilot Parameters
- References
- By QGroundControl or MAVProxy
- AVOID_ENABLE = 7 (or any values that includes "Proximity Sensors")
- PRX_TYPE = 2 (MAVLink)
- PRX_ORIENT = 1 (Upside Down)
- OA_TYPE = 1 (BendyRuler)
-
Test
- Via Terminal
rostopic echo /mavros/obstacle/send
- QGroundControl
- Ensure ArduPilot Parameter,
OA_DB_OUTPUT
>= 2 (Send HIGH and NORMAL importance item) - Obstacle icons should show up on main GUI
- Ensure ArduPilot Parameter,
- Via Terminal
The current version of ArduCopter does not allow terrain following if object avoidance is enabled.
-
Walk-through
- Regardless whether OA is enabled,
AC_WPNav_OA
will always be used rather thanAC_WPNav
.AC_WPNav_OA::update_wpnav()
will always callAC_WPNav::update_wpnav()
at the end. The main problem lies withinAC_WPNav_OA
. AP_OAPathPlanner
uses threading to process and adjust the waypoints. Sometimes, it isn't ready and will returnAP_OAPathPlanner::OA_Processing
.- A switch case in
AC_WPNav_OA
handles the results. However, if theOAPathPlanner
is still processing, a false boolean will disable terrain following (for that waypoint). (This might be a bug?) - Since the check occurs so frequently, terrain following will be disabled for all waypoints throughout the mission.
- The fix is to replace the false boolean to
_terrain_alt
, a boolean that stores the state of terrain following, true if enabled and false otherwise.
- Regardless whether OA is enabled,
To be honest, the implementation for multi-drone simulation is very inelegant and unscalable.
-
References:
-
Walk-through
- Segregrate the FDM ports of the drone model so ArduPilot (sim_vehicle.py) can correctly connect to the drone plugin.
- Duplicate the existing drone model
iris_with_lidar
->iris_with_lidar_2
iris_with_ardupilot
->iris_with_ardupilot_2
- Change the include model (in
iris_with_lidar
)<uri>model://iris_with_ardupilot</uri>
-><uri>model://iris_with_ardupilot_2</uri>
- Change the FDM Ports by 10 (in
iris_with_ardupilot_2
)<fdm_port_in>9002</fdm_port_in>
-><fdm_port_in>9012</fdm_port_in>
<fdm_port_out>9003</fdm_port_out>
-><fdm_port_out>9013</fdm_port_out>
- Duplicate the existing drone model
- Create another MAVROS instance for the new drone
- Duplicate the existing
apm.launch
fileapm.launch
->apm2.launch
- Change certain parameters
- Increment
fcu_url
by 10 - Increment
target_url
by 1 - Add & Set
ns
to/drone2
- Increment
- Ensure that the new drone model use the new ROS topic
- Duplicate the lidar 360 model
lidar_360
->lidar_360_2
- Change the ROS topic name
/mavros/obstacle/send
->/drone2/mavros/obstacle/send
- Duplicate the lidar 360 model
- Duplicate the existing
- Fix QGroundControl to allow multiple drones
- Navigate to the ArduPilot Repository (
~/ardupilot/Tools/autotest
)- Duplicate the existing ArduPilot startup parameter file (in
./default_params
)gazebo-iris
->gazebo-iris-2
- Append
SYSID_THISMAV 2
to end of file
- Register this new parameter file (in
./pysim/vehicleinfo.py
)- (See references)
- Duplicate the existing ArduPilot startup parameter file (in
- Navigate to the ArduPilot Repository (
- Segregrate the FDM ports of the drone model so ArduPilot (sim_vehicle.py) can correctly connect to the drone plugin.
-
Test
- Start the Gazebo World in ROS
roslaunch helium flat_multi.launch
- Start the ArduCopter instances
sim_vehicle.py -v ArduCopter -f gazebo-iris -I0 --out=tcpin:0.0.0.0:8100
sim_vehicle.py -v ArduCopter -f gazebo-iris-2 -I1 --out=tcpin:0.0.0.0:8200
- Start the MAVROS instances
roslaunch helium apm.launch
roslaunch helium apm2.launch
- Start QGroundControl
- Settings -> Comm Links -> Add
- Name: Drone 2
- Type: TCP
- TCP Port: 8200
- Ok -> Drone 2 -> Connect
- Settings -> Comm Links -> Add
- Start the Gazebo World in ROS