Page 1 of 1

My off-board position control

Posted: Wed Jul 20, 2016 10:09 pm
by CrazyGuy
I create a new topic since it's off-topic in the other thread viewtopic.php?f=12&p=10650&sid=920b59f8 ... e1e#p10650

Here's a demonstration of the off-board position control I implemented. See the description for more informations.
The attitude control works fine. The position control could be a bit better. But nevertheless I'm happy with my results so far.

https://www.youtube.com/watch?v=TUU_0AYWWOE

Re: My off-board position control

Posted: Fri Jul 22, 2016 6:31 am
by arnaud
That looks great! It is quite impressive that you have so good control with the radio in the middle, I know others have tried and not succeeded because of the latency induced by the radio link.

Is the PC part implemented using the python lib or have you implemented your own in another language?

The 3D positioning is also impressive, are you using only 1 camera? How are you estimating the depth? Size of the copter?

Great job and thanks for sharing!

Re: My off-board position control

Posted: Fri Jul 22, 2016 10:56 am
by CrazyGuy
Hi and thanks :)

My client is based on the c-client by Jan Winkler: https://github.com/fairlight1337/libcflie

My first tries to implement the off-board control also failed. I was using your logging system (logging system on the crazyflie-firmware unchanged). But I'm not quite sure why it didn't work. I also tried to increase the priority of the logging on the crazyflie-firmware but that wasn't successful either.

So I decided to not use your logging routine at all. All I do is:
[*] send a commander packet from the client to the crazyflie
[*] if a commander packet arrives at commander.c (commanderCrtpCB), the containing motorratios are applied and a packet containing the euler- and gyro-data are sent back to the client via crtpSendPacket. For this packet I'm using an own port (0x08).

The euler- and gyro-data are updated every 2ms in stabilizer.c (stabilizerTask). In this case (that the motorratios are calculated on the client) stabilizerTask calls also an adepted commanderWatchdog. But that's all stabilizerTask does in this case.


I'm using two cameras to determine the 3D position. The video shows only the images of the first one. Btw: The center of the red circle marks the tracked crazyflie in the image. But the radius is always constant. So it doesn't contain any information about the location or the size of the crazyflie.

Re: My off-board position control

Posted: Fri Jul 22, 2016 11:29 am
by arnaud
Thanks for the precision, I am not surprised for the log since it was not designed to be used for such hard-realtime case. Your solution sounds good to me. it is good to know that such things are possible.

Is there a reason why you chose an off-board approach instead of coding directly un the Crazyflie?

And, by the way, are you planing to push your code on github? :-)

Re: My off-board position control

Posted: Fri Jul 22, 2016 2:57 pm
by CrazyGuy
For the linear-quadratic regulator I need to solve the algebraic riccati equation. In the solver I have to invert matrices, calculate determinants and solve linear equations (that's why I also use the Eigen library). To be honest I didn't even try to implement those things on the crazyflie.
In the future I/we want a model predictive control for the crazyflie (ideally for the 12 dimensional control system, not two nested 6 dimensional systems).

Yes, I think I will push the code on github someday. But I don't know when exactly. It's part of my master thesis whose evaluation isn't finished yet. I don't know if there will be conflicts if I make the code public before I got my grade!?

Re: My off-board position control

Posted: Sun Jun 07, 2020 10:08 pm
by asr
I'm replying to a very old thread, but I wanted to say that it's great to see that off-board control is possible. However, there might also be a slightly simpler hybrid approach to getting a LQ-based controller to work with the Crazyflie. I'm in a similar boat at the moment, as I wrote a C++ based LQI controller (very similar to an LQR controller except it just includes integral action as well) which worked well in Gazebo with ROS, but it seemed like it would be tricky to get working with the Crazyflie due to message delay issues mentioned by arnuad. However, instead of writing everything from scratch again in the firmware using C (daunting to think about doing all of the linear algebra again), one approach would be to compute the static LQI gain matrix (if you're assuming time-invariant control, which works well for waypoint position control or trajectory following that isn't too "aerobatic") off-board, and send it via radio link to the Crazyflie to be saved in a on-board gain matrix as part of the controller initialization process. You can then write the remainder, and easier part, of the controller on-board in the firmware using C, which would use the gain matrix that was computed off-board with the state estimates that are computed on-board to compute desired motor speeds. This would allow for good motor control response times by removing the need to send state estimates off-board, computing the desired motor speeds and then sending those desired motor speeds back over the radio link.

Re: My off-board position control

Posted: Tue Feb 02, 2021 8:19 am
by DimChaik
Hi CrazyGuy,

impressive work. I was wondering if you did end up uploading your code in Github.
I would especially be interested in looking at how exactly you implemented the direct motor speed setting part on the Crazyflie.
Thank you

Re: My off-board position control

Posted: Tue Feb 23, 2021 8:07 pm
by ObserverShard
Thank you for the schedule of the process , only now I begin to understand what a huge work has been done.