Skyward boardcore
Loading...
Searching...
No Matches
Follower.h
Go to the documentation of this file.
1/* Copyright (c) 2024 Skyward Experimental Rocketry
2 * Authors: Emilio Corigliano, Niccolò Betto, Federico Lolli
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 * THE SOFTWARE.
21 */
22
23#pragma once
24
28#include <logger/Logger.h>
29#include <sensors/SensorData.h>
31
32#include <atomic>
33#include <chrono>
35
36#include "FollowerData.h"
37
38namespace Boardcore
39{
40
41static constexpr float YAW_GAIN_LIMIT =
42 1.0;
43static constexpr float PITCH_GAIN_LIMIT =
44 1.0;
45
52class Follower : public Algorithm
53{
54public:
60 explicit Follower(std::chrono::milliseconds updatePeriod);
61
67 bool init() override;
68
73 void setAntennaCoordinates(const GPSData& gpsData);
74
80 void setRocketNASOrigin(const GPSData& gpsData);
81
85 void setLastRocketNasState(const NASState& nasState);
86
92 void setLastAntennaAttitude(const VN300Data& attitudeData);
93
102 bool setMaxGain(float yawGainNew, float pitchGainNew);
103
109
115
116private:
121 void step() override;
122
127 VN300Data getLastAntennaAttitude();
128
133 NASState getLastRocketNasState();
134
141 AntennaAngles rocketPositionToAntennaAngles(const NEDCoords& ned);
142
147 void setState(const FollowerState& newState);
148
152 Eigen::Vector2f getAntennaCoordinates();
153
157 Eigen::Vector3f getRocketNASOrigin();
158
159 // actuation update period [ms]
160 std::chrono::milliseconds updatePeriod;
161
162 // max number of retries for GPS data acquisition
163 const uint8_t maxInitRetries = 120;
164
165 bool antennaCoordinatesSet = false;
166 bool rocketCoordinatesSet = false;
167 bool lastRocketNasStateSet = false;
168 std::atomic<bool> firstAntennaAttitudeSet{false};
169
170 VN300Data lastAntennaAttitude;
171
172 NASState lastRocketNasState;
173
174 // TODO: See if assumption has sense...
175 /* GPS coordinates of the antenna [lat, lon] [deg, deg],
176 altitude is considered same as NAS Origin */
177 Eigen::Vector2f antennaCoordinates;
178 /* GPS coordinates of the NAS origin taken from reference origin [lat, lon,
179 alt] [deg, deg, m] */
180 Eigen::Vector3f rocketNASOrigin;
181 /* Distance between the antenna and the rocket [lat,
182 lon, alt] [deg, deg, m] */
183 Eigen::Vector2f antennaRocketDistance;
184
185 // Target yaw and pitch of the system [deg, deg]
186 AntennaAngles targetAngles;
187
188 FollowerState state;
189
190 PrintLogger logger = Logging::getLogger("Follower");
191
192 // General mutex for the follower
193 miosix::FastMutex followerMutex;
194
195 float yawGain = YAW_GAIN_LIMIT;
196 float pitchGain = PITCH_GAIN_LIMIT;
197};
198
199} // namespace Boardcore
Follower class to output the yaw ad pitch necessary to track from the GPS origin the rocket....
Definition Follower.h:53
FollowerState getState()
Synchronized getter for the State of the follower algorithm.
Definition Follower.cpp:100
AntennaAngles getTargetAngles()
Getter for the target antenna position computed by the algorithm.
Definition Follower.cpp:112
bool setMaxGain(float yawGainNew, float pitchGainNew)
Set the maximum gain for the yaw and pitch.
Definition Follower.cpp:118
void setLastRocketNasState(const NASState &nasState)
Setter for the NAS state of the rocket.
Definition Follower.cpp:87
bool init() override
Check that both the antenna and rocket coordinates have been set.
Definition Follower.cpp:132
void setLastAntennaAttitude(const VN300Data &attitudeData)
Setter for the attitude of the antenna.
Definition Follower.cpp:74
void setRocketNASOrigin(const GPSData &gpsData)
Setter for the GPS coordinates of the rocket's NAS origin reference.
Definition Follower.cpp:66
void setAntennaCoordinates(const GPSData &gpsData)
Setter for the GPS coordinates of the antenna.
Definition Follower.cpp:58
static PrintLogger getLogger(const string &name)
Driver for the VN100S IMU.
A structure for storing angles relative to the NED frame.
State of the Follower algorithm, with the angles and speeds.
Structure to handle GPS data.
Definition SensorData.h:277
Data class for VN300.
Definition VN300Data.h:51