This repository represents a testing and development framework for application in the domain of cyberphysical systems.
Currently, the "Crazyflie" drone by Bitcraze is the platform on which the test are run, but the system has been designed to include different platforms in the future. The core of the framework is based on ROS.
Currently the following modules have been implemented:
- commander_interface This package provides the point of interaction between the vehicle and the user. The commander_node advertises services for requesting task to the drone, such as goto, land, takeoff and full state tracking. These request are then managed by the Guidance that generates trajectories.
- control_router This package takes care of selecting the controller that will control the drone. Currently, it is possible to select among onboard or offboard controller and, in case of multiple offboard controllers, which one is actually driving the vehicle.
- crazyflie_controllers This package contains the controllers to command the drone offboard.
- crazyflie_ros This is the package providing the library and services to communicate with the Crazyflie drone.
- demo_launchers
This packages contains the ROS launch files and scripts to simplify the instantiation of the system components.
Currently, the main launchers are
-
"real_experiment": Launch file that starts all the components to run an experiment with the real drone.
-
"simulation_experiment": Launch file that starts all the components to run the system in simulation.
-
- guidance This package provides the guidance for the drone, that is, given a command and the current status of the drone, it generates the references to achieve the task.
- rarena This package contains the nodes for the implementation of the ROS/Arena bridge. [ONGOING WORK]
- state_aggregator This package provides the node that is aggregating the external information about the drone (currently, just the Optitrack) and provides an estimate of the drone state.
- testbed_msgs This package contains the common custom messages used by the nodes.
- utilities This package contains helpers for the framework.
- vrpn_client_cyphy Module of the vrpn client for ROS.
The project was developed in ROS Melodic and some modules used Eigen. Make sure to have ROS and Eigen available on your system.
Dependencies:
- Eigen -- a header-only linear algebra library for C++
- [libusb-1.0-0-dev] (sudo apt install libusb-1.0-0-dev)
- [VRPN](sudo apt install ros-noetic-vrpn) -- install vrpn library
- [python3-scipy] (sudo apt install python3-scipy) -- python library for math computation
- [cvxopt] (sudo apt install python3-cvxopt)
- [python-is-python3] (sudo apt install python-is-python3) -- python will then refer to python3
- [arena-py] (pip install arena-py) -- python library for the ARENA
The repository contains submodules, thus, make sure you clone recursively.
git clone --recursive <repoaddress>
To build the framework, navigate to the ws/
directory (the workspace), and run
catkin_make
Every time a new terminal is started, it's necessary to reload the references to the framework packages. This is done, running the following command from the ws/
directory:
source devel/setup.bash
Basic test simulation:
The commands to launch the the system are:
roslaunch demo_launchers demo_anchors.launch
This launch file will start the nodes:
- state_aggregator
- drone simulator
- anchor_sim
It is then possible to play with the system, such as changing the frequency of the simulator publications:
rosservice call /area0/sensors/anchors/anchorSimStatus "{freq: 40.0, active: true}"
or change the distortion of one anchor:
rosservice call /area0/sensors/anchors/anchorSimCtrl "{id: 0, enable: true, enable_distortion: true, distortion: -5.0}"
Example with simulated vehicle, feedback linearization controller and Arena:
Before launching the system, set an environmental variable to select the scene on the arena server. From the terminal
export SCENE='LandOfOz'
Then, launch the system with
roslaunch demo_launchers simulation_experiment.launch
This launch file will start the nodes:
- state_aggregator
- drone simulator
- feedback linearization controller
- control router
- commander interface
- guidance
- rarena
When launching the nodes, the system could request a login into the Arena. You can use the personal google account to perform the identification.
Once everything is started, the output of the system can be visualized at https://arenaxr.org//LandOfOz
That scene is remote and it will be shared among all the participants. Being a collaborative environment, if you launch the experiment at the same time it will be a mess.
It is possible to create new scenes if you want. The documentation for the Arena can be found at https://arena.conix.io/
In order to control the simulated drone, it is necessary to specify that the controller is an offboard one. This can be done calling the service provided by the commander interface for the vehicle "cf2".
rosservice call /cf2/Commander_Node/ctrl_offboard_srv "offboard_active: true"
Once the offboard control is active, it is possible to issue goto commands to the drone using the services provided by the same commander node.
The argument for the service is a tuple of float32, representing the position [x, y, z], a float32 representing the duration of the requested movement and a boolean to select a "relative" or "absolute" motion. For example, to issue the drone cf2 a goto to [1.0, 1.0, 0.5] in 10.0 seconds relative to the current position:
rosservice call /cf2/Commander_Node/goTo_srv '[1.0, 1.0, 0.5]' '10.0' 'false'
- When running python nodes, check that the python file running the node is made executable:
chmod +x <path_to_the_file>
- In case you are connected to the network where the optitrack system is streaming information, but you don't receive anything, check the firewall to enable the incoming traffic from the optitrack machine.