Matlab controllers and Crazyflie ROS package

Firmware/software/electronics
Post Reply
flavia1394
Beginner
Posts: 23
Joined: Fri Mar 30, 2018 5:10 pm

Matlab controllers and Crazyflie ROS package

Post by flavia1394 »

HI,
I would like to use the Matlab controller that I created in these month to let fly the crazyflie. The first step was putting all the sensor value with the ROS package in Matlab, now I would like simply to send a trajectory from MATLAB to the drone and then using the controllers that I created.

Can you help me? I will be more specific:
1) where should I send the trajectory with ROS? Is the topic /crazyflie/goal useful for this?
2) I created the publishers and subscribers in a Simulink file and everything works fine because in the graphs I can see the sine wave and the other command. The image below shows the model in Simulink. My question is: how can I let the crazyflie fly? Because even though I publish the topic and it appears in the list, nothing happen to the drone. What am I missing?

Should I rewrite the controller class in the crazyflie ros package?
Schermata 2018-07-05 alle 4.57.19 PM.png
Attachments
Schermata 2018-07-05 alle 4.56.43 PM.png
Last edited by flavia1394 on Fri Jul 06, 2018 4:11 pm, edited 1 time in total.
flavia1394
Beginner
Posts: 23
Joined: Fri Mar 30, 2018 5:10 pm

Re: Drone fly with Matlab controller

Post by flavia1394 »

Should I rewrite the controller class into the Ros crazyflie package?
whoenig
Expert
Posts: 395
Joined: Mon Oct 27, 2014 2:55 am

Re: Matlab controllers and Crazyflie ROS package

Post by whoenig »

If your controller is a position controller (and you want to use the on-board attitude controller), you can publish your target values to the cmd_vel topic. One example of such approach is the crazyflie_controller package in the crazyflie_ros stack.
If you want to replace the complete controller, the latency will be too high to run it off-board and achieve satisfactory performance. In this case, you should re-write your controller in C and include it in the firmware. One example of such approach is controller_mellinger.c in the firmware.
flavia1394
Beginner
Posts: 23
Joined: Fri Mar 30, 2018 5:10 pm

Re: Matlab controllers and Crazyflie ROS package

Post by flavia1394 »

whoenig wrote: Sat Jul 07, 2018 12:56 am If your controller is a position controller (and you want to use the on-board attitude controller), you can publish your target values to the cmd_vel topic. One example of such approach is the crazyflie_controller package in the crazyflie_ros stack.
If you want to replace the complete controller, the latency will be too high to run it off-board and achieve satisfactory performance. In this case, you should re-write your controller in C and include it in the firmware. One example of such approach is controller_mellinger.c in the firmware.

Thank you so much for your answer, this things help me for the thesis. My controllers in MATLAB are PID, LQG and LQT.

I saw that the cmd_vel is a topic that have roll pitch and yaw rate that are angles, and only the thrust is a PWM. In my LQG and LQT controllers I have the PWM values to sent to the motors. So do you suggest to rewrite the controller class in the ros package with a new topic that receive the PWM instead of roll pitch and yaw rate??
whoenig
Expert
Posts: 395
Joined: Mon Oct 27, 2014 2:55 am

Re: Matlab controllers and Crazyflie ROS package

Post by whoenig »

For controllers that output PWM directly, I suggest to implement your code in C, directly in the firmware. The latency is too high and bandwidth too low to achieve good control results if the controller is running off-board.
flavia1394
Beginner
Posts: 23
Joined: Fri Mar 30, 2018 5:10 pm

Re: Matlab controllers and Crazyflie ROS package

Post by flavia1394 »

whoenig wrote: Tue Jul 10, 2018 7:57 pm For controllers that output PWM directly, I suggest to implement your code in C, directly in the firmware. The latency is too high and bandwidth too low to achieve good control results if the controller is running off-board.
Thank you for your answer.
Baosai
Beginner
Posts: 10
Joined: Mon Jun 08, 2020 8:49 am

Re: Matlab controllers and Crazyflie ROS package

Post by Baosai »

whoenig wrote: Tue Jul 10, 2018 7:57 pm For controllers that output PWM directly, I suggest to implement your code in C, directly in the firmware. The latency is too high and bandwidth too low to achieve good control results if the controller is running off-board.
Hello, for my Master thesis I want to implement a Model Predictive Control for position and trajectory control on the Crazyflie using the lighthouse positioning deck. The controller is designed in Matlab, preferably it should be a nonlinear MPC. Is there a known framework to have an .m file compiled and then flashed on the Crazyflie so that the code doesnt have to be transformed manually?

Thanks in advance for your help!
kimberly
Bitcraze
Posts: 1050
Joined: Fri Jul 06, 2018 11:13 am

Re: Matlab controllers and Crazyflie ROS package

Post by kimberly »

Baosai wrote: Wed Jun 10, 2020 9:13 am
Hello, for my Master thesis I want to implement a Model Predictive Control for position and trajectory control on the Crazyflie using the lighthouse positioning deck. The controller is designed in Matlab, preferably it should be a nonlinear MPC. Is there a known framework to have an .m file compiled and then flashed on the Crazyflie so that the code doesnt have to be transformed manually?

Thanks in advance for your help!
I think it is better to start a new thread with your question. The original post in this thread was not about implementing Matlab code into the Crazyflie onboard.

This is just to make the forum more search friendly for other users. Thanks!
Post Reply