Simulating and control of Crazyflie 2.1 in ROS Gazebo via Matlab

Post here to get support
Post Reply
danial_ameen
Beginner
Posts: 1
Joined: Wed Jun 02, 2021 6:33 pm

Simulating and control of Crazyflie 2.1 in ROS Gazebo via Matlab

Post by danial_ameen »

Hi everyone,

I have been trying to create a hover controller for Crazyflie 2.1 using Matlab as the controller and ROS Gazebo as the simulation platform. I am using the GitHub repository (https://github.com/gsilano/CrazyS) and using the simulation files in it to run my simulations.

What I want to do is to control the quadcopter using a controller built in Matlab and to do, so I have done the following:
1) Connect ROS to Matlab and gather the following information from ROS (Gazebo)
a) Cartesian position and velocities
b) Orientation angles and velocities

2) Use that information to build a state space controller that can use the state of the quadcopter to control the altitude of the quadcopter. The control uses the 6 states to essentially find control gains which are then converted to RPM readings for the quadcopter. The RPM readings are sent to the quadcopter simulation in Gazebo, which as a result controls the states of the quadcopter.

The main issue is that this high level controller is not working well. In my simulations the quadcopter runs initially but after a few seconds losses stability and fall down. I am not sure why this is happening.

The control is done in the following manner.


1) Get information from Gazebo simulation
2) Use the information in Matlab
3) The controller in Matlab finds the required RPM values
4) Send those RPM values via ROS to the simulation in Gazebo.


I really suspect that this problem is essentially a time related issue where my code is not fast enough to work with the Gazebo simulation, but I am really stuck with this and would appreciate any help I can get. I can share the code and videos as well if needed.
kimberly
Bitcraze
Posts: 1050
Joined: Fri Jul 06, 2018 11:13 am

Re: Simulating and control of Crazyflie 2.1 in ROS Gazebo via Matlab

Post by kimberly »

Hi!

In general it is advised to not use Matlab for ROS, especially for time critical things like controlling the RPM as that needs to be done very quickly. I've heard of other ROS users that moved fully to Python exactly because of this problem, since there is way better and faster ROS integration for python.

But since you want to control RPM... you might even want to look at a c++ ROS node even. Direct RPM control over crazyradio is even too slow, just to give you an indication, and that is why we have onboard controllers on the crazyflie for the attitude.
Post Reply