Page 1 of 1

Autonomous embedded flight system

Posted: Mon Jun 19, 2017 9:53 am
by carlos
Hello!

I have been working a few weeks with a Crazyflie 2.0 using the python library.
Now I'm supposed to start to develop a embedded system that runs into the CF2, without receiving orders from a computer . Everything should be autonomously running inside.
I thought that trying to do a simple take off - landing routine would be ok in order to get to grips with the firmware and so on.
The problem is that i have been analyzing the firmware for a few days and I dont even know how to set the thrust of the motors in order to take off.

I'm even starting to doubt if is possible to this without rewriting the whole firmware.

Hope you can help a desperate man


Carlos

Re: Autonomous embedded flight system

Posted: Tue Jun 27, 2017 8:53 am
by arnaud
Hi Carlos,

Controlling the crazyflie from within the firmware is possible and you do not need to rewrite everything, though this is not something we have done a lot (yet...)

You can look at out ICRA demo, it is running a program that runs the crazyflie completely autonomously, no computer in the loop. The autonomous part is implemented from this file: https://github.com/bitcraze/crazyflie-f ... ace.c#L157. We talked about it on the blog, the crazyflie is controlled using simple buttons: https://www.bitcraze.io/2017/05/demo-for-icra-2017/

This is the first time we try to run things completly autonomous so there is some hack here and there but the most important is part of the official firmware: it is possible to set the setpoint from within the crazyflie with a priority setting that sets if the setpoint has more or less priority than the setpoint sent by the python lib from the ground: https://github.com/bitcraze/crazyflie-f ... ace.c#L333

We took some videos of this demo: the base retrace code https://www.youtube.com/watch?v=csbXiC-pLK4 and the demo at ICRA: https://www.youtube.com/watch?v=hIH3bwq2B6U

Re: Autonomous embedded flight system

Posted: Mon Oct 30, 2017 5:32 pm
by UMD_bioinformatics
@arnaud,

I have been banging my head attempting to see where I can change the firmware in order to be able to modify setpoints within the firmware.

What would be nice to do:

Read a setpoint
Read some sensor information using I2C
Perform some computation
Send a setpoint as a result


I am having a blast controlling the crazyflie using the python lib (I built off of the figure 8 example), but, as a start, I would like to to do the same thing in firmware. I have gone through the experimental firmware, but (and I admittedly know a limited amount of embedded systems) the examples there are highly convolved with the use of the locodeck, which I am not using nor intend to.

How can I do this?

Thanks

UMD IBIS Lab

Re: Autonomous embedded flight system

Posted: Tue Oct 31, 2017 4:21 pm
by kristoffer
Hi Carlos!

Yes, embedded systems are a bit different from a python script. There is not really an application layer in the Crazyflie (even though we have discussed adding one) where you easily can add what you want to do.
Since there are no processes and threads in the same way as in a preemptive OS you must find a way to execute your code spread out over time. There are a few different ways to do it but the easiest might be to add a timer.

I did a Friday hack a while ago that does pretty much what you want to do (it is sort of the base of what we did for the ICRA demo as well). It can be a bit tricky to figure out what code you have to change but I think a good start is to take a look at commit
https://github.com/bitcraze/crazyflie-f ... eb8cc49cf2
This is where I added most of what you are looking for.

To break it down a bit
* src/modules/src/retrace.c implements your timer. It also contains a state machine that first waits for the Kalman filter to stabilise, then records the current position of the copter and then finally retraces the path it moved by changing the set point (when dropped).
* src/modules/src/estimator_kalman.c - changes to expose data in the module that are required by retrace.c
* src/modules/src/sitaw.c - (sitaw = Situation Awareness) This module keeps track of the current situation and if the Crazyflie is tumbling or free falling. The change here simply enables the free fall detection. A callback in retrace.c is registered to be called when the copter if free falling and this is used to switch from recording to retrace mode.
* src/modules/src/system.c - initialisation of the retrace timer
* Makefile - added the new c file to be compiled and also turned on situation awareness. The ESTIMATOR part is not needed any more.

Note: In this example I used the Loco Positioning system.

Sensor data is used by the stabilizer task and this might be a good place for you to access it. There is a state variable called "sensorData" in stabilizer.c that might be useful for you?

I hope this might give you some more ideas of how to move on!