Skip to content

Commit

Permalink
Move controlManual down
Browse files Browse the repository at this point in the history
  • Loading branch information
okalachev committed Dec 13, 2023
1 parent dbedf2a commit 9a12ae9
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions flix/control.ino
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,21 @@ void controlAttitude()
}
}

// passthrough mode
void controlManual()
void controlRate()
{
if (controls[RC_CHANNEL_THROTTLE] < 0.1) {
if (!armed) {
memset(motors, 0, sizeof(motors));
rollRatePID.reset();
pitchRatePID.reset();
yawRatePID.reset();
return;
}

torqueTarget = ratesTarget * 0.01;
Vector ratesFiltered = ratesFilter.update(rates);

torqueTarget.x = rollRatePID.update(ratesTarget.x - ratesFiltered.x, dt); // un-normalized "torque"
torqueTarget.y = pitchRatePID.update(ratesTarget.y - ratesFiltered.y, dt);
torqueTarget.z = yawRatePID.update(ratesTarget.z - ratesFiltered.z, dt);

motors[MOTOR_FRONT_LEFT] = thrustTarget + torqueTarget.y + torqueTarget.x - torqueTarget.z;
motors[MOTOR_FRONT_RIGHT] = thrustTarget + torqueTarget.y - torqueTarget.x + torqueTarget.z;
Expand All @@ -149,21 +155,15 @@ void controlManual()
motors[3] = constrain(motors[3], 0, 1);
}

void controlRate()
// passthrough mode
void controlManual()
{
if (!armed) {
if (controls[RC_CHANNEL_THROTTLE] < 0.1) {
memset(motors, 0, sizeof(motors));
rollRatePID.reset();
pitchRatePID.reset();
yawRatePID.reset();
return;
}

Vector ratesFiltered = ratesFilter.update(rates);

torqueTarget.x = rollRatePID.update(ratesTarget.x - ratesFiltered.x, dt); // un-normalized "torque"
torqueTarget.y = pitchRatePID.update(ratesTarget.y - ratesFiltered.y, dt);
torqueTarget.z = yawRatePID.update(ratesTarget.z - ratesFiltered.z, dt);
torqueTarget = ratesTarget * 0.01;

motors[MOTOR_FRONT_LEFT] = thrustTarget + torqueTarget.y + torqueTarget.x - torqueTarget.z;
motors[MOTOR_FRONT_RIGHT] = thrustTarget + torqueTarget.y - torqueTarget.x + torqueTarget.z;
Expand Down

0 comments on commit 9a12ae9

Please sign in to comment.