The future of robotics development, including drones, is powerful simulation, which makes it possible to achieve faster development and better performance by reducing the "trial and error" process of testing everything with physical machines. The Dronecode projects have long used a number of powerful drone-specific simulators, including both "hardware-in-the-loop" (HITL) and "software-in-the-loop" (SITL) programs. 

But as drone simulation goes beyond simply simulating the drone itself and extends to simulating an entire robotic system, including swarming, pathfinding, environmental awareness and autonomous mapping and navigation without GPS, you need even more powerful tools. 

The gold standard for advanced robotics simulation is the ROS/Gazebo package, which is now supported by ArduPilot as part of the Dronecode project (ROS is the Robot Operating System, created by the Open Source Robotics Foundation, which is part of Dronecode).

The APM Dev wiki now has a great page on how to use it. Here's a sample, but click through for the whole thing.

ROS and Gazebo are a well-known and respected robotics framework and simulator:

  • The ROS framework contains many “packets” of software for performing robotics tasks. It allows you to model the environment (including indoor environments with walls, doors etc) and run your own control algorithms for autonomous flight.
  • Gazebo supports several different Copter models (at time of writing there are 6 URDF models in the rotors_simulator package). These can be extended to include support for additional sensors and other behaviours.
Tip:
The ROS/Gazebo is particularly useful for defining autonomous indoor flights.

This article shows how you can replace the default SITL Copter simulation with one supplied by Gazebo and control the autopilot using the ROS framework (instead of Mavproxy or some other Ground Control System).

An architectural overview of how ROS/Gazebo integrate with SITL is shown below:

Architecture Diagram: Using SITL with ROS and Gazebo

Views: 13569

Comment by Víctor Mayoral on August 28, 2015 at 1:55am

Great stuff! Thanks for sharing Chris! 

Comment by Gustavo Togeiro de Alckmin on August 28, 2015 at 4:57am

Great!

Comment by Alejandro Martin Pirola on August 29, 2015 at 10:29pm

Great!  But...

I went through the whole setup process and fail. I did a bunch of steps more than wiki has.  

First, don't try to setup Gazebo in a VirtualBox, make your life easy and do it in a native Ubuntu 14.04 installation. VM adds a lot of GPU virtualization issues, Gazebo needs OpenGL instructions not supported in VirtualBox 5.0.2 with Guest Addition 5.0.2.
The only way to run, pretty slow but it runs, Gazebo + Ubuntu 14.04 on VirtualBox is installing mesa utils and adding:

apt-get install mesa-utils

export LIBGL_ALWAYS_SOFTWARE=1

And then OpenGL error are gone. Trade off is that Gazebo don't run with GPU acceleration. :(

After that I follow the Wiki in order to setup catkin workspace for ArduCopter SITL. The issue here was a lot of missing dependencies. 

Actually every time I did run catkin_make a new unresolved dependency shows up. At catkin_ws/src I did install bunch more packages and dependencies:

git clone https://github.com/ethz-asl/mav_comm

git clone https://github.com/ethz-asl/glog_catkin

git clone https://github.com/catkin/catkin_simple

git clone https://github.com/ros-controls/control_toolbox.git

git clone https://github.com/ros-controls/realtime_tools.git

And then others ROS packages:

sudo apt-get install ros-indigo-octomap

sudo apt-get install ros-indigo-octomap-msgs

sudo apt-get install ros-indigo-octomap-ros

After that If your are lucky catkin_make will work... or not

Other Issue I did found was that alexbuyval/rotors_simulator repo fork adds missing planning_msgs at catkin_make compilation time. In the other hand PX4/rotors_simulator original repo compiles just fine. But there is no quadX450_empty_world.launch in PX4 fork. Well I did try PX4 repo just check out if it compiles. Of course it wont work at run time because of missing adX450_empty_world.

Anyway before I could run simulator... There are a couple of missing steps:

Install pip and then MAVProxy

sudo apt-get install python-pip python-dev build-essential
sudo pip install --upgrade pip
sudo pip install --upgrade pymavlink MAVProxy

Then the wiki says run:

sim_vehicle.sh -f arducopter_sitl_ros --console

But it wont work because on alexbuyval/ardupilot fork there is no auto vehicle detection based on directory in sim_vehicle.sh so you need to run instead:

sim_vehicle.sh -v ArduCopter -f arducopter_sitl_ros --console

So I'm still fighting to get this setup done.

By the way there is a VM image Ubuntu 14.04+ROS Indigo/Gazebo on internet it would be a good starting point for many of you.
http://nootrix.com/2014/09/ros-indigo-virtual-machine/

Comment by Alejandro Martin Pirola on August 30, 2015 at 12:37am

I did fix missing planning_msgs removing both refrences from rotors_simulator/rotors_gazebo_plugins/CMakeLists.txt

seems those reference were not needed.

Now catkin_male runs up to 73% then compilation FAILS, error message:

/home/viki/catkin_ws/src/rotors_simulator/rotors_gazebo/src/waypoint_publisher.cpp:24:40: fatal error: mav_msgs/CommandTrajectory.h: No such file or directory
#include <mav_msgs/CommandTrajectory.h>

Comment by Alejandro Martin Pirola on August 30, 2015 at 1:01am

Seems like alexbuyval's mav_comm version is different from https://github.com/ethz-asl/mav_comm

Mar 19 they renamed CommandTrajectory to CommandTrajectoryPositionYaw at pull #14

https://github.com/ethz-asl/mav_comm/pull/14

I did try downgrade ethz-asl/mav_comm to v1.0.0 where CommandTrajectory wasn't changed yet... but it triggers a new set of compilation fails.

