Reader small image

You're reading from  Mastering ROS for Robotics Programming, Third edition - Third Edition

Product typeBook
Published inOct 2021
PublisherPackt
ISBN-139781801071024
Edition3rd Edition
Concepts
Right arrow
Authors (2):
Lentin Joseph
Lentin Joseph
author image
Lentin Joseph

Lentin Joseph is an author and robotics entrepreneur from India. He runs a robotics software company called Qbotics Labs in India. He has 7 years of experience in the robotics domain primarily in ROS, OpenCV, and PCL. He has authored four books in ROS, namely, Learning Robotics using Python, Mastering ROS for Robotics Programming, ROS Robotics Projects, and Robot Operating System for Absolute Beginners. He is currently pursuing his master's in Robotics from India and is also doing research at Robotics Institute, CMU, USA.
Read more about Lentin Joseph

Jonathan Cacace
Jonathan Cacace
author image
Jonathan Cacace

Jonathan Cacace was born in Naples, Italy, on December 13, 1987. He received his Master's degree in computer science, and a Ph.D. degree in Information and Automation Engineering, from the University of Naples Federico II. Currently, he is an Assistant Professor at the University of Naples Federico II. He is also a member of PRISMA Lab where he is involved in different research projects focused on industrial and service robotics in which he has developed several ROS-based applications integrating robot perception and control.
Read more about Jonathan Cacace

View More author details
Right arrow

Chapter 8: ROS for Aerial Robots

In previous chapters, we have considered only ground-based and industrial robots. In the last decade, a new kind of system has become very popular – flying robots, also known as Unmanned Aerial Vehicles (UAVs). Nowadays, UAVs are constructed in different shapes and dimensions. In the main, they can be divided into fixed-wing (these being airplane-like vehicles) and rotary-wing (these being vehicles with multiple vertical axis rotors). Modern UAVs are equipped with onboard computers and sensors that make them real autonomous robots, able to perform different tasks, such as autonomous navigation. Using ROS makes it possible to read a UAV's sensors and send commands to the aerial platform. In addition to the real-life devices, it is also possible to use Gazebo to simulate the hardware and the sensors of different kinds of aerial systems.

This chapter is divided into two sections. First, we will discuss the basic components of aerial robots...

Technical requirements

To follow along with this chapter, you will need a standard laptop running Ubuntu 20.04 with ROS Noetic installed. The reference code for this chapter can be downloaded from the following Git repository: https://github.com/PacktPublishing/Mastering-ROS-for-Robotics-Programming-Third-edition.git. The code is contained inside the Chapter8/px4_ros_ctrl and Chapter8/iris_model folders.

You can view this chapter's code in action here: https://bit.ly/3svXX9L.

Using aerial robots

At present, flying vehicles are very popular. Even in their primary configuration where they are controlled by a radio controller, some flying vehicles can be considered as robots that respond to their environment in order to stay in the air. Such vehicles can use external sensors to estimate their state and pose, thus allowing them to fly autonomously. Of course, providing a flying robot with autonomy is more complicated than doing the same for a ground robot because of several reasons, listed here:

  • Stabilization: A flying robot must be able to adjust its pose to hold its position and orientation relative to the environment. Inertial sensors are not enough to accomplish this task, since they are not able to estimate position divergence caused by external disturbances (like wind or ground airflow), or the possible errors generated due to an inertial measurement unit sensor.
  • Low computation resources: Compared to a ground robot, flight platforms have...

Using the PX4 flight control stack

PX4 firmware allows developers to directly simulate the code running on the autopilot board on your Linux system. Additionally, it is possible to modify the autopilot source code and reload the new version on the Pixhawk board. To install the firmware on your system, you will firstly need to download it. Even though it is not mandatory, linking this with the ROS will conveniently place it in your ROS workspace. To download the autopilot code, enter your ROS workspace and use the following command:

git clone https://github.com/PX4/PX4-Autopilot.git --recursive

This repository contains all the necessary files to run the PX4 firmware on a ROS-Gazebo simulation, using different UAV quadrotors equipped with a camera, a depth camera, a laser scanner, and so on. Simulation represents a quick, easy, and safe way to test changes to PX4 code before attempting to fly in the real world. It is also a good way to start flying with PX4 when you have not yet...

PC/autopilot communication

