ROS Q&A | How to Start Programming Drones using ROS

ROS Q&A | How to Start Programming Drones using ROS

In this video answer, we walk through the basics of a Parrot AR Drone Gazebo simulation.
You will learn the topics provided by the simulation and how to use a ROS program to interact, sending commands or reading sensors, with this robot.

[irp posts=”8190″ name=”Performing LSD-SLAM with a ROS based Parrot AR. Drone”]

Let’s get started!

Step1. Create a new project on ROS Development Studio(RDS)

We’ll use ROS Development Studio(RDS) for this tutorial, you can register a free account here.

After logging into RDS, click on create my project. It will move to the public simulation. You can find tons of public simulation here offered by the construct for free and start to work on any of them in just minutes. See how powerful RDS is! For today, we’ll use sjtu_drone_tc project. Please click on it. Click the tools menu, you can find some tools that help you develop in RDS. For example, you have the:

  1.  Shell: it is the terminal where you can execute commands in RDS. You can open it as many as you want in RDS!
  2.  IDE: It’s the best way to explore the source tree of your project. With a right click, you can add or remove files easily.
  3. Jupyter Notebook: You can take notes for your project here. Since it’s working with python shell, you can directly execute python script here. A default notebook is provided to help you start the simulation.
  4. Graphical tool: You can use all the GUIs supported by ROS here(e.g. RViz, rqt_gui…etc.)

Notice:

We are not automatically running the simulation when you start RDS now. In order to have the same simulation shown in the video. Please go Simulations->Select launch file->main.launch to launch it by yourself. Then you can type the following command in a shell to check if the topics are correctly publishing by the drone.

$ rostopic list

 


Step2. Get started with the simulation

Let’s get started by following the instruction in the default jupyter notebook. Open it from tools->jupyter notebook->default.ipynb.

We can make the drone take off with the shell command

$ rostopic pub /drone/takeoff std_msgs/Empty "{}"

You should see the drone take off as soon as you send this command.

Notice:

You can use the ROS auto-completion function while you are typing a ROS command by pressing [TAB]. It’s a good idea to do that when the command is too long and hard to type it correctly.

You can also land the drone with the following command

$ rostopic pub /drone/land std_msgs/Empty "{}"

You can also find an instruction in the default.ipynb shows you how to do it with a python script instead of sending commend from shell.


Step3. Program with drones

We have more examples for you! Let’s say, we want to use the position control function provided by the drone. We found there is a topic called /drone/posctrl, but how to use it? By typing

rostopic info /drone/posctrl

You’ll see the output like this.

Type: std_msgs/Bool

Publishers:
* /my_node (http://ip-172-31-35-31:45972/)

Subscribers:
* /gazebo (http://10.8.0.1:44685/)

It seems that the topic is using the Bool message, but what is Bool message and how can I use it? You can further investigate it by typing

rosmsg show std_msgs/Bool

and got the output

bool data

The Bool message is very simple. It contains only one attribute called data with the type bool. Let’s try to send a message to this topic! Before we publish to the topic, we set up a monitor first with

rostopic echo /drone/posctrl

Then copy, paste and execute the following code in jupyter notebook.

from std_msgs.msg import Bool

var_bool = Bool()
pub_posctrl = rospy.Publisher('/drone/posctrl',Bool,queue_size = 1)
var_bool.data = True
pub_posctrl.publish(var_bool)

You should see

data: True

which means the message is published correctly. We enable the position control function on the drone successfully. Similarly, you can move the drone by publishing Twist message to the /cmd_vel topic. Here is an example script

from geometry_msgs.msg import Twist

var_twist = Twist()
pub_position = rospy.Publisher('/cmd_vel', Twist, queue_size=1)
var_twist.linear.x = 1
var_twist.linear.y = 1
var_twist.linear.z = 2
pub_position.publish(var_twist)

Now you know how to start programming drones easily with RDS! You can do lots of things in RDS(e.g. using the cameras on the drone to implement computer vision algorithms). If you are interested but have no ideas how to do it, you can check our Programming drones with ROS course on robot ignite academy!

 

Edit by Tony Huang

[Links and resources mentioned in the video]

– ROS Development Studio: https://goo.gl/1Qb4AT

– The course of Programming Drones with ROS is available here: https://goo.gl/x6yaZW


programming-drone-with-ros-course-banner

Pin It on Pinterest