THCLIP released

This commit is contained in:
Hakan Bastedt
2025-06-02 14:45:01 +02:00
parent eb1d76ad3f
commit e4c3f14809
12 changed files with 2104 additions and 321 deletions

View File

@@ -56,8 +56,11 @@ void cb_set_outputs(void) // Get Master outputs, slave inputs, first operation
}
float oldLowPassGain = 0;
float oldLowPassFilteredVoltage = 0;
uint32_t oldLowpassFilterPoleFrequency = 0;
uint32_t timeSinceOhmicSensingEnabled = 0;
void cb_get_inputs(void) // Set Master inputs, slave outputs, last operation
{
static float validData0 = 0.0, validVoltage0 = 0.0;
@@ -150,14 +153,32 @@ void cb_get_inputs(void) // Set Master inputs, slave outputs, last operation
float gain = oldLowPassGain;
if (oldLowpassFilterPoleFrequency != Obj.LowpassFilterPoleFrequency)
{
gain = 1 - expf(-2.0 * M_PI * Obj.LowpassFilterPoleFrequency * 1.0e-9 * ESC_SYNC0cycletime());
gain = 1 - expf(-2.0 * M_PI * Obj.LowpassFilterPoleFrequency * 0.001 /*1.0e-9 * ESC_SYNC0cycletime()*/);
oldLowPassGain = gain;
oldLowpassFilterPoleFrequency = Obj.LowpassFilterPoleFrequency;
}
if (Obj.CalculatedVoltage < Obj.LowPassFilterThresholdVoltage)
Obj.LowpassFilteredVoltage = Obj.CalculatedVoltage; // Just forward
else
Obj.LowpassFilteredVoltage += (Obj.CalculatedVoltage - Obj.LowpassFilteredVoltage) * gain;
Obj.LowpassFilteredVoltage = oldLowPassFilteredVoltage + (Obj.CalculatedVoltage - oldLowPassFilteredVoltage) * gain;
oldLowPassFilteredVoltage = Obj.LowpassFilteredVoltage;
Obj.OhmicSensingSensed = 0;
if (Obj.EnableOhmicSensing && stat == 0)
{
timeSinceOhmicSensingEnabled++; // Lazy and just use iterations now.
if (timeSinceOhmicSensingEnabled >= Obj.OhmicSensingSetupTime) // Let's check
{ //
if (Obj.CalculatedVoltage < Obj.OhmicSensingVoltageLimit) // Limit hit, set output
{
Obj.OhmicSensingSensed = 1;
}
}
}
else
{
timeSinceOhmicSensingEnabled = 0;
}
}
void ESC_interrupt_enable(uint32_t mask);