To send and receive information from the aerial platform (simulated or real), we can use the following two modes:

  • Ground station: High-level software that can be connected to the autopilot to send commands such as take off and land or relay waypoint navigation information.
  • API: Programming an API allows developers to manage the behavior of the robot.

In both cases, the communication is managed by the MAVLink protocol. Micro Air Vehicle Link (MAVLink)and is a protocol for communicating with small, unmanned vehicles. It is designed as a header-only message-marshaling library. It is used mostly for communication between a Ground Control Station (GCS) and unmanned vehicles, and in the intercommunication of the subsystem of the vehicle. A packet datagram example is shown in the following figure:

Figure 8.6 – MAVLink protocol

Messages are no more than 263 bytes. The sender always fills in the System ID and Component...

Writing a ROS-PX4 application

Let's now create a new package in which we will store all the source and launch files needed to send and receive data from the simulated UAV using ROS. Enter your ROS source workspace and use the following command:

catkin_create_project px4_ros_ctrl roscpp mavros_msgs  geometry_msgs

As you can see, this package depends from the mavros_msgs. This will be used to retrieve data from the UAV. Here, we will discuss the ROS node that controls the vehicle. The complete code can be found in the book source code and it is contained into the src/px4_ctrl_example.cpp source file.

To achieve our goal, we need to perform the following operations:

  1. Arm the quadrotor. Arming the vehicle allows the motors to start spinning. This can be done using mavros through ROS services. The /mavros/cmd/arming service can be used.
  2. Switch to OFFBOARD mode. After that, the motors should start to spin and we can send input to the UAV. To accept external...

Using the RotorS simulation framework

In the previous section, we discussed how to simulate flight controller unit code using Gazebo ROS. However, in some cases, we might be interested in simulating only UAV dynamics with basic sensors (such as IMU, GPS, and so on) and propellers. This is the goal of the RotorS simulator. This simulator provides a set of configuration files and models shaped as ROS packages in order to simulate different types of UAVs. Besides the standard models, RotorS allows developers to configure new multirotor systems from scratch. In short, this ROS package implements both sensors and mechanisms in the form of Gazebo plugins that can be mounted on the multirotor. In this section, we will install RotorS on our ROS. Later, we will create a new multirotor model containing four rotors.

Installing RotorS

Let's start by installing RotorS on our system. To accomplish this step, you should install the following dependencies:

sudo apt-get install ros-noetic...

Summary

This chapter introduced the concept of aerial robots and discussed their main elements. We also described one of the most famous autopilot boards used to develop custom applications with UAV – the Pixhawk control board running the PX4 autopilot. After we learned how to use real multirotor platforms and integrate them with ROS, we then went on to discuss two simulation modalities. It is very important to simulate the effect of control algorithms before running them on a real UAV. This is in order to prevent damage to the robot and nearby people.

In the next chapter, we will discuss how to interface microcontroller boards and actuators with ROS.

Here are some questions based on what we learned in this chapter.

Questions

  • What is an aerial robot?
  • What is the main element of an aerial robot?
  • What is the PX4 control stack?
  • What are the main differences between PX4 SITL and RotorS simulations?
lock icon
The rest of the chapter is locked
You have been reading a chapter from
Mastering ROS for Robotics Programming, Third edition - Third Edition
Published in: Oct 2021Publisher: PacktISBN-13: 9781801071024
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Authors (2)

author image
Lentin Joseph

Lentin Joseph is an author and robotics entrepreneur from India. He runs a robotics software company called Qbotics Labs in India. He has 7 years of experience in the robotics domain primarily in ROS, OpenCV, and PCL. He has authored four books in ROS, namely, Learning Robotics using Python, Mastering ROS for Robotics Programming, ROS Robotics Projects, and Robot Operating System for Absolute Beginners. He is currently pursuing his master's in Robotics from India and is also doing research at Robotics Institute, CMU, USA.
Read more about Lentin Joseph

author image
Jonathan Cacace

Jonathan Cacace was born in Naples, Italy, on December 13, 1987. He received his Master's degree in computer science, and a Ph.D. degree in Information and Automation Engineering, from the University of Naples Federico II. Currently, he is an Assistant Professor at the University of Naples Federico II. He is also a member of PRISMA Lab where he is involved in different research projects focused on industrial and service robotics in which he has developed several ROS-based applications integrating robot perception and control.
Read more about Jonathan Cacace