mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-30 15:52:12 +01:00
LP-598 Followed Laurent's suggestions that makes it possible to remove duplicated code
- Update assessAltitude() to return the altitude in auto takeoff as well as auto land code. Code that duplicated the calculations has been removed. - Make pretty & update headers
This commit is contained in:
parent
ec9b867b44
commit
d53dadaf6b
@ -3,13 +3,13 @@
|
|||||||
* @addtogroup LibrePilotModules LibrePilot Modules
|
* @addtogroup LibrePilotModules LibrePilot Modules
|
||||||
* @{
|
* @{
|
||||||
* @addtogroup PathFollower FSM
|
* @addtogroup PathFollower FSM
|
||||||
* @brief Executes landing sequence via an FSM
|
* @brief Executes auto takeoff sequence via an FSM
|
||||||
* @{
|
* @{
|
||||||
*
|
*
|
||||||
* @file vtollandfsm.h
|
* @file vtolautotakeofffsm.h
|
||||||
* @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2016.
|
* @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2016-2018
|
||||||
* The OpenPilot Team, http://www.openpilot.org Copyright (C) 2015.
|
* The OpenPilot Team, http://www.openpilot.org Copyright (C) 2015.
|
||||||
* @brief Executes FSM for landing sequence
|
* @brief Executes FSM for auto takeoff sequence
|
||||||
*
|
*
|
||||||
* @see The GNU Public License (GPL) Version 3
|
* @see The GNU Public License (GPL) Version 3
|
||||||
*
|
*
|
||||||
@ -144,7 +144,7 @@ protected:
|
|||||||
int32_t runAlways();
|
int32_t runAlways();
|
||||||
|
|
||||||
void updateVtolAutoTakeoffFSMStatus();
|
void updateVtolAutoTakeoffFSMStatus();
|
||||||
void assessAltitude(void);
|
float assessAltitude(void);
|
||||||
|
|
||||||
void setStateTimeout(int32_t count);
|
void setStateTimeout(int32_t count);
|
||||||
|
|
||||||
|
@ -7,7 +7,8 @@
|
|||||||
* @{
|
* @{
|
||||||
*
|
*
|
||||||
* @file vtollandfsm.h
|
* @file vtollandfsm.h
|
||||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2015.
|
* @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2018
|
||||||
|
* The OpenPilot Team, http://www.openpilot.org Copyright (C) 2015.
|
||||||
* @brief Executes FSM for landing sequence
|
* @brief Executes FSM for landing sequence
|
||||||
*
|
*
|
||||||
* @see The GNU Public License (GPL) Version 3
|
* @see The GNU Public License (GPL) Version 3
|
||||||
@ -133,7 +134,7 @@ protected:
|
|||||||
int32_t runState();
|
int32_t runState();
|
||||||
int32_t runAlways();
|
int32_t runAlways();
|
||||||
void updateVtolLandFSMStatus();
|
void updateVtolLandFSMStatus();
|
||||||
void assessAltitude(void);
|
float assessAltitude(void);
|
||||||
|
|
||||||
void setStateTimeout(int32_t count);
|
void setStateTimeout(int32_t count);
|
||||||
|
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
/*
|
/*
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*
|
*
|
||||||
* @file vtollandcontroller.cpp
|
* @file vtolautotakeoffcontroller.cpp
|
||||||
* @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2016.
|
* @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2016-2018
|
||||||
* The OpenPilot Team, http://www.openpilot.org Copyright (C) 2015.
|
* The OpenPilot Team, http://www.openpilot.org Copyright (C) 2015.
|
||||||
* @brief Vtol landing controller loop
|
* @brief Vtol auto takeoff controller loop
|
||||||
* @see The GNU Public License (GPL) Version 3
|
* @see The GNU Public License (GPL) Version 3
|
||||||
* @addtogroup LibrePilot LibrePilotModules Modules PathFollower Navigation
|
* @addtogroup LibrePilot LibrePilotModules Modules PathFollower Navigation
|
||||||
*
|
*
|
||||||
|
@ -2,7 +2,8 @@
|
|||||||
******************************************************************************
|
******************************************************************************
|
||||||
*
|
*
|
||||||
* @file vtolautotakeofffsm.cpp
|
* @file vtolautotakeofffsm.cpp
|
||||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2015.
|
* @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2018
|
||||||
|
* The OpenPilot Team, http://www.openpilot.org Copyright (C) 2015.
|
||||||
* @brief This autotakeoff state machine is a helper state machine to the
|
* @brief This autotakeoff state machine is a helper state machine to the
|
||||||
* VtolAutoTakeoffController.
|
* VtolAutoTakeoffController.
|
||||||
* @see The GNU Public License (GPL) Version 3
|
* @see The GNU Public License (GPL) Version 3
|
||||||
@ -64,7 +65,7 @@ extern "C" {
|
|||||||
#define TIMEOUT_SLOWSTART (2 * TIMER_COUNT_PER_SECOND)
|
#define TIMEOUT_SLOWSTART (2 * TIMER_COUNT_PER_SECOND)
|
||||||
#define TIMEOUT_THRUSTUP (1 * TIMER_COUNT_PER_SECOND)
|
#define TIMEOUT_THRUSTUP (1 * TIMER_COUNT_PER_SECOND)
|
||||||
#define TIMEOUT_THRUSTDOWN (5 * TIMER_COUNT_PER_SECOND)
|
#define TIMEOUT_THRUSTDOWN (5 * TIMER_COUNT_PER_SECOND)
|
||||||
#define AUTOTAKEOFFING_SLOWDOWN_HEIGHT -5.0f
|
#define AUTOTAKEOFF_SLOWDOWN_HEIGHT -5.0f
|
||||||
|
|
||||||
VtolAutoTakeoffFSM::PathFollowerFSM_AutoTakeoffStateHandler_T VtolAutoTakeoffFSM::sAutoTakeoffStateTable[AUTOTAKEOFF_STATE_SIZE] = {
|
VtolAutoTakeoffFSM::PathFollowerFSM_AutoTakeoffStateHandler_T VtolAutoTakeoffFSM::sAutoTakeoffStateTable[AUTOTAKEOFF_STATE_SIZE] = {
|
||||||
[AUTOTAKEOFF_STATE_INACTIVE] = { .setup = &VtolAutoTakeoffFSM::setup_inactive, .run = 0 },
|
[AUTOTAKEOFF_STATE_INACTIVE] = { .setup = &VtolAutoTakeoffFSM::setup_inactive, .run = 0 },
|
||||||
@ -246,14 +247,8 @@ void VtolAutoTakeoffFSM::setState(StatusVtolAutoTakeoffStateOptions newState, St
|
|||||||
mAutoTakeoffData->currentState = newState;
|
mAutoTakeoffData->currentState = newState;
|
||||||
|
|
||||||
if (newState != STATUSVTOLAUTOTAKEOFF_STATE_INACTIVE) {
|
if (newState != STATUSVTOLAUTOTAKEOFF_STATE_INACTIVE) {
|
||||||
PositionStateData positionState;
|
float altitudeAboveTakeoff = assessAltitude();
|
||||||
PositionStateGet(&positionState);
|
mAutoTakeoffData->fsmAutoTakeoffStatus.AltitudeAtState[newState] = altitudeAboveTakeoff;
|
||||||
float altitudeAboveGround = 0.0f;
|
|
||||||
if (mAutoTakeoffData->takeOffLocation.Status == TAKEOFFLOCATION_STATUS_VALID) {
|
|
||||||
altitudeAboveGround = mAutoTakeoffData->takeOffLocation.Down - positionState.Down;
|
|
||||||
}
|
|
||||||
mAutoTakeoffData->fsmAutoTakeoffStatus.AltitudeAtState[newState] = altitudeAboveGround;
|
|
||||||
assessAltitude();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Restart state timer counter
|
// Restart state timer counter
|
||||||
@ -290,7 +285,7 @@ void VtolAutoTakeoffFSM::updateVtolAutoTakeoffFSMStatus()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void VtolAutoTakeoffFSM::assessAltitude(void)
|
float VtolAutoTakeoffFSM::assessAltitude(void)
|
||||||
{
|
{
|
||||||
float positionDown;
|
float positionDown;
|
||||||
|
|
||||||
@ -300,11 +295,13 @@ void VtolAutoTakeoffFSM::assessAltitude(void)
|
|||||||
takeOffDown = mAutoTakeoffData->takeOffLocation.Down;
|
takeOffDown = mAutoTakeoffData->takeOffLocation.Down;
|
||||||
}
|
}
|
||||||
float positionDownRelativeToTakeoff = positionDown - takeOffDown;
|
float positionDownRelativeToTakeoff = positionDown - takeOffDown;
|
||||||
if (positionDownRelativeToTakeoff < AUTOTAKEOFFING_SLOWDOWN_HEIGHT) {
|
if (positionDownRelativeToTakeoff < AUTOTAKEOFF_SLOWDOWN_HEIGHT) {
|
||||||
mAutoTakeoffData->flLowAltitude = false;
|
mAutoTakeoffData->flLowAltitude = false;
|
||||||
} else {
|
} else {
|
||||||
mAutoTakeoffData->flLowAltitude = true;
|
mAutoTakeoffData->flLowAltitude = true;
|
||||||
}
|
}
|
||||||
|
// Return the altitude above takeoff, which is the negation of positionDownRelativeToTakeoff
|
||||||
|
return -positionDownRelativeToTakeoff;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Action the required state from plans.c
|
// Action the required state from plans.c
|
||||||
|
@ -2,7 +2,8 @@
|
|||||||
******************************************************************************
|
******************************************************************************
|
||||||
*
|
*
|
||||||
* @file vtollandfsm.cpp
|
* @file vtollandfsm.cpp
|
||||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2015.
|
* @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2018
|
||||||
|
* The OpenPilot Team, http://www.openpilot.org Copyright (C) 2015.
|
||||||
* @brief This landing state machine is a helper state machine to the
|
* @brief This landing state machine is a helper state machine to the
|
||||||
* VtolLandController.
|
* VtolLandController.
|
||||||
* @see The GNU Public License (GPL) Version 3
|
* @see The GNU Public License (GPL) Version 3
|
||||||
@ -275,14 +276,8 @@ void VtolLandFSM::setState(StatusVtolLandStateOptions newState, StatusVtolLandSt
|
|||||||
mLandData->currentState = newState;
|
mLandData->currentState = newState;
|
||||||
|
|
||||||
if (newState != STATUSVTOLLAND_STATE_INACTIVE) {
|
if (newState != STATUSVTOLLAND_STATE_INACTIVE) {
|
||||||
PositionStateData positionState;
|
float altitudeAboveTakeoff = assessAltitude();
|
||||||
PositionStateGet(&positionState);
|
mLandData->fsmLandStatus.AltitudeAtState[newState] = altitudeAboveTakeoff;
|
||||||
float takeOffDown = 0.0f;
|
|
||||||
if (mLandData->takeOffLocation.Status == TAKEOFFLOCATION_STATUS_VALID) {
|
|
||||||
takeOffDown = mLandData->takeOffLocation.Down;
|
|
||||||
}
|
|
||||||
mLandData->fsmLandStatus.AltitudeAtState[newState] = positionState.Down - takeOffDown;
|
|
||||||
assessAltitude();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Restart state timer counter
|
// Restart state timer counter
|
||||||
@ -332,7 +327,7 @@ float VtolLandFSM::BoundVelocityDown(float velocity_down)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void VtolLandFSM::assessAltitude(void)
|
float VtolLandFSM::assessAltitude(void)
|
||||||
{
|
{
|
||||||
float positionDown;
|
float positionDown;
|
||||||
|
|
||||||
@ -347,6 +342,8 @@ void VtolLandFSM::assessAltitude(void)
|
|||||||
} else {
|
} else {
|
||||||
mLandData->flLowAltitude = true;
|
mLandData->flLowAltitude = true;
|
||||||
}
|
}
|
||||||
|
// Return the altitude above takeoff, which is the negation of positionDownRelativeToTakeoff
|
||||||
|
return -positionDownRelativeToTakeoff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user