diff --git a/src/modules/interface/power_distribution.h b/src/modules/interface/power_distribution.h index 8167514d35..59583312d8 100644 --- a/src/modules/interface/power_distribution.h +++ b/src/modules/interface/power_distribution.h @@ -31,6 +31,7 @@ void powerDistributionInit(void); bool powerDistributionTest(void); void powerDistribution(const control_t *control); +void powerDistributionDirect(const setpoint_t *setpoint); void powerStop(); diff --git a/src/modules/src/power_distribution_stock.c b/src/modules/src/power_distribution_stock.c index 0e66c0b85e..f9ded0afa1 100644 --- a/src/modules/src/power_distribution_stock.c +++ b/src/modules/src/power_distribution_stock.c @@ -107,6 +107,31 @@ void powerDistribution(const control_t *control) } } + +void powerDistributionDirect(const setpoint_t *setpoint) +{ + // expects floats as thrust measure as percentage in the range 0 to 100.0 + motorPower.m1 = limitThrust((int) (setpoint->motorControl.topLeft/100.0f * 65536)); + motorPower.m2 = limitThrust((int) (setpoint->motorControl.topRight/100.0f * 65536)); + motorPower.m3 = limitThrust((int) (setpoint->motorControl.bottomLeft/100.0f * 65536)); + motorPower.m4 = limitThrust((int)(setpoint->motorControl.bottomRight/100.0f * 65536)); + // TODO unsure what this flag does + if (motorSetEnable) + { + motorsSetRatio(MOTOR_M1, motorPowerSet.m1); + motorsSetRatio(MOTOR_M2, motorPowerSet.m2); + motorsSetRatio(MOTOR_M3, motorPowerSet.m3); + motorsSetRatio(MOTOR_M4, motorPowerSet.m4); + } + else + { + motorsSetRatio(MOTOR_M1, motorPower.m1); + motorsSetRatio(MOTOR_M2, motorPower.m2); + motorsSetRatio(MOTOR_M3, motorPower.m3); + motorsSetRatio(MOTOR_M4, motorPower.m4); + } +} + PARAM_GROUP_START(motorPowerSet) PARAM_ADD(PARAM_UINT8, enable, &motorSetEnable) PARAM_ADD(PARAM_UINT16, m1, &motorPowerSet.m1) diff --git a/src/modules/src/stabilizer.c b/src/modules/src/stabilizer.c index 48f436f22d..7590b131b3 100644 --- a/src/modules/src/stabilizer.c +++ b/src/modules/src/stabilizer.c @@ -129,17 +129,21 @@ static void stabilizerTask(void* param) commanderGetSetpoint(&setpoint, &state); - sitAwUpdateSetpoint(&setpoint, &sensorData, &state); + // Update of setpoint according to current state seems unnecessary + //sitAwUpdateSetpoint(&setpoint, &sensorData, &state); - stateController(&control, &setpoint, &sensorData, &state, tick); + // Seems also unnecessary but we could include some ramping or of course an actual controller + //stateController(&control, &setpoint, &sensorData, &state, tick); checkEmergencyStopTimeout(); - if (emergencyStop) { - powerStop(); - } else { - powerDistribution(&control); - } + // if (emergencyStop) { + // powerStop(); + // } else { + //FIXME I would maybe overload the power distribution directly on the setpoint_t struct + //powerDistribution(&control); + powerDistributionDirect(&setpoint); + // } tick++; }