Merged in f5soh/librepilot/update_credits (pull request #529)
[librepilot.git] / flight / modules / PathFollower / inc / vtolbrakefsm.h
blobac10faa0d3cbece27024e1566e2f6552342e03c4
1 /**
2 ******************************************************************************
3 * @addtogroup OpenPilotModules OpenPilot Modules
4 * @{
5 * @addtogroup PathFollower FSM Brake
6 * @brief Executes brake seqeuence
7 * @{
9 * @file vtolbrakfsm.h
10 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2015.
11 * @brief Executes brake sequence fsm
13 * @see The GNU Public License (GPL) Version 3
15 *****************************************************************************/
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 3 of the License, or
20 * (at your option) any later version.
22 * This program is distributed in the hope that it will be useful, but
23 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
24 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
25 * for more details.
27 * You should have received a copy of the GNU General Public License along
28 * with this program; if not, write to the Free Software Foundation, Inc.,
29 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 #ifndef VTOLBRAKEFSM_H
32 #define VTOLBRAKEFSM_H
34 #include "pathfollowerfsm.h"
36 // Brakeing state machine
37 typedef enum {
38 BRAKE_STATE_INACTIVE = 0, // Inactive state is the initialised state on startup
39 BRAKE_STATE_BRAKE, // Initiate altitude hold before starting descent
40 BRAKE_STATE_HOLD, // Waiting for attainment of landing descent rate
41 BRAKE_STATE_SIZE
42 } PathFollowerFSM_BrakeState_T;
44 typedef enum {
45 FSMBRAKESTATUS_STATEEXITREASON_NONE = 0
46 } VtolBrakeFSMStatusStateExitReasonOptions;
48 class VtolBrakeFSM : public PathFollowerFSM {
49 private:
50 static VtolBrakeFSM *p_inst;
51 VtolBrakeFSM();
53 public:
54 static VtolBrakeFSM *instance()
56 if (!p_inst) {
57 p_inst = new VtolBrakeFSM();
59 return p_inst;
61 int32_t Initialize(VtolPathFollowerSettingsData *vtolPathFollowerSettings,
62 PathDesiredData *pathDesired,
63 FlightStatusData *flightStatus,
64 PathStatusData *ptr_pathStatus);
65 void Inactive(void);
66 void Activate(void);
67 void Update(void);
68 PathFollowerFSMState_T GetCurrentState(void);
69 uint8_t PositionHoldState(void);
71 protected:
73 // FSM instance data type
74 typedef struct {
75 PathFollowerFSM_BrakeState_T currentState;
76 uint32_t stateRunCount;
77 uint32_t stateTimeoutCount;
78 float sum1;
79 float sum2;
80 uint8_t observationCount;
81 uint8_t observation2Count;
82 } VtolBrakeFSMData_T;
84 // FSM state structure
85 typedef struct {
86 void(VtolBrakeFSM::*setup) (void); // Called to initialise the state
87 void(VtolBrakeFSM::*run) (uint8_t); // Run the event detection code for a state
88 } PathFollowerFSM_BrakeStateHandler_T;
90 // Private variables
91 VtolBrakeFSMData_T *mBrakeData;
92 VtolPathFollowerSettingsData *vtolPathFollowerSettings;
93 PathDesiredData *pathDesired;
94 PathStatusData *pathStatus;
95 FlightStatusData *flightStatus;
97 void setup_brake(void);
98 void run_brake(uint8_t);
99 void initFSM(void);
100 void setState(PathFollowerFSM_BrakeState_T newState, VtolBrakeFSMStatusStateExitReasonOptions reason);
101 int32_t runState();
102 // void updateVtolBrakeFSMStatus();
104 void setStateTimeout(int32_t count);
106 static PathFollowerFSM_BrakeStateHandler_T sBrakeStateTable[BRAKE_STATE_SIZE];
109 #endif // VTOLBRAKEFSM_H