Implement new controller for autonomous flight #91
-
Hi, I'm trying to implement a brand new controller on the crazyflie so that it can fly autonomously. Basically I'd like the controller to use position, linear velocity, angular velocity, and quaternion as its state, and generate required thrust for each motor as command. However, I'm constantly getting lost due to the complexity of firmware. I wonder whether you have any suggestions on which files to modify and where to start. I've noticed that with the PID and INDI controller, position and attitude controller are implemented in different files. I'd like to implement the computation for everything in just one file, so I'm assuming I can follow the structure of Mellinger controller, not sure if this is right though. In addition, I'm using the Loco Positioning System for positioning data, which is also part of the controller's state, how should I integrate the output of LPS with the controller? Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 10 replies
-
Hi! Controllers are plugins (sort of) and should be pretty straight forward to add. Controllers are registered in https://github.com/bitcraze/crazyflie-firmware/blob/master/src/modules/src/controller.c#L24-L29 Add a new identifier in https://github.com/bitcraze/crazyflie-firmware/blob/master/src/modules/interface/controller.h#L31-L37 (after the ControllerTypeINDI but before ControllerType_COUNT) Add a new c-file for your controller and add it to the Kbuild file https://github.com/bitcraze/crazyflie-firmware/blob/master/src/modules/src/Kbuild#L10-L13. You can start from the mellinger controller if you like or just make a new file, the only thing that is important is that you implement the three functions. Your init function should initialize data. It will be called when the controller is activated. Your update function will be called from the stabilizer loop (at 1000 Hz) and the task is essentially to fill in the values in the control struct (roll, pitch, yaw and thrust). You get at bunch of information in the other structs that you can use to understand the state of the world.
In the standard implementation, the Loco data is fed to the estimator and is fused with other sensor data there. You will get the information implicitly in the controller through the |
Beta Was this translation helpful? Give feedback.
-
Hi. First of all, an apology for using this issue, but I am also looking for how to implement my own control law only that I am using optitrck cameras, so I would like to know, what lines of code do I have to use to program a new controller?, given that as mentioned, it is hard to understand the code in general. I'd appreciate your help. |
Beta Was this translation helpful? Give feedback.
Hi!
Controllers are plugins (sort of) and should be pretty straight forward to add.
Controllers are registered in https://github.com/bitcraze/crazyflie-firmware/blob/master/src/modules/src/controller.c#L24-L29
As you can see you have to implement 3 functions (init, test and update) that you pass on to the system in the registration.
Add a new line in the registration after the INDI controller and add your functions here.
Add a new identifier in https://github.com/bitcraze/crazyflie-firmware/blob/master/src/modules/interface/controller.h#L31-L37 (after the ControllerTypeINDI but before ControllerType_COUNT)
Add a new c-file for your controller and add it to the Kbuild file https://github.c…