2 ******************************************************************************
3 * @addtogroup OpenPilotModules OpenPilot Modules
5 * @addtogroup PathFollower FSM
6 * @brief Executes landing sequence via an FSM
10 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2015.
11 * @brief Executes FSM for landing sequence
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
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
35 #include "statusvtolland.h"
37 #include "pathfollowerfsm.h"
39 // Landing state machine
41 LAND_STATE_INACTIVE
= 0, // Inactive state is the initialised state on startup
42 LAND_STATE_INIT_ALTHOLD
, // Initiate altitude hold before starting descent
43 LAND_STATE_WTG_FOR_DESCENTRATE
, // Waiting for attainment of landing descent rate
44 LAND_STATE_AT_DESCENTRATE
, // Landing descent rate achieved
45 LAND_STATE_WTG_FOR_GROUNDEFFECT
, // Waiting for group effect to be detected
46 LAND_STATE_GROUNDEFFECT
, // Ground effect detected
47 LAND_STATE_THRUSTDOWN
, // Thrust down sequence
48 LAND_STATE_THRUSTOFF
, // Thrust is now off
49 LAND_STATE_DISARMED
, // Disarmed
51 } PathFollowerFSM_LandState_T
;
53 class VtolLandFSM
: public PathFollowerFSM
{
55 static VtolLandFSM
*p_inst
;
59 static VtolLandFSM
*instance()
62 p_inst
= new VtolLandFSM();
66 int32_t Initialize(VtolPathFollowerSettingsData
*vtolPathFollowerSettings
,
67 PathDesiredData
*pathDesired
,
68 FlightStatusData
*flightStatus
);
72 void BoundThrust(float &ulow
, float &uhigh
);
73 PathFollowerFSMState_T
GetCurrentState(void);
74 void ConstrainStabiDesired(StabilizationDesiredData
*stabDesired
);
75 float BoundVelocityDown(float);
76 void CheckPidScaler(pid_scaler
*scaler
);
80 // FSM instance data type
82 StatusVtolLandData fsmLandStatus
;
83 StatusVtolLandStateOptions currentState
;
84 TakeOffLocationData takeOffLocation
;
85 uint32_t stateRunCount
;
86 uint32_t stateTimeoutCount
;
89 float expectedLandPositionNorth
;
90 float expectedLandPositionEast
;
94 uint8_t observationCount
;
95 uint8_t observation2Count
;
96 uint8_t flZeroStabiHorizontal
;
97 uint8_t flConstrainThrust
;
98 uint8_t flLowAltitude
;
99 uint8_t flAltitudeHold
;
102 // FSM state structure
104 void(VtolLandFSM::*setup
) (void); // Called to initialise the state
105 void(VtolLandFSM::*run
) (uint8_t); // Run the event detection code for a state
106 } PathFollowerFSM_LandStateHandler_T
;
109 VtolLandFSMData_T
*mLandData
;
110 VtolPathFollowerSettingsData
*vtolPathFollowerSettings
;
111 PathDesiredData
*pathDesired
;
112 FlightStatusData
*flightStatus
;
114 void setup_inactive(void);
115 void setup_init_althold(void);
116 void setup_wtg_for_descentrate(void);
117 void setup_at_descentrate(void);
118 void setup_wtg_for_groundeffect(void);
119 void run_init_althold(uint8_t);
120 void run_wtg_for_descentrate(uint8_t);
121 void run_at_descentrate(uint8_t);
122 void run_wtg_for_groundeffect(uint8_t);
123 void setup_groundeffect(void);
124 void run_groundeffect(uint8_t);
125 void setup_thrustdown(void);
126 void run_thrustdown(uint8_t);
127 void setup_thrustoff(void);
128 void run_thrustoff(uint8_t);
129 void setup_disarmed(void);
130 void run_disarmed(uint8_t);
132 void setState(StatusVtolLandStateOptions newState
, StatusVtolLandStateExitReasonOptions reason
);
135 void updateVtolLandFSMStatus();
136 void assessAltitude(void);
138 void setStateTimeout(int32_t count
);
140 static PathFollowerFSM_LandStateHandler_T sLandStateTable
[LAND_STATE_SIZE
];
143 #endif // VTOLLANDFSM_H