Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Brushless type config bug #1277

Open
knmcguire opened this issue May 8, 2023 · 0 comments
Open

Brushless type config bug #1277

knmcguire opened this issue May 8, 2023 · 0 comments

Comments

@knmcguire
Copy link
Member

Currently there is the following kconfig variable called: ENABLE_THRUST_BAT_COMPENSATED. This compensates the thrust based on the current battery level:

// We have data that maps PWM to thrust at different supply voltage levels.
// However, it is not the PWM that drives the motors but the voltage and
// amps (= power). With the PWM it is possible to simulate different
// voltage levels. The assumption is that the voltage used will be an
// procentage of the supply voltage, we assume that 50% PWM will result in
// 50% voltage.
//
// Thrust (g) Supply Voltage PWM (%) Voltage needed
// 0.0 4.01 0 0
// 1.6 3.98 6.25 0.24875
// 4.8 3.95 12.25 0.49375
// 7.9 3.82 18.75 0.735
// 10.9 3.88 25 0.97
// 13.9 3.84 31.25 1.2
// 17.3 3.80 37.5 1.425
// 21.0 3.76 43.25 1.6262
// 24.4 3.71 50 1.855
// 28.6 3.67 56.25 2.06438
// 32.8 3.65 62.5 2.28125
// 37.3 3.62 68.75 2.48875
// 41.7 3.56 75 2.67
// 46.0 3.48 81.25 2.8275
// 51.9 3.40 87.5 2.975
// 57.9 3.30 93.75 3.09375
//
// To get Voltage needed from wanted thrust we can get the quadratic
// polyfit coefficients using GNU octave:
//
// thrust = [0.0 1.6 4.8 7.9 10.9 13.9 17.3 21.0 ...
// 24.4 28.6 32.8 37.3 41.7 46.0 51.9 57.9]
//
// volts = [0.0 0.24875 0.49375 0.735 0.97 1.2 1.425 1.6262 1.855 ...
// 2.064375 2.28125 2.48875 2.67 2.8275 2.975 3.09375]
//
// p = polyfit(thrust, volts, 2)
//
// => p = -0.00062390 0.08835522 0.06865956
//
// We will not use the constant term, since we want zero thrust to equal
// zero PWM.
//
// And to get the PWM as a percentage we would need to divide the
// Voltage needed with the Supply voltage.
float motorsCompensateBatteryVoltage(uint32_t id, float iThrust, float supplyVoltage)
{
#ifdef CONFIG_ENABLE_THRUST_BAT_COMPENSATED
ASSERT(id < NBR_OF_MOTORS);
if (motorMap[id]->drvType == BRUSHED)
{
/*
* A LiPo battery is supposed to be 4.2V charged, 3.7V mid-charge and 3V
* discharged.
*
* A suitable sanity check for disabling the voltage compensation would be
* under 2V. That would suggest a damaged battery. This protects against
* rushing the motors on bugs and invalid voltage levels.
*/
if (supplyVoltage < 2.0f)
{
return iThrust;
}
float thrust = (iThrust / 65536.0f) * 60;
float volts = -0.0006239f * thrust * thrust + 0.088f * thrust;
float ratio = volts / supplyVoltage;
return UINT16_MAX * ratio;
}
#endif
return iThrust;
}

In Kconfig this setting is on by default, but for brushless types or anything with a different motor, this should probably be turned off. We should add it to the kconfig for the bolt and or other brushless types.

Mind that we now also have the upgrade kit, so that these values are not valid as soon somebody replaces the motors and propellers, but that is more related to #936

@knmcguire knmcguire added the bug label May 8, 2023
@knmcguire knmcguire added enhancement and removed bug labels Oct 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant