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

WIP Setting powerdistribution directly from setpoint message #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/modules/interface/power_distribution.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
void powerDistributionInit(void);
bool powerDistributionTest(void);
void powerDistribution(const control_t *control);
void powerDistributionDirect(const setpoint_t *setpoint);
void powerStop();


Expand Down
25 changes: 25 additions & 0 deletions src/modules/src/power_distribution_stock.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 11 additions & 7 deletions src/modules/src/stabilizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
}
Expand Down