41 std::function<
void(
float)> setActuator)
42 : getCurrentPosition(
std::move(getCurrentPosition)),
43 setActuator(
std::move(setActuator)), trajectoryOpenSet(trajectoryOpenSet),
44 trajectoryCloseSet(trajectoryCloseSet), configInterp(configInterp)
56 if (configInterp.
DM == 0)
59 choosenOpenTrajectory = &trajectoryOpenSet.
trajectories[0];
60 choosenCloseTrajectory = &trajectoryCloseSet.
trajectories[0];
65 round((currentMass - configInterp.
INITIAL_MASS) / configInterp.
DM);
68 index = std::max(index, 0);
69 uint32_t boundedIndex = std::min(
static_cast<uint32_t
>(index),
70 trajectoryOpenSet.
length() - 1);
72 choosenOpenTrajectory = &trajectoryOpenSet.
trajectories[boundedIndex];
73 choosenCloseTrajectory = &trajectoryCloseSet.
trajectories[boundedIndex];
79void AirBrakesInterpPID::step()
81 auto currentPosition = getCurrentPosition();
84 if (lastPosition.
timestamp >= currentPosition.timestamp)
87 lastPosition = currentPosition;
90 float percentage = controlInterp(currentPosition);
97 lastPercentage + (percentage - lastPercentage) * filterCoeff;
122 lastPercentage = percentage;
123 setActuator(percentage);
126float AirBrakesInterpPID::controlInterp(TrajectoryPoint currentPosition)
131 floor((currentPosition.z / configInterp.
DZ)) + configInterp.
N_FORWARD;
133 index_z = std::max(index_z, 0);
137 index_z = std::min(index_z, std::min(choosenCloseTrajectory->
trjSize - 1,
138 choosenOpenTrajectory->
trjSize - 1));
141 choosenCloseTrajectory->
points[index_z];
143 choosenOpenTrajectory->
points[index_z];
149 if (currentPosition.vz <= trjPointClosed.
vz)
153 else if (currentPosition.vz >= trjPointOpen.
vz)
159 float detectedPosition = (currentPosition.vz - trjPointClosed.
vz) /
160 (trjPointOpen.
vz - trjPointClosed.
vz);
162 float dt = 1 / configInterp.
ARB_FREQ;
164 float ref = configInterp.
PID_REF;
165 float error = detectedPosition - ref;
166 float prevError = lastPercentage - ref;
168 if (saturation ==
false)
169 integralError += error * dt;
171 float kp = configInterp.
KP;
172 float ki = configInterp.
KI;
173 float kd = configInterp.
KD;
176 kp * error + kd * prevError / dt + ki * integralError + ref;
183 else if (percentage > 1)
AirBrakesInterpPID(std::function< TimedTrajectoryPoint()> getCurrentPosition, const TrajectorySet &trajectoryOpenSet, const TrajectorySet &trajectoryCloseSet, const AirBrakesInterpPIDConfig &configInterp, std::function< void(float)> setActuator)
bool init() override
Initializes the Algorithm object, must be called as soon as the object is created.
void begin()
Starts the execution of the algorithm and set the running flag to true.
std::atomic< bool > running
Trajectory point with timestamp and velocity module.
float vz
Vertical velocity [m/s].
Trajectory * trajectories
Driver for the VN100S IMU.
float FILTER_MINIMUM_ALTITUDE
float ABK_CRITICAL_ALTITUDE
float FILTER_MAXIMUM_ALTITUDE
float STARTING_FILTER_VALUE