OP-1900 added deceleration check to autotakeoff failsafe
[librepilot.git] / flight / modules / ManualControl / pathfollowerhandler.c
blob0d5c8078d9ccf9e5744e097737c723b4c6b421d9
1 /**
2 ******************************************************************************
3 * @addtogroup OpenPilotModules OpenPilot Modules
4 * @{
5 * @addtogroup ManualControl
6 * @brief Interpretes the control input in ManualControlCommand
7 * @{
9 * @file pathfollowerhandler.c
10 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2014.
12 * @see The GNU Public License (GPL) Version 3
14 ******************************************************************************/
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 3 of the License, or
19 * (at your option) any later version.
21 * This program is distributed in the hope that it will be useful, but
22 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
23 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24 * for more details.
26 * You should have received a copy of the GNU General Public License along
27 * with this program; if not, write to the Free Software Foundation, Inc.,
28 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 #include "inc/manualcontrol.h"
32 #include <pathdesired.h>
33 #include <manualcontrolcommand.h>
34 #include <flightstatus.h>
35 #include <positionstate.h>
36 #include <flightmodesettings.h>
38 #if defined(REVOLUTION)
39 #include <plans.h>
41 // Private constants
43 // Private types
45 // Private functions
47 /**
48 * @brief Handler to control Guided flightmodes. FlightControl is governed by PathFollower, control via PathDesired
49 * @input: NONE: fully automated mode -- TODO recursively call handler for advanced stick commands
50 * @output: PathDesired
52 void pathFollowerHandler(bool newinit)
54 if (newinit) {
55 plan_initialize();
58 FlightStatusFlightModeOptions flightMode;
59 FlightStatusAssistedControlStateOptions assistedControlFlightMode;
60 FlightStatusFlightModeAssistOptions flightModeAssist;
61 FlightStatusFlightModeGet(&flightMode);
62 FlightStatusFlightModeAssistGet(&flightModeAssist);
63 FlightStatusAssistedControlStateGet(&assistedControlFlightMode);
65 if (newinit) {
66 // After not being in this mode for a while init at current height
67 switch (flightMode) {
68 case FLIGHTSTATUS_FLIGHTMODE_RETURNTOBASE:
69 plan_setup_returnToBase();
70 break;
71 case FLIGHTSTATUS_FLIGHTMODE_POSITIONHOLD:
72 if ((flightModeAssist != FLIGHTSTATUS_FLIGHTMODEASSIST_NONE) &&
73 (assistedControlFlightMode == FLIGHTSTATUS_ASSISTEDCONTROLSTATE_PRIMARY)) {
74 // Switch from primary (just entered this PH flight mode) into brake
75 plan_setup_assistedcontrol();
76 } else {
77 plan_setup_positionHold();
79 break;
80 case FLIGHTSTATUS_FLIGHTMODE_COURSELOCK:
81 plan_setup_CourseLock();
82 break;
83 case FLIGHTSTATUS_FLIGHTMODE_VELOCITYROAM:
84 plan_setup_VelocityRoam();
85 break;
86 case FLIGHTSTATUS_FLIGHTMODE_HOMELEASH:
87 plan_setup_HomeLeash();
88 break;
89 case FLIGHTSTATUS_FLIGHTMODE_ABSOLUTEPOSITION:
90 plan_setup_AbsolutePosition();
91 break;
93 case FLIGHTSTATUS_FLIGHTMODE_LAND:
94 if (flightModeAssist == FLIGHTSTATUS_FLIGHTMODEASSIST_NONE) {
95 plan_setup_land();
96 } else {
97 plan_setup_VelocityRoam();
99 break;
100 case FLIGHTSTATUS_FLIGHTMODE_AUTOTAKEOFF:
101 plan_setup_AutoTakeoff();
102 break;
103 case FLIGHTSTATUS_FLIGHTMODE_AUTOCRUISE:
104 plan_setup_AutoCruise();
105 break;
107 case FLIGHTSTATUS_FLIGHTMODE_STABILIZED1:
108 case FLIGHTSTATUS_FLIGHTMODE_STABILIZED2:
109 case FLIGHTSTATUS_FLIGHTMODE_STABILIZED3:
110 case FLIGHTSTATUS_FLIGHTMODE_STABILIZED4:
111 case FLIGHTSTATUS_FLIGHTMODE_STABILIZED5:
112 case FLIGHTSTATUS_FLIGHTMODE_STABILIZED6:
113 if (assistedControlFlightMode == FLIGHTSTATUS_ASSISTEDCONTROLSTATE_BRAKE) {
114 // Just initiated braking after returning from stabi control
115 plan_setup_assistedcontrol();
117 break;
119 default:
120 plan_setup_positionHold();
121 break;
125 switch (flightMode) {
126 case FLIGHTSTATUS_FLIGHTMODE_COURSELOCK:
127 plan_run_CourseLock();
128 break;
129 case FLIGHTSTATUS_FLIGHTMODE_VELOCITYROAM:
130 plan_run_VelocityRoam();
131 break;
132 case FLIGHTSTATUS_FLIGHTMODE_HOMELEASH:
133 plan_run_HomeLeash();
134 break;
135 case FLIGHTSTATUS_FLIGHTMODE_ABSOLUTEPOSITION:
136 plan_run_AbsolutePosition();
137 break;
138 case FLIGHTSTATUS_FLIGHTMODE_LAND:
139 if (flightModeAssist != FLIGHTSTATUS_FLIGHTMODEASSIST_NONE) {
140 plan_run_VelocityRoam();
142 break;
143 case FLIGHTSTATUS_FLIGHTMODE_AUTOCRUISE:
144 plan_run_AutoCruise();
145 break;
146 default:
147 break;
151 #else /* if defined(REVOLUTION) */
152 void pathFollowerHandler(__attribute__((unused)) bool newinit)
154 AlarmsSet(SYSTEMALARMS_ALARM_MANUALCONTROL, SYSTEMALARMS_ALARM_CRITICAL); // should not be called
156 #endif // REVOLUTION
160 * @}
161 * @}