Skip to content

Commit c123a24

Browse files
committed
toilet bowling detection
1 parent 93153cf commit c123a24

File tree

8 files changed

+58
-1
lines changed

8 files changed

+58
-1
lines changed

docs/Settings.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3992,6 +3992,16 @@ P gain of altitude PID controller (Multirotor)
39923992

39933993
---
39943994

3995+
### nav_mc_toiletbowl_detection
3996+
3997+
Sets sensitivity of toilet bowling detection for multirotors. On detection a heading correction is applied which should stop the toilet bowling. A setting of 2 works well for 5 inch multirotors. Increasing the setting will reduce sensitivity and delay detection. Set to 0 to disable. (Toilet bowling occurs most obviously during position hold when an inaccurate compass heading causes a rapidly increasing fast sweeping bowl shaped flight path).
3998+
3999+
| Default | Min | Max |
4000+
| --- | --- | --- |
4001+
| 0 | 0 | 20 |
4002+
4003+
---
4004+
39954005
### nav_mc_vel_xy_d
39964006

39974007
D gain of Position-Rate (Velocity to Acceleration) PID controller. It can damp P and I. Increasing D might help when drone overshoots target.

src/main/fc/settings.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2516,6 +2516,12 @@ groups:
25162516
field: mc.inverted_crash_detection
25172517
min: 0
25182518
max: 15
2519+
- name: nav_mc_toiletbowl_detection
2520+
description: "Sets sensitivity of toilet bowling detection for multirotors. On detection a heading correction is applied which should stop the toilet bowling. A setting of 2 works well for 5 inch multirotors. Increasing the setting will reduce sensitivity and delay detection. Set to 0 to disable. (Toilet bowling occurs most obviously during position hold when an inaccurate compass heading causes a rapidly increasing fast sweeping bowl shaped flight path)."
2521+
default_value: 0
2522+
field: mc.toiletbowl_detection
2523+
min: 0
2524+
max: 20
25192525
- name: nav_mc_althold_throttle
25202526
description: "If set to STICK the FC remembers the throttle stick position when enabling ALTHOLD and treats it as the neutral midpoint for holding altitude. If set to MID_STICK or HOVER the neutral midpoint is set to the mid stick position or the hover throttle position respectively."
25212527
default_value: "STICK"

