How to obtain thrust from PWM

Firmware/software/electronics/mechanics
Max_Kemmeren
Member
Posts: 40
Joined: Wed Jan 20, 2021 4:03 pm

How to obtain thrust from PWM

Post by Max_Kemmeren »

Dear all,

I am developing a controller based of the INDI such that the crazyflie will be able to fly close to the ceiling or other flight boundaries (For my MsC thesis). For this I now need an estimate of the thrust that will be produced under a certain PWM signal.

What I now got is a logging script logging the following: Accelerometer data (acc.z), motor data (motor.m1) and motor pwm data (pwm.m1_PWM). But i do not understand all of this data.

For the accelerometer the value equals 1 during hover, this seems logical as it only feels the gravitational acceleration which is 1g, if the coordinate frame has z pointing downwards, is this correct?

Then for both the motor and pwm data the values range between 0 and 65536. What I get from the firmware code (motors.c) is that the pwm.m1_pwm data is the pwm signal but compensated for the battery voltage, am I correct? And my guess is that the motor.m1 data is the pwm signal not compensated for battery voltage, correct?

Lastly is there an estimated formula to change the 0-65536 range to thrust in newton? I found this page (https://www.bitcraze.io/2015/02/measuri ... pm-part-3/) but the graph with PWM to thrust uses different values for the PWM.

Thanks in advance for helping.

Greetings
Max Kemmeren
whoenig
Expert
Posts: 395
Joined: Mon Oct 27, 2014 2:55 am

Re: How to obtain thrust from PWM

Post by whoenig »

All your guesses are correct!

For the last one (battery voltage compensation), this is just an approximation and not necessarily up-to-date with the current hardware. You can find a better mapping in Table 1, https://arxiv.org/pdf/2012.05457.pdf, which was obtained from a force stand. We are planning to integrate this in the official firmware, such that a controller could just output force and torque in SI units, and the rest is handled automatically in the power distribution. Would that be useful for your use-case?
Max_Kemmeren
Member
Posts: 40
Joined: Wed Jan 20, 2021 4:03 pm

Re: How to obtain thrust from PWM

Post by Max_Kemmeren »

Thanks for the answer.

What I need for my controller is the ratio between command applied (thrust command) and the actual measured thrust. For now I wanted to do this in the following manner. Using the accelerometer data (z-axis), and then using the simple relationship f=m*a to gather measured thrust. One thing what is the axis system in which the acceleration measurements are logged? Is it body frame with z-axis pointing down?

To get the commanded thrust I was looking into the command send to the motors and convert that to the thrust that is expected from that command. So it would be helpful if I either got a relationship for that or what you say a thrust command can be given to the drone instead of method which is implemented now.

If you are going to implement it what is the planning for it?

Greetings
Max Kemmeren
whoenig
Expert
Posts: 395
Joined: Mon Oct 27, 2014 2:55 am

Re: How to obtain thrust from PWM

Post by whoenig »

The accelerometer is in the body frame using a right-handed coordinate system with z-axis pointing up. You can also test this pretty easily if you use the CFClient and log the "acc.{x,y,z}" variables and visualize them in the Plotter tab. This signal tends to be pretty noisy and you will have much better data if you use a CF 2.1 over a CF 2.0.

For the second part (obtaining commanded thrust), you can simply use psi_1 in the paper that I listed earlier ("small" quadrotor). You will need as input the normalized PWM (i.e., PWM / 65536) and normalized battery voltage (i.e., voltage / 4.2). This equation will output the force of a single motor in grams, so you'll need to convert it to N or any other unit you use. To obtain the total thrust, repeat the procedure for each motor.

I have a prototype for the SI-unit based power distribution, but no concrete timeline on when this will be clean enough to be in the official master branch. From your description, it sounds like you might not need it for your purpose, though?
Max_Kemmeren
Member
Posts: 40
Joined: Wed Jan 20, 2021 4:03 pm

Re: How to obtain thrust from PWM

Post by Max_Kemmeren »

Thanks!!!

Yes I have the crazyflie 2.1.

Ah I see the explanation of the formula is few pages later (read past it, so was not sure what the formula meant).

No if this works I will not be needing it.

Thanks a lot for the quick answers it really helped me!

Greetings
Max
Max_Kemmeren
Member
Posts: 40
Joined: Wed Jan 20, 2021 4:03 pm

Re: How to obtain thrust from PWM

Post by Max_Kemmeren »

Hi

I have a question. I have calculated the thrust via the formula provided in the paper and the signal logging of pwm.m1_pwm (the motor pwm compensated for battery voltage). This is the blue line seen in the graph. The orange line is using the accelerometer data from the body z-axis and uses f=m*a to calculate the thrust.

What can be noticed is that there is an offset between the lines, this offset seems somewhat constant. What could cause this? As during hover I expect the engines to produce the thrust equal to 1g of acceleration. (and thus the lines needing to be almost equal).

The graph shows force in Newton on the y-axis and time on the x-axis. The hover flight starts around 4 seconds and lasts 5 seconds.
Attachments
Screenshot from 2021-04-01 13-55-57.png
whoenig
Expert
Posts: 395
Joined: Mon Oct 27, 2014 2:55 am

Re: How to obtain thrust from PWM

Post by whoenig »

I can think of multiple reasons:

1. Unbalanced rotors, i.e., during hover your PWM is actually not the same for all motors. You can look at m1-m4 and apply the transformation to each of them.
2. Numerical issues. The paper only shows 2 digits. Here are the full parameters:

Code: Select all

C_00 = 11.093358483549203
C_10 = -39.08104165843915
C_01 = -9.525647087583181
C_20 = 20.573302305476638
C_11 = 38.42885066644033
3. Worn out motors/propellers. I haven't really seen this in practice, but the data provided in the paper was only checked with 3 different Crazyflies (& different batteries). I think the only way to address this, would be to build a force stand. We are in the process of building one at Bitcraze, which is an improved version of the one that I built for the paper cited earlier. You can find some preliminary documentation and analysis scripts at https://github.com/bitcraze/crazyflie-f ... /README.md.
DarkKnight
Member
Posts: 39
Joined: Tue Jun 15, 2021 10:19 pm

Re: How to obtain thrust from PWM

Post by DarkKnight »

Hello,

I have done following experiment: I let the Crazyflie hover for 100 seconds, and I logged the stabilizer.thrust(this is thrust percentage mapped to a uint16_t, where 0 is no trust and 65535 is full thrust.). I used following formula to calculate the thrust (the unit is g, according to your website, the total thrust is about 60g):thrust = (thrust_ratio/65536)*60. Therefore, I can get the mean thrust is about 37g, but if I use a Electronic scale, the weight of the crazyflie2.1(include the markers which is use for motion capturing) is 32g. so there is about 5g error, is this an acceptable error?

I also logged the pwm.m1_pwm to pwm.m4_pwm(this is pwm percentage mapped to a uint16_t, where 0 is no pwm and 65535 is full pwm.), then I used the relation about PWM vs thrust from here(pwm vs thrust: thrust(g) = 0.409e-3*pwm^2+140.5e-3*pwm-0.099, in this formula, the pwm is represented by 8bit value):https://wiki.bitcraze.io/misc:investigations:thrust. of course, before I used this formula, I convert the pwm percentage from uint16_t to 8 bit.

I put the thrust vs pwm plot in the attachment. According to the plot, the thrust from each motor is different, also they all greater than 30g(if this is true, the total thrust is greater than 30*4=120g? I don't believe that). is there anything that I do it wrong?

Thanks
Attachments
thrust vs pwm.png
tobias
Bitcraze
Posts: 2339
Joined: Mon Jan 28, 2013 7:17 pm
Location: Sweden

Re: How to obtain thrust from PWM

Post by tobias »

The battery voltage will influence how much thrust the motors can generate and I think this is one of the major thing that you see here. 60g thrust is only true for a fully charged battery.

The graph you are referring to is showing the combined thrust of all motors, thus should be divided by 4 to get single motor thrust.
lin24016
Beginner
Posts: 5
Joined: Mon Oct 18, 2021 9:05 am

Re: How to obtain thrust from PWM

Post by lin24016 »

Hey I am also working on the mapping from PWM to thrust these days and I am a bit confused about the log variables and the formulas.

For the voltage compensation formula, which PWM should I use? The raw PWM (motor.m1) or the already compensated one (pwm.m1_pwm).
BTW, I logged the voltage data from pm.vbat and used it for calculation. Is it the correct data?

Thanks in advance
Post Reply