Skip to content

Commit 3bef6b2

Browse files
dr-obliviumf5soh
authored andcommitted
Merged in Oblivium/librepilot/LP-598_Autotakeoff_Corrections (pull request #512)
LP-598 Autotakeoff Corrections Approved-by: Lalanne Laurent <f5soh@free.fr> Approved-by: Jan NIJS <dr.oblivium@gmail.com>
2 parents a4c0bcf + d53dada commit 3bef6b2

5 files changed

Lines changed: 42 additions & 47 deletions

File tree

flight/modules/PathFollower/inc/vtolautotakeofffsm.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
* @addtogroup LibrePilotModules LibrePilot Modules
44
* @{
55
* @addtogroup PathFollower FSM
6-
* @brief Executes landing sequence via an FSM
6+
* @brief Executes auto takeoff sequence via an FSM
77
* @{
88
*
9-
* @file vtollandfsm.h
10-
* @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2016.
9+
* @file vtolautotakeofffsm.h
10+
* @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2016-2018
1111
* The OpenPilot Team, http://www.openpilot.org Copyright (C) 2015.
12-
* @brief Executes FSM for landing sequence
12+
* @brief Executes FSM for auto takeoff sequence
1313
*
1414
* @see The GNU Public License (GPL) Version 3
1515
*
@@ -144,7 +144,7 @@ class VtolAutoTakeoffFSM : public PathFollowerFSM {
144144
int32_t runAlways();
145145

146146
void updateVtolAutoTakeoffFSMStatus();
147-
void assessAltitude(void);
147+
float assessAltitude(void);
148148

149149
void setStateTimeout(int32_t count);
150150

flight/modules/PathFollower/inc/vtollandfsm.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
* @{
88
*
99
* @file vtollandfsm.h
10-
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2015.
10+
* @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2018
11+
* The OpenPilot Team, http://www.openpilot.org Copyright (C) 2015.
1112
* @brief Executes FSM for landing sequence
1213
*
1314
* @see The GNU Public License (GPL) Version 3
@@ -133,7 +134,7 @@ class VtolLandFSM : public PathFollowerFSM {
133134
int32_t runState();
134135
int32_t runAlways();
135136
void updateVtolLandFSMStatus();
136-
void assessAltitude(void);
137+
float assessAltitude(void);
137138

138139
void setStateTimeout(int32_t count);
139140

flight/modules/PathFollower/vtolautotakeoffcontroller.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/*
22
******************************************************************************
33
*
4-
* @file vtollandcontroller.cpp
5-
* @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2016.
4+
* @file vtolautotakeoffcontroller.cpp
5+
* @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2016-2018
66
* The OpenPilot Team, http://www.openpilot.org Copyright (C) 2015.
7-
* @brief Vtol landing controller loop
7+
* @brief Vtol auto takeoff controller loop
88
* @see The GNU Public License (GPL) Version 3
99
* @addtogroup LibrePilot LibrePilotModules Modules PathFollower Navigation
1010
*
@@ -132,19 +132,19 @@ void VtolAutoTakeoffController::ObjectiveUpdated(void)
132132
if (mOverride) {
133133
// override pathDesired from PathPlanner with current position,
134134
// as we deliberately don't care about the location of the waypoints on the map
135-
float velocity_down;
135+
float autotakeoff_velocity;
136136
float autotakeoff_height;
137137
PositionStateData positionState;
138138
PositionStateGet(&positionState);
139-
FlightModeSettingsAutoTakeOffVelocityGet(&velocity_down);
139+
FlightModeSettingsAutoTakeOffVelocityGet(&autotakeoff_velocity);
140140
FlightModeSettingsAutoTakeOffHeightGet(&autotakeoff_height);
141141
autotakeoff_height = fabsf(autotakeoff_height);
142142
if (autotakeoff_height < AUTOTAKEOFF_TO_INCREMENTAL_HEIGHT_MIN) {
143143
autotakeoff_height = AUTOTAKEOFF_TO_INCREMENTAL_HEIGHT_MIN;
144144
} else if (autotakeoff_height > AUTOTAKEOFF_TO_INCREMENTAL_HEIGHT_MAX) {
145145
autotakeoff_height = AUTOTAKEOFF_TO_INCREMENTAL_HEIGHT_MAX;
146146
}
147-
controlDown.UpdateVelocitySetpoint(velocity_down);
147+
controlDown.UpdateVelocitySetpoint(-autotakeoff_velocity);
148148
controlNE.UpdateVelocitySetpoint(0.0f, 0.0f);
149149
controlNE.UpdatePositionSetpoint(positionState.North, positionState.East);
150150

@@ -320,9 +320,9 @@ void VtolAutoTakeoffController::UpdateAutoPilot()
320320
// 1. Arming must be done whilst in the AutoTakeOff flight mode
321321
// 2. If the AutoTakeoff flight mode is selected and already armed, requires disarming first
322322
// 3. Wait for armed state
323-
// 4. Once the user increases the throttle position to above 50%, then and only then initiate auto-takeoff.
324-
// 5. Whilst the throttle is < 50% before takeoff, all stick inputs are being ignored.
325-
// 6. If during the autotakeoff sequence, at any stage, if the throttle stick position reduces to less than 10%, landing is initiated.
323+
// 4. Once the user increases the throttle position to above 30%, then and only then initiate auto-takeoff.
324+
// 5. Whilst the throttle is < 30% before takeoff, all stick inputs are being ignored.
325+
// 6. If during the autotakeoff sequence, at any stage, the throttle stick position reduces to less than 10%, landing is initiated.
326326

327327
switch (autotakeoffState) {
328328
case STATUSVTOLAUTOTAKEOFF_CONTROLSTATE_REQUIREUNARMEDFIRST:

flight/modules/PathFollower/vtolautotakeofffsm.cpp

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
******************************************************************************
33
*
44
* @file vtolautotakeofffsm.cpp
5-
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2015.
5+
* @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2018
6+
* The OpenPilot Team, http://www.openpilot.org Copyright (C) 2015.
67
* @brief This autotakeoff state machine is a helper state machine to the
78
* VtolAutoTakeoffController.
89
* @see The GNU Public License (GPL) Version 3
@@ -60,11 +61,11 @@ extern "C" {
6061

6162

6263
// Private constants
63-
#define TIMER_COUNT_PER_SECOND (1000 / vtolPathFollowerSettings->UpdatePeriod)
64-
#define TIMEOUT_SLOWSTART (2 * TIMER_COUNT_PER_SECOND)
65-
#define TIMEOUT_THRUSTUP (1 * TIMER_COUNT_PER_SECOND)
66-
#define TIMEOUT_THRUSTDOWN (5 * TIMER_COUNT_PER_SECOND)
67-
#define AUTOTAKEOFFING_SLOWDOWN_HEIGHT -5.0f
64+
#define TIMER_COUNT_PER_SECOND (1000 / vtolPathFollowerSettings->UpdatePeriod)
65+
#define TIMEOUT_SLOWSTART (2 * TIMER_COUNT_PER_SECOND)
66+
#define TIMEOUT_THRUSTUP (1 * TIMER_COUNT_PER_SECOND)
67+
#define TIMEOUT_THRUSTDOWN (5 * TIMER_COUNT_PER_SECOND)
68+
#define AUTOTAKEOFF_SLOWDOWN_HEIGHT -5.0f
6869

6970
VtolAutoTakeoffFSM::PathFollowerFSM_AutoTakeoffStateHandler_T VtolAutoTakeoffFSM::sAutoTakeoffStateTable[AUTOTAKEOFF_STATE_SIZE] = {
7071
[AUTOTAKEOFF_STATE_INACTIVE] = { .setup = &VtolAutoTakeoffFSM::setup_inactive, .run = 0 },
@@ -246,14 +247,8 @@ void VtolAutoTakeoffFSM::setState(StatusVtolAutoTakeoffStateOptions newState, St
246247
mAutoTakeoffData->currentState = newState;
247248

248249
if (newState != STATUSVTOLAUTOTAKEOFF_STATE_INACTIVE) {
249-
PositionStateData positionState;
250-
PositionStateGet(&positionState);
251-
float takeOffDown = 0.0f;
252-
if (mAutoTakeoffData->takeOffLocation.Status == TAKEOFFLOCATION_STATUS_VALID) {
253-
takeOffDown = mAutoTakeoffData->takeOffLocation.Down;
254-
}
255-
mAutoTakeoffData->fsmAutoTakeoffStatus.AltitudeAtState[newState] = positionState.Down - takeOffDown;
256-
assessAltitude();
250+
float altitudeAboveTakeoff = assessAltitude();
251+
mAutoTakeoffData->fsmAutoTakeoffStatus.AltitudeAtState[newState] = altitudeAboveTakeoff;
257252
}
258253

259254
// Restart state timer counter
@@ -266,6 +261,7 @@ void VtolAutoTakeoffFSM::setState(StatusVtolAutoTakeoffStateOptions newState, St
266261
(this->*sAutoTakeoffStateTable[mAutoTakeoffData->currentState].setup)();
267262
}
268263

264+
// Update StatusVtolAutoTakeoff UAVObject with new status
269265
updateVtolAutoTakeoffFSMStatus();
270266
}
271267

@@ -276,6 +272,7 @@ void VtolAutoTakeoffFSM::setStateTimeout(int32_t count)
276272
mAutoTakeoffData->stateTimeoutCount = count;
277273
}
278274

275+
// Update StatusVtolAutoTakeoff UAVObject
279276
void VtolAutoTakeoffFSM::updateVtolAutoTakeoffFSMStatus()
280277
{
281278
mAutoTakeoffData->fsmAutoTakeoffStatus.State = mAutoTakeoffData->currentState;
@@ -288,7 +285,7 @@ void VtolAutoTakeoffFSM::updateVtolAutoTakeoffFSMStatus()
288285
}
289286

290287

291-
void VtolAutoTakeoffFSM::assessAltitude(void)
288+
float VtolAutoTakeoffFSM::assessAltitude(void)
292289
{
293290
float positionDown;
294291

@@ -298,11 +295,13 @@ void VtolAutoTakeoffFSM::assessAltitude(void)
298295
takeOffDown = mAutoTakeoffData->takeOffLocation.Down;
299296
}
300297
float positionDownRelativeToTakeoff = positionDown - takeOffDown;
301-
if (positionDownRelativeToTakeoff < AUTOTAKEOFFING_SLOWDOWN_HEIGHT) {
298+
if (positionDownRelativeToTakeoff < AUTOTAKEOFF_SLOWDOWN_HEIGHT) {
302299
mAutoTakeoffData->flLowAltitude = false;
303300
} else {
304301
mAutoTakeoffData->flLowAltitude = true;
305302
}
303+
// Return the altitude above takeoff, which is the negation of positionDownRelativeToTakeoff
304+
return -positionDownRelativeToTakeoff;
306305
}
307306

308307
// Action the required state from plans.c
@@ -347,10 +346,10 @@ void VtolAutoTakeoffFSM::setup_checkstate(void)
347346
// Assumptions that do not need to be checked if flight mode is AUTOTAKEOFF
348347
// 1. Already armed
349348
// 2. Not in flight. This was checked in plans.c
350-
// 3. User has placed throttle position to more than 50% to allow autotakeoff
349+
// 3. User has placed throttle position to more than 30% to allow autotakeoff
351350

352351
// If pathplanner, we need additional checks
353-
// E.g. if inflight, this mode is just positon hol
352+
// E.g. if inflight, this mode is just position hold
354353
StabilizationDesiredData stabDesired;
355354

356355
StabilizationDesiredGet(&stabDesired);
@@ -407,15 +406,13 @@ void VtolAutoTakeoffFSM::run_slowstart(__attribute__((unused)) uint8_t flTimeout
407406
}
408407
}
409408

410-
// STATE: THRUSTUP spools up motors to vtol min over 5 seconds for effect.
409+
// STATE: THRUSTUP spools up motors to vtol min over 1 second for effect.
411410
// PID loops may be cumulating I terms but that problem needs to be solved
412411
#define THRUSTUP_FINAL_THRUST_AS_RATIO_OF_VTOLMAX 0.8f
413412
void VtolAutoTakeoffFSM::setup_thrustup(void)
414413
{
415414
setStateTimeout(TIMEOUT_THRUSTUP);
416415
mAutoTakeoffData->flZeroStabiHorizontal = false;
417-
StabilizationDesiredData stabDesired;
418-
StabilizationDesiredGet(&stabDesired);
419416
mAutoTakeoffData->sum2 = THRUSTUP_FINAL_THRUST_AS_RATIO_OF_VTOLMAX * vtolPathFollowerSettings->ThrustLimits.Max;
420417
mAutoTakeoffData->sum1 = (mAutoTakeoffData->sum2 - mAutoTakeoffData->boundThrustMax) / (float)TIMEOUT_THRUSTUP;
421418
mAutoTakeoffData->boundThrustMin = vtolPathFollowerSettings->ThrustLimits.Min;

flight/modules/PathFollower/vtollandfsm.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
******************************************************************************
33
*
44
* @file vtollandfsm.cpp
5-
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2015.
5+
* @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2018
6+
* The OpenPilot Team, http://www.openpilot.org Copyright (C) 2015.
67
* @brief This landing state machine is a helper state machine to the
78
* VtolLandController.
89
* @see The GNU Public License (GPL) Version 3
@@ -275,14 +276,8 @@ void VtolLandFSM::setState(StatusVtolLandStateOptions newState, StatusVtolLandSt
275276
mLandData->currentState = newState;
276277

277278
if (newState != STATUSVTOLLAND_STATE_INACTIVE) {
278-
PositionStateData positionState;
279-
PositionStateGet(&positionState);
280-
float takeOffDown = 0.0f;
281-
if (mLandData->takeOffLocation.Status == TAKEOFFLOCATION_STATUS_VALID) {
282-
takeOffDown = mLandData->takeOffLocation.Down;
283-
}
284-
mLandData->fsmLandStatus.AltitudeAtState[newState] = positionState.Down - takeOffDown;
285-
assessAltitude();
279+
float altitudeAboveTakeoff = assessAltitude();
280+
mLandData->fsmLandStatus.AltitudeAtState[newState] = altitudeAboveTakeoff;
286281
}
287282

288283
// Restart state timer counter
@@ -332,7 +327,7 @@ float VtolLandFSM::BoundVelocityDown(float velocity_down)
332327
}
333328
}
334329

335-
void VtolLandFSM::assessAltitude(void)
330+
float VtolLandFSM::assessAltitude(void)
336331
{
337332
float positionDown;
338333

@@ -347,6 +342,8 @@ void VtolLandFSM::assessAltitude(void)
347342
} else {
348343
mLandData->flLowAltitude = true;
349344
}
345+
// Return the altitude above takeoff, which is the negation of positionDownRelativeToTakeoff
346+
return -positionDownRelativeToTakeoff;
350347
}
351348

352349

0 commit comments

Comments
 (0)