src/main/io/osd.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6156,6 +6156,9 @@ textAttributes_t osdGetSystemMessage(char *buff, size_t buff_size, bool isCenter
61566156
}
61576157
}
61586158
}
6159+
if (STATE(MULTIROTOR) && isNavHoldPositionActive() && toiletBowlingHeadingCorrection) {
6160+
messages[messageCount++] = OSD_MESSAGE_STR(OSD_MSG_TOILET_BOWL);
6161+
}
61596162
} else if (ARMING_FLAG(ARMING_DISABLED_ALL_FLAGS)) { /* ADDS MAXIMUM OF 2 MESSAGES TO TOTAL */
61606163
unsigned invalidIndex;
61616164

src/main/io/osd.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@
122122
#define OSD_MSG_ANGLEHOLD_PITCH "(ANGLEHOLD PITCH)"
123123
#define OSD_MSG_ANGLEHOLD_LEVEL "(ANGLEHOLD LEVEL)"
124124
#define OSD_MSG_MOVE_STICKS "MOVE STICKS TO ABORT"
125+
#define OSD_MSG_TOILET_BOWL "TOILET BOWLING !"
125126

126127
#ifdef USE_DEV_TOOLS
127128
#define OSD_MSG_GRD_TEST_MODE "GRD TEST > MOTORS DISABLED"

src/main/navigation/navigation.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ PG_RESET_TEMPLATE(navConfig_t, navConfig,
201201
.slowDownForTurning = SETTING_NAV_MC_WP_SLOWDOWN_DEFAULT,
202202
.althold_throttle_type = SETTING_NAV_MC_ALTHOLD_THROTTLE_DEFAULT, // STICK
203203
.inverted_crash_detection = SETTING_NAV_MC_INVERTED_CRASH_DETECTION_DEFAULT, // 0 - disarm time delay for inverted crash detection
204+
.toiletbowl_detection = SETTING_NAV_MC_TOILETBOWL_DETECTION_DEFAULT, // 0 - sensitivity factor for toilet bowling detection
204205
},
205206

206207
// Fixed wing
@@ -252,6 +253,7 @@ static navWapointHeading_t wpHeadingControl;
252253
navigationPosControl_t posControl;
253254
navSystemStatus_t NAV_Status;
254255
static bool landingDetectorIsActive;
256+
int16_t toiletBowlingHeadingCorrection; // Indicates toilet bowling detected multirotor
255257

256258
EXTENDED_FASTRAM multicopterPosXyCoefficients_t multicopterPosXyCoefficients;
257259

src/main/navigation/navigation.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ typedef struct geozone_s {
197197
int32_t distanceHorToNearestZone;
198198
int32_t distanceVertToNearestZone;
199199
int32_t zoneInfo;
200-
int32_t currentzoneMaxAltitude;
200+
int32_t currentzoneMaxAltitude;
201201
int32_t currentzoneMinAltitude;
202202
bool nearestHorZoneHasAction;
203203
bool sticksLocked;
@@ -464,6 +464,7 @@ typedef struct navConfig_s {
464464
bool slowDownForTurning; // Slow down during WP missions when changing heading on next waypoint
465465
uint8_t althold_throttle_type; // throttle zero datum type for alt hold
466466
uint8_t inverted_crash_detection; // Enables inverted crash detection, setting defines disarm time delay (0 = disabled)
467+
uint8_t toiletbowl_detection; // Enables toilet bowling detection and heading correction (0 = disabled)
467468
} mc;
468469

469470
struct {

src/main/navigation/navigation_multicopter.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,33 @@ static float getVelocityExpoAttenuationFactor(float velTotal, float velMax)
483483
return 1.0f - posControl.posResponseExpo * (1.0f - (velScale * velScale)); // x^3 expo factor
484484
}
485485

486+
static void isToiletBowlingDetected(void)
487+
{
488+
static timeMs_t startTime = 0;
489+
490+
uint16_t courseToHoldPoint = calculateBearingToDestination(&posControl.desiredState.pos);
491+
int16_t courseError = wrap_18000(courseToHoldPoint - 10 * gpsSol.groundCourse);
492+
bool courseErrorCheck = ABS(courseError) > 3000 && ABS(courseError) < 15500;
493+
494+
uint16_t distanceToHoldPoint = calculateDistanceToDestination(&posControl.desiredState.pos);
495+
bool distanceSpeedCheck = posControl.actualState.velXY * distanceToHoldPoint > (navConfig()->mc.toiletbowl_detection * 10000);
496+
497+
if (toiletBowlingHeadingCorrection) {
498+
uint16_t correctedHeading = wrap_36000(posControl.actualState.yaw - 0.67 * toiletBowlingHeadingCorrection);
499+
posControl.actualState.sinYaw = sin_approx(CENTIDEGREES_TO_RADIANS(correctedHeading));
500+
posControl.actualState.cosYaw = cos_approx(CENTIDEGREES_TO_RADIANS(correctedHeading));
501+
} else if (posControl.actualState.velXY > 100 && distanceToHoldPoint > 100 && courseErrorCheck && distanceSpeedCheck) {
502+
if (startTime == 0) {
503+
startTime = millis();
504+
} else if (millis() - startTime > 1000) {
505+
// Try to correct heading error
506+
toiletBowlingHeadingCorrection = courseError;
507+
}
508+
} else {
509+
startTime = 0;
510+
}
511+
}
512+
486513
static void updatePositionVelocityController_MC(const float maxSpeed)
487514
{
488515
if (FLIGHT_MODE(NAV_COURSE_HOLD_MODE)) {
@@ -498,6 +525,12 @@ static void updatePositionVelocityController_MC(const float maxSpeed)
498525
}
499526
}
500527

528+
if (navConfig()->mc.toiletbowl_detection && isNavHoldPositionActive()) {
529+
isToiletBowlingDetected();
530+
} else {
531+
toiletBowlingHeadingCorrection = 0;
532+
}
533+
501534
const float posErrorX = posControl.desiredState.pos.x - navGetCurrentActualPositionAndVelocity()->pos.x;
502535
const float posErrorY = posControl.desiredState.pos.y - navGetCurrentActualPositionAndVelocity()->pos.y;
503536

src/main/navigation/navigation_private.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,7 @@ PG_DECLARE_ARRAY(navWaypoint_t, NAV_MAX_WAYPOINTS, nonVolatileWaypointList);
525525

526526
extern navigationPosControl_t posControl;
527527
extern multicopterPosXyCoefficients_t multicopterPosXyCoefficients;
528+
extern int16_t toiletBowlingHeadingCorrection;
528529

529530
/* Internally used functions */
530531
const navEstimatedPosVel_t * navGetCurrentActualPositionAndVelocity(void);

0 commit comments

Comments
 (0)