Accessing sensor information in selfmade attitude controller

Firmware/software/electronics/mechanics
Post Reply
joyner
Beginner
Posts: 15
Joined: Mon Nov 18, 2019 12:37 pm

Accessing sensor information in selfmade attitude controller

Post by joyner »

Hey all,

I have developed an attitude controller for the crazyflie which I soon want to implement on the firmware. The input variables are as following:

Setpoints given by any input device:
- ascent/descent speed (in the direction of the intertial frame z-axis)
- yaw rate (angular velocity)
- Pitch- and Rollangle

The 4 corresponding actual values given by sensors (in my case calculated with model equations):
- ascent/descent speed (in the direction of the intertial frame z-axis)
- yaw rate (angular velocity)
- Pitch- and Rollangle

and as it is a cascaded Controller, it also needs:
- ascent/descent acceleration (in the direction of the intertial frame z-axis)
- angular velocities of Pitch- and Rollangle

The output values are the 4 input command values (cmd) to control the motors. I created a c-file containing the controller calculations and I want to implement it on the crazyflie to replace the original attitude controller in the firmware.

My questions for now: Is it possible to get the above named values from the firmware? Is there a function which calculates the Pitch- and Rollangle? And how can I access the values (including setpoints) in my code? Later I want to control the crazyflie using the USB-dongle.
And how can I set the input command values (cmd) respectively commit them to the motor controller?

I just started trying to implement my controller and already facing lot of difficulties. I'd be very glad if anybody can help or knows where I can find further information. I couldn't find any information in the documentations so far.

Kind regards,
Joyner
arnaud
Bitcraze
Posts: 2538
Joined: Tue Feb 06, 2007 12:36 pm

Re: Accessing sensor information in selfmade attitude controller

Post by arnaud »

Hi,

Controller implementation is quite modular in the Crazyflie so you should be able to implement your controller in parallel with the existing one and enable it dynamically. There is actually already two controller implemented currently. The top of the stabilizer loop is the right place to start to understand how the Crazyflie control loop is working: https://github.com/bitcraze/crazyflie-f ... zer.c#L248

Controllers are declared in controller.c: https://github.com/bitcraze/crazyflie-f ... ntroller.c. As you can see in this file, each controller is expected to provide an update function that takes-in the setpoint, sensors data, the current state estimation and the time expressed in 1KHz tick. The update function needs to fill up the control_t structure with the motor control values. The update function is called at 1KHz.

The best is to look at the definition of all the structures passed in and out of the update function to see what you are getting, As far as I can tell, all you need should be in these structures. The definitions are in https://github.com/bitcraze/crazyflie-f ... er_types.h. Units are documented for most fields, the tricky one is the output control though: the values are expressed in percentage of the motor thrust with 0% encoded as 0 and 100% encoded as 65535. This is something we have been meaning to fix by having SI units for thrust and torque instead.

As for the setpoints structure, it is filled up by commander packets. Either you find one commander packet that implements what you need, of you will have to implement your own. On the crazyflie the commander packets are implemented there: https://github.com/bitcraze/crazyflie-f ... eric.c#L39 and there on the python side: https://github.com/bitcraze/crazyflie-l ... mmander.py.
joyner
Beginner
Posts: 15
Joined: Mon Nov 18, 2019 12:37 pm

Re: Accessing sensor information in selfmade attitude controller

Post by joyner »

Thanks a lot Arnaud! This will help me to better understand the code.
Post Reply