2 ******************************************************************************
3 * @addtogroup OpenPilotModules OpenPilot Modules
5 * @addtogroup ManualControl
6 * @brief Interpretes the control input in ManualControlCommand
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
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)
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
)
58 FlightStatusFlightModeOptions flightMode
;
59 FlightStatusAssistedControlStateOptions assistedControlFlightMode
;
60 FlightStatusFlightModeAssistOptions flightModeAssist
;
61 FlightStatusFlightModeGet(&flightMode
);
62 FlightStatusFlightModeAssistGet(&flightModeAssist
);
63 FlightStatusAssistedControlStateGet(&assistedControlFlightMode
);
66 // After not being in this mode for a while init at current height
68 case FLIGHTSTATUS_FLIGHTMODE_RETURNTOBASE
:
69 plan_setup_returnToBase();
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();
77 plan_setup_positionHold();
80 case FLIGHTSTATUS_FLIGHTMODE_COURSELOCK
:
81 plan_setup_CourseLock();
83 case FLIGHTSTATUS_FLIGHTMODE_VELOCITYROAM
:
84 plan_setup_VelocityRoam();
86 case FLIGHTSTATUS_FLIGHTMODE_HOMELEASH
:
87 plan_setup_HomeLeash();
89 case FLIGHTSTATUS_FLIGHTMODE_ABSOLUTEPOSITION
:
90 plan_setup_AbsolutePosition();
93 case FLIGHTSTATUS_FLIGHTMODE_LAND
:
94 if (flightModeAssist
== FLIGHTSTATUS_FLIGHTMODEASSIST_NONE
) {
97 plan_setup_VelocityRoam();
100 case FLIGHTSTATUS_FLIGHTMODE_AUTOTAKEOFF
:
101 plan_setup_AutoTakeoff();
103 case FLIGHTSTATUS_FLIGHTMODE_AUTOCRUISE
:
104 plan_setup_AutoCruise();
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();
120 plan_setup_positionHold();
125 switch (flightMode
) {
126 case FLIGHTSTATUS_FLIGHTMODE_COURSELOCK
:
127 plan_run_CourseLock();
129 case FLIGHTSTATUS_FLIGHTMODE_VELOCITYROAM
:
130 plan_run_VelocityRoam();
132 case FLIGHTSTATUS_FLIGHTMODE_HOMELEASH
:
133 plan_run_HomeLeash();
135 case FLIGHTSTATUS_FLIGHTMODE_ABSOLUTEPOSITION
:
136 plan_run_AbsolutePosition();
138 case FLIGHTSTATUS_FLIGHTMODE_LAND
:
139 if (flightModeAssist
!= FLIGHTSTATUS_FLIGHTMODEASSIST_NONE
) {
140 plan_run_VelocityRoam();
143 case FLIGHTSTATUS_FLIGHTMODE_AUTOCRUISE
:
144 plan_run_AutoCruise();
151 #else /* if defined(REVOLUTION) */
152 void pathFollowerHandler(__attribute__((unused
)) bool newinit
)
154 AlarmsSet(SYSTEMALARMS_ALARM_MANUALCONTROL
, SYSTEMALARMS_ALARM_CRITICAL
); // should not be called