In this post, we will see how to program drones using ROS2. Perhaps you have programmed drones using ROS1, found that programming drones using ROS2 is not as straightforward, and have been wondering, “how the heck do you program drones using ROS2?” You have come to the right place!
Step 1: Grab the required source code
You can program drones using ROS2 on your local PC by following the instructions in this repository step by step. However if you use the rosject you copied below, we have already done most of the heavy lifting for you and you just need to run a few commands to get your drone flying!
Click here to get your own copy of the project (PS: If you don’t have an account on the ROS Development Studio, you would need to create one. Once you create an account or log in, we will copy the project to your workspace).
That done, open the project using the Run button. This might take a few moments, please be patient.
Step 2: Understand the basic components
The ros2 drone system used in this post consists of three main parts:
A ros2 simulation containing the simulation and the plugin that connects to the rest of the system.
cd ~/ros2_ws
source install/setup.bash
ros2 launch ls2n_drone_simulation single_drone_trajectory_sitl.launch.py
By this time, you should have the simulation running. Open the Gazebo app (if not opened automatically) to see it. Right click on the drone model on the left pane and select “Follow” to keep seeing the drone when it takes off.
Now, open another web shell and start the PX-4 system:
cd ~
cd px4-autopilot/Tools/
./gazebo_sitl_multiple_run_only_px4.sh
Finally, start the ground control system in another web shell:
user:~$ cd squashfs-root/
user:~/squashfs-root$ ./AppRun
The ground control GUI should load shortly. Open the Graphical Tools app to see it, if not opened automatically:
Time to take off the drone!
Ensure the top-left corner of the controller says “Ready to Fly” in a green background.
Click the Takeoff button on the top left.
In the bottom middle, drag the slider to the right to confirm takeoff. You should see something similar to the image below.
If the takeoff does not work, repeat 2 & 3.
After takeoff, the button changes to “Land”. Use it to land the drone.
Step 4: Consolidate your learning
Do you understand how to program drones using ROS2 after watching the video? If not, please review the material again and perhaps go over the video again. Let us know any problems you are seeing in the comments.
Extra Step: Watch the video for the sights and sounds version of how to program drones using ROS2
Did you like this post? Do you have any questions about the explanations? Whatever the case, please leave a comment on the comments section below, so we can interact and learn from each other. If you want to learn about other ROS2 topics, please let us know in the comments area and we will do a video or post about it.
Welcome to the ROS Q&A series again. In this post, we are going to answer and solve a question from a user on Gazebo Answers which asks how to launch a Parrot Drone simulation locally. The question can be found here.
What will you learn in this post
How to spawn a drone simulation in your local computer
Before downloading the repositories, let’s first create a catkin workspace for the parrot drone, which we will call parrot_ws. Let’s do that with the commands below:
mkdir -p ~/parrot_ws/src
cd ~/parrot_ws/
Now we have the parrot_ws (parrot workspace). Let’s then download the required git repositories which contain the simulation:
cd ~/parrot_ws/src
git clone --branch kinetic-gazebo7 https://bitbucket.org/theconstructcore/parrot_ardrone.git
git clone https://bitbucket.org/theconstructcore/spawn_robot_tools.git
You should now have the folders parrot_ardrone and spawn_robot_tools on the ~/parrot_ws/src folder.
Installing ignition-math, used by sjtu_drone
Before compiling the packages we downloaded in the previous step, we will need to install the Ignition Math library, which is used by the sjtu_drone drone found on the parrot_ardrone repository we cloned previously.
We can install the Ignition Math library with the following commands:
Now that we have the Ignition Math library installed, we can proceed to compile the packages in our workspace.
Compiling the drone package
Now that we have everything in place, we can compile our packages we downloaded previously.
IMPORTANT: it may happen that when compiling the package, catkin_make can’t find the ignition library, so we need to export the CXXFLAGS accordingly. In my local computer, the ignition library is found at /usr/include/ignition/math4, so to compile we use the following commands:
cd ~/parrot_ws
export CXXFLAGS=-isystem\ /usr/include/ignition/math4
source /opt/ros/kinetic/setup.bash
catkin_make
If everything worked as expected, great. If not, try removing the devel and build first with cd ~/parrot_ws/; rm -rf build/ devel/ and compile it again with the commands exemplified above.
If everything went ok, you should have something like:
root@79e5b2505ede:~/parrot_ws# export CXXFLAGS=-isystem\ /usr/include/ignition/math4
root@79e5b2505ede:~/parrot_ws# source /opt/ros/kinetic/setup.bash; catkin_make
Base path: /root/parrot_ws
Source space: /root/parrot_ws/src
Build space: /root/parrot_ws/build
Devel space: /root/parrot_ws/devel
Install space: /root/parrot_ws/install
####
#### Running command: "cmake /root/parrot_ws/src -DCATKIN_DEVEL_PREFIX=/root/parrot_ws/devel -DCMAKE_INSTALL_PREFIX=/root/parrot_ws/install -G Unix Makefiles" in "/root/parrot_ws/build"
####
...
-- catkin 0.7.14
-- BUILD_SHARED_LIBS is on
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- ~~ traversing 6 packages in topological order:
-- ~~ - custom_teleop
-- ~~ - drone_demo
-- ~~ - ardrone_as
-- ~~ - sjtu_drone
-- ~~ - spawn_robot_tools_pkg
-- ~~ - drone_construct
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- +++ processing catkin package: 'custom_teleop'
-- ==> add_subdirectory(parrot_ardrone/custom_teleop)
-- +++ processing catkin package: 'drone_demo'
-- ==> add_subdirectory(parrot_ardrone/drone_demo)
-- +++ processing catkin package: 'ardrone_as'
-- ==> add_subdirectory(parrot_ardrone/ardrone_as)
-- Using these message generators: gencpp;geneus;genlisp;gennodejs;genpy
-- Generating .msg files for action ardrone_as/Ardrone /root/parrot_ws/src/parrot_ardrone/ardrone_as/action/Ardrone.action
Generating for action Ardrone
-- ardrone_as: 7 messages, 0 services
-- +++ processing catkin package: 'sjtu_drone'
-- ==> add_subdirectory(parrot_ardrone/sjtu_drone)
-- Using these message generators: gencpp;geneus;genlisp;gennodejs;genpy
-- Boost version: 1.58.0
-- Found the following Boost libraries:
-- thread
-- signals
-- system
-- filesystem
-- program_options
-- regex
-- iostreams
-- date_time
-- chrono
-- atomic
-- Found Protobuf: /usr/lib/x86_64-linux-gnu/libprotobuf.so
...
-- Generating done
-- Build files have been written to: /root/parrot_ws/build
####
#### Running command: "make -j4 -l4" in "/root/parrot_ws/build"
####
Scanning dependencies of target _ardrone_as_generate_messages_check_deps_ArdroneActionFeedback
Scanning dependencies of target _ardrone_as_generate_messages_check_deps_ArdroneGoal
Scanning dependencies of target _ardrone_as_generate_messages_check_deps_ArdroneActionGoal
Scanning dependencies of target _ardrone_as_generate_messages_check_deps_ArdroneResult
[ 0%] Built target _ardrone_as_generate_messages_check_deps_ArdroneResult
...
Scanning dependencies of target plugin_drone
[ 1%] Building CXX object parrot_ardrone/sjtu_drone/CMakeFiles/plugin_ros_cam.dir/src/plugin_ros_cam.cpp.o
[ 3%] Building CXX object parrot_ardrone/sjtu_drone/CMakeFiles/plugin_ros_imu.dir/src/plugin_ros_imu_native.cpp.o
[ 5%] Building CXX object parrot_ardrone/sjtu_drone/CMakeFiles/plugin_drone.dir/src/plugin_drone.cpp.o
[ 7%] Building CXX object parrot_ardrone/sjtu_drone/CMakeFiles/plugin_ros_sonar.dir/src/plugin_ros_sonar.cpp.o
...
[ 9%] Linking CXX shared library /root/parrot_ws/src/parrot_ardrone/sjtu_drone/plugins/libplugin_ros_imu.so
[ 11%] Linking CXX shared library /root/parrot_ws/src/parrot_ardrone/sjtu_drone/plugins/libplugin_ros_sonar.so
[ 11%] Built target plugin_ros_sonar
[ 13%] Building CXX object parrot_ardrone/sjtu_drone/CMakeFiles/plugin_ros_cam.dir/src/util_ros_cam.cpp.o
[ 13%] Built target plugin_ros_imu
Scanning dependencies of target plugin_ros_init
[ 15%] Building CXX object parrot_ardrone/sjtu_drone/CMakeFiles/plugin_ros_init.dir/src/plugin_ros_init.cpp.o
[ 17%] Building CXX object parrot_ardrone/sjtu_drone/CMakeFiles/plugin_drone.dir/src/pid_controller.cpp.o
[ 19%] Linking CXX shared library /root/parrot_ws/src/parrot_ardrone/sjtu_drone/plugins/libplugin_drone.so
[ 19%] Built target plugin_drone
Scanning dependencies of target spawn_drone
[ 21%] Building CXX object parrot_ardrone/sjtu_drone/CMakeFiles/spawn_drone.dir/src/spawn_drone.cpp.o
...
[ 23%] Linking CXX executable /root/parrot_ws/src/parrot_ardrone/sjtu_drone/bin/spawn_drone
[ 23%] Built target spawn_drone
Scanning dependencies of target spawn_robot_tools_pkg_xacro_generated_to_devel_space_
[ 23%] Built target spawn_robot_tools_pkg_xacro_generated_to_devel_space_
Scanning dependencies of target ardrone_as_generate_messages_cpp
[ 25%] Generating C++ code from ardrone_as/ArdroneFeedback.msg
[ 27%] Generating C++ code from ardrone_as/ArdroneActionResult.msg
[ 29%] Generating C++ code from ardrone_as/ArdroneAction.msg
[ 31%] Generating C++ code from ardrone_as/ArdroneResult.msg
[ 33%] Generating C++ code from ardrone_as/ArdroneActionGoal.msg
[ 35%] Generating C++ code from ardrone_as/ArdroneGoal.msg
[ 37%] Generating C++ code from ardrone_as/ArdroneActionFeedback.msg
Scanning dependencies of target ardrone_as_generate_messages_py
[ 37%] Built target ardrone_as_generate_messages_cpp
[ 39%] Generating Python from MSG ardrone_as/ArdroneFeedback
Scanning dependencies of target ardrone_as_generate_messages_nodejs
[ 41%] Generating Javascript code from ardrone_as/ArdroneFeedback.msg
[ 43%] Generating Javascript code from ardrone_as/ArdroneActionResult.msg
[ 47%] Generating Javascript code from ardrone_as/ArdroneAction.msg
[ 47%] Generating Python from MSG ardrone_as/ArdroneActionResult
[ 49%] Generating Javascript code from ardrone_as/ArdroneResult.msg
[ 50%] Generating Javascript code from ardrone_as/ArdroneActionGoal.msg
[ 52%] Generating Python from MSG ardrone_as/ArdroneAction
[ 54%] Generating Javascript code from ardrone_as/ArdroneGoal.msg
[ 56%] Generating Javascript code from ardrone_as/ArdroneActionFeedback.msg
[ 58%] Generating Python from MSG ardrone_as/ArdroneResult
[ 58%] Built target ardrone_as_generate_messages_nodejs
Scanning dependencies of target ardrone_as_generate_messages_eus
[ 60%] Generating EusLisp code from ardrone_as/ArdroneFeedback.msg
[ 62%] Generating EusLisp code from ardrone_as/ArdroneActionResult.msg
[ 64%] Generating Python from MSG ardrone_as/ArdroneActionGoal
[ 66%] Generating EusLisp code from ardrone_as/ArdroneAction.msg
[ 68%] Generating Python from MSG ardrone_as/ArdroneGoal
[ 70%] Generating EusLisp code from ardrone_as/ArdroneResult.msg
[ 72%] Generating EusLisp code from ardrone_as/ArdroneActionGoal.msg
[ 74%] Generating Python from MSG ardrone_as/ArdroneActionFeedback
[ 76%] Generating EusLisp code from ardrone_as/ArdroneGoal.msg
[ 78%] Generating EusLisp code from ardrone_as/ArdroneActionFeedback.msg
[ 80%] Generating Python msg __init__.py for ardrone_as
[ 82%] Generating EusLisp manifest code for ardrone_as
[ 82%] Built target ardrone_as_generate_messages_py
Scanning dependencies of target ardrone_as_generate_messages_lisp
[ 84%] Generating Lisp code from ardrone_as/ArdroneFeedback.msg
[ 86%] Generating Lisp code from ardrone_as/ArdroneActionResult.msg
[ 88%] Generating Lisp code from ardrone_as/ArdroneAction.msg
[ 90%] Generating Lisp code from ardrone_as/ArdroneResult.msg
[ 92%] Generating Lisp code from ardrone_as/ArdroneActionGoal.msg
[ 94%] Generating Lisp code from ardrone_as/ArdroneGoal.msg
[ 96%] Generating Lisp code from ardrone_as/ArdroneActionFeedback.msg
[ 96%] Built target ardrone_as_generate_messages_lisp
[ 96%] Built target ardrone_as_generate_messages_eus
Scanning dependencies of target ardrone_as_generate_messages
[ 96%] Built target ardrone_as_generate_messages
...
[ 98%] Linking CXX shared library /root/parrot_ws/src/parrot_ardrone/sjtu_drone/plugins/libplugin_ros_cam.so
[ 98%] Built target plugin_ros_cam
[100%] Linking CXX shared library /root/parrot_ws/src/parrot_ardrone/sjtu_drone/plugins/libplugin_ros_init.so
[100%] Built target plugin_ros_init
Once the package is compiled, in every shell you need to source the parrot_ws so that ROS can find the compiled packages. In each shell you can run the commands below:
cd ~/parrot_ws/
source devel/setup.bash
rospack profile
Launching the simulation
Now that you have everything in place, you should be able to launch the simulation with the command below:
After running rosrun teleop_twist_keyboard teleop_twist_keyboard.py you can easily move the robot using the keyboard.
So that is the post for today. You can also find a live version of this post on our YouTube channel in the link below. Also, please consider subscribing to our channel if you liked the content and press the bell for a new video every day.
We show you how you can launch two drones (or more) in the same Gazebo simulation, each one having its own independent control system based on ROS. This procedure can be replicated to launch as many drones as required.
RELATED LINKS
– How to start programming drones with ROS: https://youtu.be/f7b5tSZW1Ig – Hector Quadrotor Simulation: https://bitbucket.org/theconstructcore/hector_quadrotor_sim – ROS Development Studio: https://goo.gl/Yf2Q4J
[irp posts=”6638″ name=”ROS Q&A | How to Start Programming Drones using ROS”]
Drones market is growing more and more each year, and so does the need of improving the way we control them. One of the most important topics here is, of course, how to navigate drones. In this series of videos we are going to have a look at how to implement in ROS one of the approaches that can allow us to perform Localization and Mapping in drones in a quite easy way: LSD-SLAM. LSD-SLAM is a direct monocular SLAM technique, developed by TUM, which allows to localize and create maps with drones with just a 3D camera. Hope you enjoy it!
You will learn step by step through 4 video tutorials:
[irp posts=”6638″ name=”ROS Q&A | How to Start Programming Drones using ROS”]
Part 1 – Setup the whole environment
How to perform LSD-SLAM with a ROS based Parrot AR.Drone with a Gazebo simulation. In this 1st video, you’re going to
Learn the definition of LSD SLAM (Large-Scale Direct Monocular SLAM)
Install LSD-SLAM packages and compile them
Setup the whole environment in order to have all the packages we need for performing LSD-SLAM with a Parrot AR.Drone.
Step 1. Create the project in ROS Development Studio(RDS)
You can simply build the project in RDS without any configuration in the local machine. If you haven’t had an account yet, please register here.
Step 2. Download and compile the simulation environment
Let’s clone the drone simulation under the simulation_ws, you can find shell from Tools->shell
$ cd ~/simulation_ws/src
$ git clone https://bitbucket.org/theconstructcore/tum_ardrone_sim
Now we have to compile the package before using it.
Since the package is for ROS-indigo, we have to configure something first. Please replace the following part in the file ~/simulation_ws/src/tum_ardrone_sim/tum_ardrone/src/UINode/RosThread.h
Part 2 – Solve compilation errors & Launch the nodes for performing LSD SLAM
In this 2nd video of the series, we are going to solve some compilation errors we got in the previous video, and we are trying to launch the nodes for performing LSD SLAM.
[irp posts=”8584″ name=”How to launch two drones on a Single Gazebo Simulation”]
Part 3 – Launch the LSD-SLAM ROS node in an Hector Quadrotor simulation
In this 3rd video of the series, we are successfully achieve to launch the LSD-SLAM ROS node in an Hector Quadrotor simulation.
Part 4 – Perform LSD-SLAM in an small village environment
In this 4th video of the series, we have successfully achieved to launch the LSD-SLAM ROS nodes in an Hector Quadrotor simulation, and we perform some LSD-SLAM in an small village environment.
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:
Shell: it is the terminal where you can execute commands in RDS. You can open it as many as you want in RDS!
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.
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.
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
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.
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
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!