New controller for the crazyflie 2.1

Discussions about autonomous flight in general, regardless of positioning method
Post Reply
HazarB
Beginner
Posts: 11
Joined: Mon Feb 14, 2022 5:40 pm

New controller for the crazyflie 2.1

Post by HazarB »

Hi, in my project one of my tasks is to develop a new controller for crazyflie in simulink
so my questions:
-is that possible? and if it's yes, should i disable the on board controllers in crazyflie? any examples of work to design a new controller?
-if it's not possible ,should i modify the source code of the firmware? and any tutorials or examples of writing c code of controller.

thank you so much
kimberly
Bitcraze
Posts: 1050
Joined: Fri Jul 06, 2018 11:13 am

Re: New controller for the crazyflie 2.1

Post by kimberly »

Hi! Let me try to help you out with your questions.

Yes that is possible and no you will not be needing to change the C code of the controller if you do it correctly. You will just need to give only attitude setpoints to the crazyflie in that case. How the controllers scheme looks like you can checkout this page, that also points to how the PID controller has been implemented for instance. You can use the cflib python api to send these setpoints to the crazyflie: https://www.bitcraze.io/documentation/r ... commander/ but we don't have anything that works with simulink out of the box.

If in case you do want to dig around in the c code and have an example, the latest controller implemented in the firmware is the INDI controller: https://github.com/bitcraze/crazyflie-firmware/pull/568

Btw, there is another thread going on for simulink that might be good for you to also keep an eye on: viewtopic.php?t=5284
HazarB
Beginner
Posts: 11
Joined: Mon Feb 14, 2022 5:40 pm

Re: New controller for the crazyflie 2.1

Post by HazarB »

Thank you so much for your fast reply and details.

If i understand you well , i will keep working with PID controllers but choose which type of commands that i will send it to crazyflie, is that right?
for example if i need to send set-points to crazyflie i will use the function ** send_position_setpoint(self, x, y, z, yaw)** ?

what is the difference between sending set-points with this function and using this script https://github.com/bitcraze/crazyflie-l ... equence.py.

Also my question is it possible to change the PID controller to another controller ? and how can i disable the on board controllers in crazyflie to work with the one that i will develop in simulink?

sorry, my ideas are note clear that's why my questions are not well formulated , if you need more explanation i will do it
thank you for your time.
kimberly
Bitcraze
Posts: 1050
Joined: Fri Jul 06, 2018 11:13 am

Re: New controller for the crazyflie 2.1

Post by kimberly »

Indeed send_position_setpoint is also used in crazyflie_autonomousSequence.py example.

But I think you should look at the

Code: Select all

def send_setpoint(self, roll, pitch, yaw, thrust)
instead as that actually sends roll pitch and yaw, which is more interesting to you if you want to make a position PID controller. If you send roll pitch yaw setpoints with that function, the firmware will automatically skip the position and velocity PID controller, so there is no need to disable it.
HazarB
Beginner
Posts: 11
Joined: Mon Feb 14, 2022 5:40 pm

Re: New controller for the crazyflie 2.1

Post by HazarB »

Thank you so much,But in my project i need to design the attitude controler so i need to send the PWM to each motor separetly any idea how to do this
and im not using ROS.
I tried to find a python script for that but unfortunately i didn't.
thank you so much.
kimberly
Bitcraze
Posts: 1050
Joined: Fri Jul 06, 2018 11:13 am

Re: New controller for the crazyflie 2.1

Post by kimberly »

I think that this forum thread is suitable for you about controlling the motor controls directly: viewtopic.php?t=5258

It doesn't work by standard and using the parameters framework will be to slow. Also in general the communication delay will make it close to impossible to control the motors directly offboard (or so I have been told by mutliple control experts). Giving desired attitude rate commands however does seem to work, but then you would need to adjust the crazyflie python library for that.

Are you by any chance taking the ETH zurich's course on quadcopters? Because if so, then you don't need to worry about any of this at all I know for a fact :)
HazarB
Beginner
Posts: 11
Joined: Mon Feb 14, 2022 5:40 pm

Re: New controller for the crazyflie 2.1

Post by HazarB »

Thank you so much and sorry for taking time to answer.

So finally, we have decided to implement a new controller(Atttitude Rate controller) inside the crazyflie 2.1.
The thing that we will do, is to design the controller in simulink, build it and then deploy it in crazyflie 2.1.

So my qyestions are:
-Is there any tool that i can use to deploy the c genrated code from simulink in crazyflie 2.1.
-If not, i think i will do that manually, placing the generated files in the firmware folder, so which files that will be changed i mean designing new controller will affect which files.
-And finally you think that using simulink to build the controller will be a good idea i mean the building files will be suitable to directly be flashed in crazyflie 2.1.

Sorry for asking too many questions.
Thank you.
kimberly
Bitcraze
Posts: 1050
Joined: Fri Jul 06, 2018 11:13 am

Re: New controller for the crazyflie 2.1

Post by kimberly »

Hi!

Sorry for the delay, due to the easter holiday.

- Sure there is some kind of Matlab to c converter, but never really heard of anything that does that from simulink blocks. Usually people integrate it themselves in c from scratch.

So in that sense... I don't think that automatically generating c files from simulink that is compatible with the c-firmware. It would require a lot of own hacking and knowing the firmware, and the easiest would just be just to write it from scratch yourself. Try to get inspiration of how the attitude pid controller is implemented.
HazarB
Beginner
Posts: 11
Joined: Mon Feb 14, 2022 5:40 pm

Re: New controller for the crazyflie 2.1

Post by HazarB »

Thank you for your response.
I will take that in consideration, thank you for that.
According to how PID controller is designed i think to make new controller I will change these files :
stabilizer.c
controller-new controller
controller.new controller
attitude-controller-new-controller
attitude-controller-new-controller


Another question, about the delay of communication '''''''communication delay will make it close to impossible to control the motors directly off board (or so I have been told by multiple control experts).'''''' Any idea how to prove that, I mean any idea how to plot some curves and see the delay.
I have tried to write a python script, where I will send and receive data and calculate the delay of response but because i can't send and receive in same time it will be impossible to plot the delay.

Thank you so much.
kimberly
Bitcraze
Posts: 1050
Joined: Fri Jul 06, 2018 11:13 am

Re: New controller for the crazyflie 2.1

Post by kimberly »

oke cool! Let us know if it works out

About that comment about the delay, it will be quite difficult to proof this... as it will be impossible to correctly sync up the data.

But anyway, the delay comment is kind of compiled from feedback from several advanced users that used the crazyflie to try to control it to that level, and all came to the conclusion that controlling the motors directly through crazyradio was too difficult to do. But no, there is no exact proof.
Post Reply