For the simulation and the described commands to work, the ROS2 workspace ros2_px4_ws should be in the $HOME
directory of the pc, as well as the PX4-Autopilot, px4_ros_com_ros2, and gazebo_ros_pkgs folders. For commodity, it is suggested to add the command source ~/ros2_px4_ws/src/ros2_px4_swarming/other/ros2_px4_swarming_aliases.sh
to the ~/.bashrc
file.
It is the code running on each drone of the swarm. It initializes the parameteres from params.yaml and it is responsible of reacting to the requests for the vehicle. When run, it connects to the Pixhawk and it puts the drone in an idle state, where it waits for external commands. When takeoff is commanded, the vehicle waits for its peers to be ready as well, then reaches a predefined altitude and, when the whole formation is ready, the swarming algorithm is run. If the swarm loses contact with one of its members, it is not considered anymore in the swarming algorithm and a new formation is generated.
It continuously publishes dummy data on the visual odometry topic of every drone. In this way, the vehicle thinks to know its global position. It is useful to run the code indoor, without the propellers mounted.
It continuously publishes the number of vehicles in the formation.
It publishes information about the performance of the system (tracking error, inter-anchors distances, synchronization error, ...), so that the architecture could be analyzed through graphs and plots.
It plots the data stored in a specific bag file (tracking error, inter-anchors distances, target UWB distances, trajectories, altitudes, tracking velocity, velocities, positions, synchronization error, ...).
It reads a topic on which every drone publishes information for debug, and it consequently prints every message to screen.
It is the node through which the followed target is commanded in simulation. Like anchorDrone.py, it subscribes to a service to receive the inputs from the user.
It plots the data stored in the .csv files by topicsRecorder.py.
It records the data published on some chosen topics, together with a timestamp. It is needed because, at present time, it is not possible to use the rosbag command while using the DDS server.
It is the brain of the formation: it applies the PID controller to the data received from the anchors and it publishes the resulting tracking velocity, that is equal for every member of the swarm.
It is the script launching the node running on the physical drone for testing. It runs anchorDrone.py.
It is the script launching all the needed pieces of the simulation. It runs numAnchorsNode.py, targetRover.py, anchorDrone.py, trackingVelocityCalculator.py, and performanceAnalyzer.py.
It is the script launching the central nodes needed to test the system on hardware. It runs numAnchorsNode.py, targetRover.py, trackingVelocityCalculator.py and performanceAnalyzer.py.
The model of the drone used in simulation.
The model of the rover used in simulation.
The model of the UWB anchor used in simulation.
The model of the UWB sensor used in simulation.
It opens gazebo, spawning the desired number and type of vehicles in the chosen world for the simulation.
It initializes some parameters, including the UWB anchor's identifier.
It stores the number of drones and the information about the presence of the target vehicle. These data are retrieved by the proper scripts to give everybody the needed information for the system to work properly.
This document.
This file, which should be sourced in the .bashrc, generates some aliases, useful to easily launch simulations and tests of this package.
buildws
: builds the whole ros2_px4_ws workspace with colconbuildswarming
: builds only the ros2_px4_swarming package, included in the ros2_px4_ws workspacekillgazebosimulation
: kills px4, gazebo, the microRTPS agent and ROS2agent 0
: generates the microRTPS agent, with namespace X500_0gazebosimulation 4 1
: launches a gazebo simulation with 4 drones and 1 roverlaunchsimulation
: runs launch_simulation.launch.pylaunchtest 4 1
: runs launch_test.launch.py, for a test with 4 drones and 1 rover
swarmtakeoff
: commands the formation to takeoffswarmhover
: commands the formation to hover at the current locationswarmswarming
: commands the formation to start the swarming algorithmswarmgoto 45.06 7.66
: commands the formation to move to latitude 45.06 and longitude 7.66swarmreturn
: commands each drone to return to its starting point, that is the one where it concluded the takeoff (it could be dangerous, because the drones move independently and not as a whole)swarmland
: commands the formation to land at the current locationswarmrestart
: commands each drone to restart, that is reset the parameters and get ready to fly again
dronetakeoff 0 -3
: commands drone 0 to takeoff to an altitude of 3 metersdronehover 0
: commands drone 0 to hover at its current locationdroneswarming 0
: commands drone 0 to start the swarming algorithmdronegoto 0 1 2 -3
: commands drone 0 to go to position (1, 2, -3) with respect to its boot position, considering a NED reference systemdronesethorizontalvelocity 0 1 2
: commands drone 0 to set a velocity of (1, 2), considering a NED reference systemdronereturnhome 0
: commands drone 0 to return to its starting point, that is the one where it concluded the takeoffdroneland 0
: commands drone 0 to land at its current locationdronerestart 0
: commands drone 0 to restart, that is reset the parameters and get ready to fly again
targetroverhold
: commands the target to stand stilltargetroverstraight 1
: commands the target to move straight with a speed of 1 m/stargetrovercircle 1 2
: commands the target to move describing a circle, with throttle 1 m/s and yaw rate 2 rad/stargetroverrandom
: commands the target to move randomlytargetrovergoto 1 2
: commands the target to move to (1, 2) with respect to its spawning locationtargetroverrotate 1
: commands the target to rotate with yaw rate 1 rad/stargetroverturn 90
: commands the target to rotate of 90° on its z axistargetroversquare
: commands the target to move describing a square
ddsserver
: opens a DDS server at 192.168.1.99:11811rds
: exports ROS_DISCOVERY_SERVERsendworkspace 0
: sends the ros2_px4_ws workspace to drone 0sendpackage 0
: sends the ros2_px4_swarming package to drone 0sendparams 0
: sends drone_params.yaml to drone 0connectssh 0
: connects via ssh to drone 0launchdrone 0 1
: command to launch anchorDrone.py on the RaspberryPi, with ID=0 and MAVSYS_ID=1srvstatus
: command to check the status of the service on the RaspberryPisrvrestart
: command to restart the service on the RaspberryPisrvstop
: command to stop the service on the RaspberryPirecordbagserver
: use this alias to record a bag of all the topics while using the discovery server
plotbag rosbag2_2021_09_02-11_33_25
: plots the data stored in rosbag2_2021_09_02-11_33_25plotlastbag
: plots the data stored in the last bag createdplotcsv 2021_09_02-11_33_25
: plots the data stored in 2021_09_02-11_33_25plotlastcsv
: plots the data stored in the last csv created
So for example, to launch a simulation with 4 drones and 1 target, the commands should be:
- in every used terminal, run
source ~/ros2_px4_ws/src/ros2_px4_swarming/other/ros2_px4_swarming_aliases.sh
- in a terminal, run
gazebosimulation 4 1
- in a second terminal, run
launchsimulation
- in a third terminal, run
swarmtakeoff
- in a fourth terminal, run
targetroverrandom
To launch a real world test, do:
- turn on the drones, the command
launchdrone
is executed automatically at startup
On the computer:
- in every used terminal, run
source ~/ros2_px4_ws/src/ros2_px4_swarming/other/ros2_px4_swarming_aliases.sh
- in a terminal, run
ddsserver
- in a second terminal, run
rds && launchtest 2 0
to initialize the test with two drones and no target rover - in a third terminal, run
rds && swarmtakeoff
- in the third terminal, run
rds && swarmland