47 else if (angle < -180)
54 : updatePeriod{updPeriod}, targetAngles({0, 0, 0})
60 Lock<FastMutex> lock(followerMutex);
63 antennaCoordinatesSet =
true;
68 Lock<FastMutex> lock(followerMutex);
71 rocketCoordinatesSet =
true;
76 Lock<FastMutex> lock(followerMutex);
77 firstAntennaAttitudeSet =
true;
78 lastAntennaAttitude = attitudeData;
81VN300Data Follower::getLastAntennaAttitude()
83 Lock<FastMutex> lock(followerMutex);
84 return lastAntennaAttitude;
89 Lock<FastMutex> lock(followerMutex);
90 lastRocketNasState = nasState;
91 lastRocketNasStateSet =
true;
94NASState Follower::getLastRocketNasState()
96 Lock<FastMutex> lock(followerMutex);
97 return lastRocketNasState;
102 miosix::Lock<miosix::FastMutex> lock(followerMutex);
108 miosix::Lock<miosix::FastMutex> lock(followerMutex);
114 miosix::Lock<miosix::FastMutex> lock(followerMutex);
120 Lock<FastMutex> lock(followerMutex);
123 if (yawGainNew < 0 || yawGainNew > YAW_GAIN_LIMIT || pitchGainNew < 0 ||
124 pitchGainNew > PITCH_GAIN_LIMIT)
127 yawGain = yawGainNew;
128 pitchGain = pitchGainNew;
134 Lock<FastMutex> lock(followerMutex);
135 if (!antennaCoordinatesSet || !rocketCoordinatesSet)
137 LOG_ERR(logger,
"Antenna or rocket coordinates not set");
152 Lock<FastMutex> lock(followerMutex);
154 if (!firstAntennaAttitudeSet)
156 LOG_ERR(logger,
"Antenna attitude not set\n");
162 lastRocketNas = lastRocketNasState;
163 vn300 = lastAntennaAttitude;
167 rocketPosition = {lastRocketNas.n, lastRocketNas.e, lastRocketNas.d};
170 targetAngles = rocketPositionToAntennaAngles(rocketPosition);
173 diffAngles = {targetAngles.
timestamp, targetAngles.
yaw - vn300.yaw,
174 targetAngles.
pitch - vn300.pitch};
177 diffAngles.yaw = std::min(yawGain, YAW_GAIN_LIMIT) *
179 diffAngles.pitch = std::min(pitchGain, PITCH_GAIN_LIMIT) *
184 float horizontalSpeed =
185 std::abs((diffAngles.yaw) /
186 (360 * (
static_cast<float>(updatePeriod.count()) / 1000)));
187 TRACE(
"[Follower] horizontalSpeed is: %f\n", horizontalSpeed);
189 std::abs((diffAngles.pitch) /
190 (360 * (
static_cast<float>(updatePeriod.count()) / 1000)));
191 TRACE(
"[Follower] Vertical speed is: %f\n", horizontalSpeed);
194 FollowerState newState;
196 newState.yaw = diffAngles.yaw;
197 newState.pitch = diffAngles.pitch;
198 newState.horizontalSpeed = horizontalSpeed;
203 Lock<FastMutex> lockWrite(followerMutex);
208 std::cout <<
"[FOLLOWER] STEPPER " <<
"Angles: [" << newState.
yaw <<
", "
209 << newState.pitch <<
"] " <<
"Speed: ["
210 << newState.horizontalSpeed <<
", " << newState.verticalSpeed
211 <<
"] VN300 measure: [" << vn300.yaw <<
", " << vn300.pitch
216Eigen::Vector2f Follower::getAntennaCoordinates()
218 Lock<FastMutex> lock(followerMutex);
219 return Eigen::Vector2f{antennaCoordinates};
222Eigen::Vector3f Follower::getRocketNASOrigin()
224 Lock<FastMutex> lock(followerMutex);
225 return Eigen::Vector3f{rocketNASOrigin};
228AntennaAngles Follower::rocketPositionToAntennaAngles(
229 const NEDCoords& rocketNed)
232 Eigen::Vector2f antennaCoord = antennaCoordinates;
235 Eigen::Vector2f rocketCoord = rocketNASOrigin.head<2>();
240 NEDCoords ned = {rocketNed.n + antennaRocketDistance.x(),
241 rocketNed.e + antennaRocketDistance.y(), rocketNed.d};
243 AntennaAngles angles;
248 angles.yaw = std::atan2(ned.e, ned.n) / EIGEN_PI * 180;
250 float distance = std::sqrt(ned.n * ned.n + ned.e * ned.e);
252 angles.pitch = std::atan2(-ned.d, distance) / EIGEN_PI * 180;
#define LOG_ERR(logger,...)
FollowerState getState()
Synchronized getter for the State of the follower algorithm.
AntennaAngles getTargetAngles()
Getter for the target antenna position computed by the algorithm.
bool setMaxGain(float yawGainNew, float pitchGainNew)
Set the maximum gain for the yaw and pitch.
Follower(std::chrono::milliseconds updatePeriod)
Constructor of the follower class.
void setLastRocketNasState(const NASState &nasState)
Setter for the NAS state of the rocket.
bool init() override
Check that both the antenna and rocket coordinates have been set.
void setLastAntennaAttitude(const VN300Data &attitudeData)
Setter for the attitude of the antenna.
void setRocketNASOrigin(const GPSData &gpsData)
Setter for the GPS coordinates of the rocket's NAS origin reference.
void setAntennaCoordinates(const GPSData &gpsData)
Setter for the GPS coordinates of the antenna.
LoggerResult log(const T &t)
Call this function to log a class.
static Logger & getInstance()
float verticalSpeed(float p, float dpDt, float pRef, float tRef)
Vector2f geodetic2NED(const Vector2f &target, const Vector2f &origin)
uint64_t getTimestamp()
Returns the current timer value in microseconds.
This file includes all the types the logdecoder script will decode.
float minimizeRotation(float angle)
Minimize rotation angle.
A structure for storing angles relative to the NED frame.
float pitch
position, positive UP [deg]
State of the Follower algorithm, with the angles and speeds.
Structure to handle GPS data.
A structure for logging the ARP system coordinates set in the Follower.
A structure for logging the Rocket coordinates set in the Follower.