diff --git a/src/shared/algorithms/Follower/Follower.cpp b/src/shared/algorithms/Follower/Follower.cpp index d4551e5bc7fa7f0f3dc1c120ea76a63037a8c6da..e7a8d4e74837baa54f8976aa6d231c71a2833b9f 100644 --- a/src/shared/algorithms/Follower/Follower.cpp +++ b/src/shared/algorithms/Follower/Follower.cpp @@ -117,6 +117,8 @@ AntennaAngles Follower::getTargetAngles() bool Follower::setMaxGain(float yawGainNew, float pitchGainNew) { + Lock<FastMutex> lock(followerMutex); + // In case of negative or over the limit values, do not set the gains if (yawGainNew < 0 || yawGainNew > YAW_GAIN_LIMIT || pitchGainNew < 0 || pitchGainNew > PITCH_GAIN_LIMIT) @@ -170,13 +172,13 @@ void Follower::step() // Calculate the amount to move from the current position diffAngles = {targetAngles.timestamp, targetAngles.yaw - vn300.yaw, targetAngles.pitch - vn300.pitch}; - } - // Rotate in the shortest direction - diffAngles.yaw = - std::min(yawGain, YAW_GAIN_LIMIT) * minimizeRotation(diffAngles.yaw); - diffAngles.pitch = std::min(pitchGain, PITCH_GAIN_LIMIT) * - minimizeRotation(diffAngles.pitch); + // Rotate in the shortest direction + diffAngles.yaw = std::min(yawGain, YAW_GAIN_LIMIT) * + minimizeRotation(diffAngles.yaw); + diffAngles.pitch = std::min(pitchGain, PITCH_GAIN_LIMIT) * + minimizeRotation(diffAngles.pitch); + } // Calculate angular velocity for moving the antennas toward position float horizontalSpeed =