Skip to content

Commit

Permalink
Merge pull request #8280 from breadoven/abo_wp_enforce_altitude_fix
Browse files Browse the repository at this point in the history
Enforce waypoint altitude tolerance fix
  • Loading branch information
DzikuVx committed Aug 15, 2022
2 parents 359030d + f7e10fe commit f716721
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 18 deletions.
4 changes: 2 additions & 2 deletions docs/Settings.md
Expand Up @@ -3884,11 +3884,11 @@ Defines how Pitch/Roll input from RC receiver affects flight in POSHOLD mode: AT

### nav_wp_enforce_altitude

Forces craft to achieve the set WP altitude as well as position before moving to next WP. Position is held and altitude adjusted as required before moving on.
Forces craft to achieve the set WP altitude as well as position before moving to next WP. Position is held and altitude adjusted as required before moving on. 0 = disabled, otherwise setting defines altitude capture tolerance [cm], e.g. 100 means required altitude is achieved when within 100cm of waypoint altitude setting.

| Default | Min | Max |
| --- | --- | --- |
| OFF | OFF | ON |
| 0 | 0 | 2000 |

---

Expand Down
9 changes: 5 additions & 4 deletions src/main/fc/settings.yaml
Expand Up @@ -2421,10 +2421,11 @@ groups:
min: 10
max: 10000
- name: nav_wp_enforce_altitude
description: "Forces craft to achieve the set WP altitude as well as position before moving to next WP. Position is held and altitude adjusted as required before moving on."
default_value: OFF
field: general.flags.waypoint_enforce_altitude
type: bool
description: "Forces craft to achieve the set WP altitude as well as position before moving to next WP. Position is held and altitude adjusted as required before moving on. 0 = disabled, otherwise setting defines altitude capture tolerance [cm], e.g. 100 means required altitude is achieved when within 100cm of waypoint altitude setting."
default_value: 0
field: general.waypoint_enforce_altitude
min: 0
max: 2000
- name: nav_wp_safe_distance
description: "First waypoint in the mission should be closer than this value [cm]. A value of 0 disables this check."
default_value: 10000
Expand Down
6 changes: 3 additions & 3 deletions src/main/io/osd.c
Expand Up @@ -1098,7 +1098,7 @@ uint16_t osdGetRemainingGlideTime(void) {

value = pt1FilterApply4(&glideTimeFilterState, isnormal(value) ? value : 0, 0.5, MS2S(curTimeMs - glideTimeUpdatedMs));
glideTimeUpdatedMs = curTimeMs;

if (value < 0) {
value = osdGetAltitude() / abs((int)value);
} else {
Expand Down Expand Up @@ -2385,7 +2385,7 @@ static bool osdDrawSingleElement(uint8_t item)
}
break;
}
case OSD_GLIDE_TIME_REMAINING:
case OSD_GLIDE_TIME_REMAINING:
{
uint16_t glideTime = osdGetRemainingGlideTime();
buff[0] = SYM_GLIDE_MINS;
Expand Down Expand Up @@ -4409,7 +4409,7 @@ textAttributes_t osdGetSystemMessage(char *buff, size_t buff_size, bool isCenter
tfp_sprintf(messageBuf, "TO WP %u/%u (%s)", getGeoWaypointNumber(posControl.activeWaypointIndex), posControl.geoWaypointCount, buf);
messages[messageCount++] = messageBuf;
} else if (NAV_Status.state == MW_NAV_STATE_HOLD_TIMED) {
if (navConfig()->general.flags.waypoint_enforce_altitude && !posControl.wpAltitudeReached) {
if (navConfig()->general.waypoint_enforce_altitude && !posControl.wpAltitudeReached) {
messages[messageCount++] = OSD_MESSAGE_STR(OSD_MSG_ADJUSTING_WP_ALT);
} else {
// WP hold time countdown in seconds
Expand Down
14 changes: 6 additions & 8 deletions src/main/navigation/navigation.c
Expand Up @@ -61,8 +61,6 @@
#include "sensors/boardalignment.h"
#include "sensors/battery.h"

#define WP_ALTITUDE_MARGIN_CM 100 // WP enforce altitude tolerance, used when WP altitude setting enforced when WP reached

// Multirotors:
#define MR_RTH_CLIMB_OVERSHOOT_CM 100 // target this amount of cm *above* the target altitude to ensure it is actually reached (Vz > 0 at target alt)
#define MR_RTH_CLIMB_MARGIN_MIN_CM 100 // start cruising home this amount of cm *before* reaching the cruise altitude (while continuing the ascend)
Expand Down Expand Up @@ -100,7 +98,7 @@ STATIC_ASSERT(NAV_MAX_WAYPOINTS < 254, NAV_MAX_WAYPOINTS_exceeded_allowable_rang
PG_REGISTER_ARRAY(navWaypoint_t, NAV_MAX_WAYPOINTS, nonVolatileWaypointList, PG_WAYPOINT_MISSION_STORAGE, 2);
#endif

PG_REGISTER_WITH_RESET_TEMPLATE(navConfig_t, navConfig, PG_NAV_CONFIG, 1);
PG_REGISTER_WITH_RESET_TEMPLATE(navConfig_t, navConfig, PG_NAV_CONFIG, 2);

PG_RESET_TEMPLATE(navConfig_t, navConfig,
.general = {
Expand All @@ -122,7 +120,6 @@ PG_RESET_TEMPLATE(navConfig_t, navConfig,
.mission_planner_reset = SETTING_NAV_MISSION_PLANNER_RESET_DEFAULT, // Allow mode switch toggle to reset Mission Planner WPs
.waypoint_mission_restart = SETTING_NAV_WP_MISSION_RESTART_DEFAULT, // WP mission restart action
.soaring_motor_stop = SETTING_NAV_FW_SOARING_MOTOR_STOP_DEFAULT, // stops motor when Saoring mode enabled
.waypoint_enforce_altitude = SETTING_NAV_WP_ENFORCE_ALTITUDE_DEFAULT, // Forces set wp altitude to be achieved
.rth_trackback_mode = SETTING_NAV_RTH_TRACKBACK_MODE_DEFAULT // RTH trackback useage mode
},

Expand Down Expand Up @@ -153,6 +150,7 @@ PG_RESET_TEMPLATE(navConfig_t, navConfig,
.safehome_max_distance = SETTING_SAFEHOME_MAX_DISTANCE_DEFAULT, // Max distance that a safehome is from the arming point
.max_altitude = SETTING_NAV_MAX_ALTITUDE_DEFAULT,
.rth_trackback_distance = SETTING_NAV_RTH_TRACKBACK_DISTANCE_DEFAULT, // Max distance allowed for RTH trackback
.waypoint_enforce_altitude = SETTING_NAV_WP_ENFORCE_ALTITUDE_DEFAULT, // Forces set wp altitude to be achieved
},

// MC-specific
Expand Down Expand Up @@ -1670,13 +1668,13 @@ static navigationFSMEvent_t navOnEnteringState_NAV_STATE_WAYPOINT_REACHED(naviga
{
UNUSED(previousState);

if (navConfig()->general.flags.waypoint_enforce_altitude) {
if (navConfig()->general.waypoint_enforce_altitude) {
posControl.wpAltitudeReached = isWaypointAltitudeReached();
}

switch ((navWaypointActions_e)posControl.waypointList[posControl.activeWaypointIndex].action) {
case NAV_WP_ACTION_WAYPOINT:
if (navConfig()->general.flags.waypoint_enforce_altitude && !posControl.wpAltitudeReached) {
if (navConfig()->general.waypoint_enforce_altitude && !posControl.wpAltitudeReached) {
return NAV_FSM_EVENT_SWITCH_TO_WAYPOINT_HOLD_TIME;
} else {
return NAV_FSM_EVENT_SUCCESS; // NAV_STATE_WAYPOINT_NEXT
Expand Down Expand Up @@ -1709,7 +1707,7 @@ static navigationFSMEvent_t navOnEnteringState_NAV_STATE_WAYPOINT_HOLD_TIME(navi
return NAV_FSM_EVENT_SWITCH_TO_EMERGENCY_LANDING;
}

if (navConfig()->general.flags.waypoint_enforce_altitude && !posControl.wpAltitudeReached) {
if (navConfig()->general.waypoint_enforce_altitude && !posControl.wpAltitudeReached) {
// Adjust altitude to waypoint setting
if (STATE(AIRPLANE)) {
int8_t altitudeChangeDirection = posControl.activeWaypoint.pos.z > navGetCurrentActualPositionAndVelocity()->pos.z ? 1 : -1;
Expand Down Expand Up @@ -2243,7 +2241,7 @@ bool isWaypointReached(const navWaypointPosition_t * waypoint, const bool isWayp

bool isWaypointAltitudeReached(void)
{
return ABS(navGetCurrentActualPositionAndVelocity()->pos.z - posControl.activeWaypoint.pos.z) < WP_ALTITUDE_MARGIN_CM;
return ABS(navGetCurrentActualPositionAndVelocity()->pos.z - posControl.activeWaypoint.pos.z) < navConfig()->general.waypoint_enforce_altitude;
}

static void updateHomePositionCompatibility(void)
Expand Down
2 changes: 1 addition & 1 deletion src/main/navigation/navigation.h
Expand Up @@ -227,7 +227,6 @@ typedef struct navConfig_s {
uint8_t soaring_motor_stop; // stop motor when Soaring mode enabled
uint8_t mission_planner_reset; // Allow WP Mission Planner reset using mode toggle (resets WPs to 0)
uint8_t waypoint_mission_restart; // Waypoint mission restart action
uint8_t waypoint_enforce_altitude; // Forces waypoint altitude to be achieved
uint8_t rth_trackback_mode; // Useage mode setting for RTH trackback
} flags;

Expand Down Expand Up @@ -257,6 +256,7 @@ typedef struct navConfig_s {
uint16_t safehome_max_distance; // Max distance that a safehome is from the arming point
uint16_t max_altitude; // Max altitude when in AltHold mode (not Surface Following)
uint16_t rth_trackback_distance; // RTH trackback maximum distance [m]
uint16_t waypoint_enforce_altitude; // Forces waypoint altitude to be achieved
} general;

struct {
Expand Down

0 comments on commit f716721

Please sign in to comment.