Installation and integration guide on SITL, Gazebo and ROS.
This page intend to make you capable of communicating drones with programs written by you. Also we are going to control a Quadcopter. OS we going to work is Ubuntu 18.04.
Before directly controlling a drone, we should test our code is working perfectly or not or to identify the flaws in it. This we can achieve by running a simulation.
-
We need to setup a virtual drone.
-
We need to establish some connection between drone and program.
A simulation requires a virtual Pixhawk( Flight Controller ) so that to make it respond similar to the original one, and a model of the drone with an environment so we can actually observe what are the impacts of our program.
Inorder to do this we need to install some softwares:
-
Setting up an SITL : SITL allows you to have a virtual flight controller attached to a 3 D modelled vehicle. So that we can observe the impacts.
-
Gazebo Simulation : Our club is following gazebo as its standard simulator. It is a light weight simulator where we can observe what all are happening to the drone with less CPU usage compared to others. Drone model can be imported during installation.
Now after these steps drone is set up in simulation which is fully functional. Now we need to establish a connection. This can be done by ROS.
ROS have a subdivision called MAVROS , which converts all commands in our program into messages( Mavlink messages) that can be interpreted by the FC ( Flight Controller) to perform a task. These messages are transmitted to SITL on running the code as we can define which port the messages have to be transmitted( Each computer has its own port ID).
So the flow is like this:
In simulation
Program -> Mavros -> Mavlink Messages -> SITL -> Drone in simulation environment.
In real drone
Program -> Mavros -> Mavlink Messages -> Pixhawk -> Drone movements.
So first we need to install and make our Laptop compatible for this.
Just after Ubuntu installation your system will be clean.To install basic neccessities,
Setup script and graphics driver
Now our OS( Operating System) is ready. Now let's start with installation of required softwares.
Here is a setup script to set your system up with ros-melodic, sitl ( Ardupilot and px4 ) and gazebo if you are using zsh terminal in ubuntu 18.04 If you are running this script you dont want to follow next installation steps.
Run ./ros-gazebo.sh if you are running to install ardupilot.
Run sudo ./ros-gazebo.sh if you are on to px4.
https://github.com/Aeroclub-IITM/Installation-SITL-Gazebo-ROS/blob/master/scripts/ros-gazebo.sh
If you are preferring manual installation go through this guide.
There are many firmwares available for drones.PX4 and Ardupilot are most common of them. You need either of PX4 or Ardupilot SITL.
To launch sitl, gazebo and ros, download the arupilot.sh script for ardupilot.sh and px4_posix.sh for px4.
Run these script by ./ardupilot.sh or ./px4_posix
Also missions are carried out in 'Guided' mode in ardupilot and 'offboard' mode in px4. Also in px4, mode can only be changed if something is published to mavros topics.
Check these codes for arm and takeoff.
For c++ users : arm.cpp
For python users : arm.py
Check out these codes as a reference to write a node.
For c++ users : square.cpp
For python users : circle.py
For additional plugin checkout plugins_setup section.