2014-03-02 14:45:17 +01:00
|
|
|
/**
|
|
|
|
******************************************************************************
|
|
|
|
* @addtogroup OpenPilotModules OpenPilot Modules
|
|
|
|
* @{
|
|
|
|
* @addtogroup ManualControl
|
|
|
|
* @brief Interpretes the control input in ManualControlCommand
|
|
|
|
* @{
|
|
|
|
*
|
|
|
|
* @file pathfollowerhandler.c
|
|
|
|
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2014.
|
|
|
|
*
|
|
|
|
* @see The GNU Public License (GPL) Version 3
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
/*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "inc/manualcontrol.h"
|
|
|
|
#include <pathdesired.h>
|
|
|
|
#include <manualcontrolcommand.h>
|
|
|
|
#include <flightstatus.h>
|
|
|
|
#include <positionstate.h>
|
|
|
|
#include <flightmodesettings.h>
|
|
|
|
|
|
|
|
#if defined(REVOLUTION)
|
2014-05-19 18:35:18 +02:00
|
|
|
#include <plans.h>
|
|
|
|
|
2014-03-02 14:45:17 +01:00
|
|
|
// Private constants
|
|
|
|
|
|
|
|
// Private types
|
|
|
|
|
|
|
|
// Private functions
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Handler to control Guided flightmodes. FlightControl is governed by PathFollower, control via PathDesired
|
|
|
|
* @input: NONE: fully automated mode -- TODO recursively call handler for advanced stick commands
|
|
|
|
* @output: PathDesired
|
|
|
|
*/
|
|
|
|
void pathFollowerHandler(bool newinit)
|
|
|
|
{
|
|
|
|
if (newinit) {
|
2014-05-19 18:35:18 +02:00
|
|
|
plan_initialize();
|
2014-03-02 14:45:17 +01:00
|
|
|
}
|
|
|
|
|
2014-05-19 18:35:18 +02:00
|
|
|
uint8_t flightMode;
|
2015-01-08 03:20:47 +01:00
|
|
|
uint8_t assistedControlFlightMode;
|
2014-05-19 18:35:18 +02:00
|
|
|
FlightStatusFlightModeGet(&flightMode);
|
2015-01-08 03:20:47 +01:00
|
|
|
FlightStatusAssistedControlStateGet(&assistedControlFlightMode);
|
2014-03-02 14:45:17 +01:00
|
|
|
|
|
|
|
if (newinit) {
|
|
|
|
// After not being in this mode for a while init at current height
|
2014-05-19 18:35:18 +02:00
|
|
|
switch (flightMode) {
|
2014-03-02 14:45:17 +01:00
|
|
|
case FLIGHTSTATUS_FLIGHTMODE_RETURNTOBASE:
|
2014-05-19 18:35:18 +02:00
|
|
|
plan_setup_returnToBase();
|
|
|
|
break;
|
|
|
|
case FLIGHTSTATUS_FLIGHTMODE_POSITIONHOLD:
|
2015-01-08 03:20:47 +01:00
|
|
|
if (assistedControlFlightMode == FLIGHTSTATUS_ASSISTEDCONTROLSTATE_BRAKE) {
|
|
|
|
// Just initiated braking after returning from stabi control
|
|
|
|
plan_setup_assistedcontrol(false);
|
|
|
|
} else {
|
|
|
|
plan_setup_positionHold();
|
|
|
|
}
|
2014-05-19 18:35:18 +02:00
|
|
|
break;
|
2014-11-08 14:04:00 +01:00
|
|
|
case FLIGHTSTATUS_FLIGHTMODE_COURSELOCK:
|
|
|
|
plan_setup_CourseLock();
|
|
|
|
break;
|
2014-11-08 16:01:59 +01:00
|
|
|
case FLIGHTSTATUS_FLIGHTMODE_POSITIONROAM:
|
|
|
|
plan_setup_PositionRoam();
|
2014-06-04 10:29:45 +02:00
|
|
|
break;
|
2014-11-08 16:01:59 +01:00
|
|
|
case FLIGHTSTATUS_FLIGHTMODE_HOMELEASH:
|
|
|
|
plan_setup_HomeLeash();
|
2014-06-04 10:29:45 +02:00
|
|
|
break;
|
2014-11-08 12:56:17 +01:00
|
|
|
case FLIGHTSTATUS_FLIGHTMODE_ABSOLUTEPOSITION:
|
|
|
|
plan_setup_AbsolutePosition();
|
2014-06-04 10:29:45 +02:00
|
|
|
break;
|
2014-05-16 21:56:44 +02:00
|
|
|
|
2014-05-19 18:35:18 +02:00
|
|
|
case FLIGHTSTATUS_FLIGHTMODE_LAND:
|
|
|
|
plan_setup_land();
|
|
|
|
break;
|
2014-06-04 10:29:45 +02:00
|
|
|
case FLIGHTSTATUS_FLIGHTMODE_AUTOCRUISE:
|
|
|
|
plan_setup_AutoCruise();
|
|
|
|
break;
|
2014-05-16 21:56:44 +02:00
|
|
|
|
2015-01-08 03:20:47 +01:00
|
|
|
case FLIGHTSTATUS_FLIGHTMODE_STABILIZED1:
|
|
|
|
case FLIGHTSTATUS_FLIGHTMODE_STABILIZED2:
|
|
|
|
case FLIGHTSTATUS_FLIGHTMODE_STABILIZED3:
|
|
|
|
case FLIGHTSTATUS_FLIGHTMODE_STABILIZED4:
|
|
|
|
case FLIGHTSTATUS_FLIGHTMODE_STABILIZED5:
|
|
|
|
case FLIGHTSTATUS_FLIGHTMODE_STABILIZED6:
|
|
|
|
if (assistedControlFlightMode == FLIGHTSTATUS_ASSISTEDCONTROLSTATE_BRAKE) {
|
|
|
|
// Just initiated braking after returning from stabi control
|
|
|
|
plan_setup_assistedcontrol(false);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2014-03-02 14:45:17 +01:00
|
|
|
default:
|
2014-05-19 18:35:18 +02:00
|
|
|
plan_setup_positionHold();
|
2014-03-02 14:45:17 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-19 18:35:18 +02:00
|
|
|
switch (flightMode) {
|
2014-11-08 14:04:00 +01:00
|
|
|
case FLIGHTSTATUS_FLIGHTMODE_COURSELOCK:
|
|
|
|
plan_run_CourseLock();
|
|
|
|
break;
|
2014-11-08 16:01:59 +01:00
|
|
|
case FLIGHTSTATUS_FLIGHTMODE_POSITIONROAM:
|
|
|
|
plan_run_PositionRoam();
|
2014-06-04 10:29:45 +02:00
|
|
|
break;
|
2014-11-08 16:01:59 +01:00
|
|
|
case FLIGHTSTATUS_FLIGHTMODE_HOMELEASH:
|
|
|
|
plan_run_HomeLeash();
|
2014-06-04 10:29:45 +02:00
|
|
|
break;
|
2014-11-08 12:56:17 +01:00
|
|
|
case FLIGHTSTATUS_FLIGHTMODE_ABSOLUTEPOSITION:
|
|
|
|
plan_run_AbsolutePosition();
|
2014-06-04 10:29:45 +02:00
|
|
|
break;
|
2014-05-19 18:35:18 +02:00
|
|
|
case FLIGHTSTATUS_FLIGHTMODE_LAND:
|
|
|
|
plan_run_land();
|
|
|
|
break;
|
2014-06-04 10:29:45 +02:00
|
|
|
case FLIGHTSTATUS_FLIGHTMODE_AUTOCRUISE:
|
|
|
|
plan_run_AutoCruise();
|
|
|
|
break;
|
2014-05-19 18:35:18 +02:00
|
|
|
default:
|
|
|
|
break;
|
2014-03-02 14:45:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#else /* if defined(REVOLUTION) */
|
|
|
|
void pathFollowerHandler(__attribute__((unused)) bool newinit)
|
|
|
|
{
|
2014-03-02 20:06:05 +01:00
|
|
|
AlarmsSet(SYSTEMALARMS_ALARM_MANUALCONTROL, SYSTEMALARMS_ALARM_CRITICAL); // should not be called
|
2014-03-02 14:45:17 +01:00
|
|
|
}
|
|
|
|
#endif // REVOLUTION
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
* @}
|
|
|
|
*/
|