Skyward boardcore
Loading...
Searching...
No Matches
AirBrakesPI.h
Go to the documentation of this file.
1/* Copyright (c) 2021-2022 Skyward Experimental Rocketry
2 * Authors: Vincenzo Santomarco, Alberto Nidasio, Emilio Corigliano
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
29#include <functional>
30#include <vector>
31
32#include "AirBrakesPIConfig.h"
33#include "TrajectorySet.h"
34
35namespace Boardcore
36{
37
38class AirBrakesPI : public Algorithm
39{
40public:
41 AirBrakesPI(std::function<TimedTrajectoryPoint()> getCurrentPosition,
42 const TrajectorySet& trajectorySet,
43 const AirBrakesPIConfig& config,
44 std::function<void(float)> setActuator);
45
46 bool init() override;
47
52 void begin();
53
58 void step() override;
59
60private:
68 float getRho(float z);
69
79 float getSurface(const TimedTrajectoryPoint& currentPosition, float rho,
80 float drag);
81
88 float getExtension(float surface);
89
98 float getCD(TimedTrajectoryPoint currentPosition, float extension);
99
109 float getDrag(TimedTrajectoryPoint currentPosition, float cd, float rho);
110
115 void chooseTrajectory(TrajectoryPoint currentPosition);
116
122 TrajectoryPoint getSetpoint(TrajectoryPoint currentPosition);
123
129 float piStep(TimedTrajectoryPoint currentPosition,
130 TrajectoryPoint reference, float rho);
131
132private:
133 std::function<TimedTrajectoryPoint()> getCurrentPosition;
134 const AirBrakesPIConfig& config;
135 std::function<void(float)> setActuator;
136
137 TimedTrajectoryPoint lastPosition;
138 uint32_t lastSelectedPointIndex = 0;
139
140 PIController pi;
141
142 // Trajectory set from which the used trajectory can be choosen
143 const TrajectorySet& trajectorySet;
144
145 Trajectory* chosenTrajectory = nullptr;
146};
147
148} // namespace Boardcore
void begin()
This method chooses the trajectory the rocket will follow and starts the algorithm.
bool init() override
Initializes the Algorithm object, must be called as soon as the object is created.
void step() override
Looks for nearest point in the current chosen trajectory and moves the airbraks according to the curr...
AirBrakesPI(std::function< TimedTrajectoryPoint()> getCurrentPosition, const TrajectorySet &trajectorySet, const AirBrakesPIConfig &config, std::function< void(float)> setActuator)
Proportional and integral controller with saturation.
Trajectory point with timestamp and velocity module.
This file includes all the types the logdecoder script will decode.