So I give up... I need alexbuyval's mav_comm in order to continue

So many hours trying... :(

Comment by Patrick Nolan on August 31, 2015 at 7:02am

Alejandro,

I also had similar issues getting this to work out of the box. I eventually got it to work by using a combination of the repositories listed in the article (from http://dev.ardupilot.com/wiki/using-rosgazebo-simulator-with-sitl/) and the PX4 article for ROS SITL Setup (from https://pixhawk.org/dev/ros/sitl). 

As a general note, I have actually never been able to get the sim_vehicle.sh script to work, but my simulation runs fine.

First and foremost, unless I am missing something fundamental, the commands listed in the "Cloning the necessary ROS packages" section of the "Using ROS/Gazebo Simulator with SITL" article don't seem to be 100% correct. Mainly, the last line should be broken up after the first "src". Starting at "rosdep", that should be its own command. After running those commands, I installed the extra dependencies that you listed above, however I installed them according to the second link I provided (https://pixhawk.org/dev/ros/sitl). One dependency that I needed that you do not have listed is the PX4/Firmware.git repository.

With this setup, I was able to run the rotors_gazebo launch files and the px4 launch files, like so:

roslaunch rotors_gazebo iris_outdoor_world.launch

-- and--

roslaunch px4 gazebo_iris_empty_world.launch 

Note that some of the launch files don't load all URDF files that they are looking for, and that is most likely due to incompatibilities with the repositories from both approaches that I linked above. I admit this isn't the cleanest setup, but it works for my purposes. Feel free to message me or comment if you would like any further details on my setup.

My ultimate goal is to get a Hardware in the Loop (HWIL) setup. Unfortunately, with the latest updates, the HWIL with ArduCopter seems to be broken. My end goal is to essentially have the SITL setup, but for HWIL. So a Pixhawk could send motor commands (either PWM or RPM directly) into ROS/Gazebo, similar to this SITL setup. Then the ROS/Gazebo environment could feed back into an actual Pixhawk to evolve the state according to the simulated motion.

Chris, is there any timeline for fixing/adding the HWIL support with ROS/Gazebo? Ultimately, I would like to have multiple Pixhawk autopilots all talking with ROS/Gazebo in a hardware in the loop environment. I am currently trying to "hack" my way through it using the SITL setup as a starting point, but its proving to be more difficult than originally anticipated.

Comment by Aurelien ROY on September 1, 2015 at 2:28am

Good morning everyone,

Like you I think the Gazebo simulation is an excellent idea, so I followed the ardupilot dev wiki page on it.

While most of it is exact, there are a few commands missing, and for the moment it requires Alex Buyval's version of Ardupilot (because his work on sim_vehicle.sh and the SITL source libraries have not yet been merged to the trunk). Nethertheless Alex did a great job coding all the interface.

Since I am on Windows, and I used on VMWare a new virtual machine created just for the occasion, it required me to setup the whole environment from scratch. So I think I covered all dependencies (you already provided most of them Alejandro, except I did not need 'control_toolbox' and 'realtime_tools', but maybe they are needed later for more control/analysis of the simulation?). And finally the sim_vehicle.sh works.

For an easier installation, gathered all the commands in shell scripts, and wrote a tutorial. They are available on:

Github with a tutorial and scripts to setup SITL ros-gazebo for Ard...l

There is still one missing dependency, 'gflags_catkin' for 'glog_catkin' package. But it does not disrupt the compilation.

Hopefully it will help you.
Feel free modify the scripts or tutorial, or report me errors you have encountered with them.

Comment by Aurelien ROY on September 1, 2015 at 2:40am

Patrick,

Maybe you did not run into the same problem, but to be able to run the gazebo_iris_outdoor_world.launch simulation, I had to follow the hacks from :

https://github.com/PX4/Firmware/issues/1683

Because Gazebo could not locate the heightmap file in the packages.

Comment by Alejandro Martin Pirola on September 4, 2015 at 10:48am

Patrick, Aurelien thank you for sharing your setups. I will try one more time from scratch using Aurelien's scripts.

Tell you later.

Comment by Aurelien ROY on September 6, 2015 at 9:17am

Alejandro,

I just published a small commit on the scripts (minor addition for Linux users who skip the step_2). Let me know if the scripts ran smoothly or if you encountered any problem.

At the beginning I was using VMware on Windows. But like you said I finally installed a native Ubuntu in dual boot to get a higher frame rate on Gazebo.

sim_vehicle.sh does run, however not smoothly.
Using MavProxy on the side (to display the map and send commands), there are frequent connection failures of a few seconds, Mavros which waits to receive about 500 unknown parameters, there is a repetitive Floating Point Exceptions coming from somewhere in ArduCopter's code (trying to track it with -G), and I haven't yet manage to make the joystick work...
If you manage to solve any of these problems, I will gladly hear your advices.
(the regular SITL simulation with sim_vehicle.sh works fine)

PX4 simulations can be launched (using the MAVROS repository from PX4, not the modified Ardupilot version), but I haven't yet tested them with the PX4 autopilot.

Side note:
For the joystick, I also modified "/dev/input/js1" into "/dev/input/js0" in teleop.launch in folder mavros/mavros_extras/launch.

Comment

You need to be a member of DIY Drones to add comments!

Join DIY Drones

Groups

Season Two of the Trust Time Trial (T3) Contest 
A list of all T3 contests is here. The current round, the Vertical Horizontal one, is here

© 2019   Created by Chris Anderson.   Powered by

Badges  |  Report an Issue  |  Terms of Service