Skip to content

Commit

Permalink
Keep yaw setpoint within +/-delta from the current yaw (#831)
Browse files Browse the repository at this point in the history
  • Loading branch information
matejkarasek authored Nov 18, 2021
1 parent 62d0126 commit e0bd515
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/modules/src/controller_pid.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,20 @@ void controllerPid(control_t *control, setpoint_t *setpoint,
if (RATE_DO_EXECUTE(ATTITUDE_RATE, tick)) {
// Rate-controled YAW is moving YAW angle setpoint
if (setpoint->mode.yaw == modeVelocity) {
attitudeDesired.yaw += setpoint->attitudeRate.yaw * ATTITUDE_UPDATE_DT;
attitudeDesired.yaw = capAngle(attitudeDesired.yaw + setpoint->attitudeRate.yaw * ATTITUDE_UPDATE_DT);

#ifdef YAW_MAX_DELTA
float delta = capAngle(attitudeDesired.yaw-state->attitude.yaw);
// keep the yaw setpoint within +/- YAW_MAX_DELTA from the current yaw
if (delta > YAW_MAX_DELTA)
{
attitudeDesired.yaw = state->attitude.yaw + YAW_MAX_DELTA;
}
else if (delta < -YAW_MAX_DELTA)
{
attitudeDesired.yaw = state->attitude.yaw - YAW_MAX_DELTA;
}
#endif
} else {
attitudeDesired.yaw = setpoint->attitude.yaw;
}
Expand Down
3 changes: 3 additions & 0 deletions tools/make/config.mk.example
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,6 @@
# CFLAGS += -DIMU_PHI=0.0f
# CFLAGS += -DIMU_THETA=0.0f
# CFLAGS += -DIMU_PSI=0.0f

## Keep the yaw setpoint within +/- YAW_MAX_DELTA from the current heading
# CFLAGS += -DYAW_MAX_DELTA=45.0f

0 comments on commit e0bd515

Please sign in to comment.