How to simulate a drone using ROS (FlytSim)

Published on . Written by

How to simulate a drone using ROS (FlytSim)

As the usage of drones is expanding day by day the misuse and accidents are also increasing because of drones. Before testing a drone in real-time simulating it on a simulator will decrease the wastage of time and money. By doing this, the occurrence of accidents due to the malfunction in hardware or software of drones can also be avoided. In this ROS tutorial, we are going to simulate a drone in FlytSim simulator which is a ROS-Gazebo based setup. 


Skyfi Labs Projects
FlytSim is a 3D simulator for Drone applications. This simulator helps developers to test their applications at the convenience of their laptop/desktop. With the SITL simulation environment, the developed application can be tested without the drone hardware. During the simulation, autopilot uses the same algorithm on FC to make the behaviour close to real-time. 

Read more..

SLNOTE
Requirements

  • Ubuntu Linux
  • Gazebo
  • ROS
  • FlytSim
Project Implementation

Step 1 - Install ROS and Gazebo in your Linux laptop. (For the installation process you can refer to the official websites)

Step 2 - Download the FlytSim package from their official website.

Step 3 - Install the FlytOS by typing the following command in the terminal (Ctrl+Alt+T) 

$ sudo bash -c 'curl -sSL http://docs.flytbase.com/_static/Downloads/flytSim_installation.sh | bash -e'

After the installation, the system will reboot.

Step 4 - Install FlytSim from the downloaded package. (Choose the one which suits with your laptop configurations)

Run the following command to install the software (for intel graphics)

Go to the installation directory and run the following:

$ sudo ./setup.sh

Install docker and docker-compose. To check whether it is installed or not, run the following command:

$ sudo docker run hello-world


SLLATEST
Step 5 - Start the FlytSim by running the following command:

$ sudo ./start.sh

After starting the FlytSim, activate the FlytOS by generating the key. You can refer to the official FlytBase documentation for the installation process.

Note: Without activating the critical APIs and Demoapps will not function. 

Now the setup is ready, let’s start the simulation. We are going to create an application using python to perform the simulation. We are going to make the drone to perform a square pattern in the sky. Below is the code to make the drone move in a square pattern:

#!/usr/bin/env python

import time

from flyt_python import api

drone = api.navigation(timeout=120000) # instance of flyt droneigation class

#at least 3sec sleep time for the drone interface to initialize properly

time.sleep(3)

print 'taking off'

drone.take_off(5.0) #This command lifts the drone up in the air for 5m.

print ' going along the setpoints'

drone.position_set(5,0,0,relative=True)

#Drone moves 5m in x axis

drone.position_set(0,5,0,relative=True)

#Drone moves 5m in y axis

drone.position_set(-5,0,0,relative=True)

#Drone moves 5m in x axis (negative)

drone.position_set(0,-5,0,relative=True)

#Drone moves 5 m in y axis (positive)

print 'Landing'

drone.land(async=False)

#shutdown the instance

drone.disconnect()

Save the code in .py format and launch it. Now you can observe the drone take-off and cover the given waypoints. 


SLDYK
Kit required to develop How to simulate a drone using ROS (FlytSim):
Technologies you will learn by working on How to simulate a drone using ROS (FlytSim):


Any Questions?


Subscribe for more project ideas