Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
112 commits
Select commit Hold shift + click to select a range
27cf0f0
autopilot naming, function sharing
ctzsnooze Sep 29, 2024
fe79db9
initial position hold setup
ctzsnooze Oct 7, 2024
1545a65
get current gps location
ctzsnooze Oct 7, 2024
04fc90b
first position hold draft
ctzsnooze Oct 8, 2024
88fe636
basic control scheme
ctzsnooze Oct 8, 2024
0cfadbb
add debug values for testing
ctzsnooze Oct 8, 2024
b882145
first working example with smoothed acceleration
ctzsnooze Oct 9, 2024
51fba29
add deadbands
ctzsnooze Oct 9, 2024
793a939
Re-organise included files and functions thanks Karate
ctzsnooze Oct 7, 2024
eea0f1a
revise PID gains
ctzsnooze Oct 9, 2024
8b92771
PIDJ distance controller, not velocity based. Remove airmode check
ctzsnooze Oct 10, 2024
cf279d5
sanity check notes
ctzsnooze Oct 10, 2024
8739c27
fix pid bug and improve iTerm handling
ctzsnooze Oct 11, 2024
9ed5445
calculate PIDs independently for each axis, increas DJ gains
ctzsnooze Oct 11, 2024
588ea7b
adjust pids and smoothing; smoothing cutoff to settings
ctzsnooze Oct 12, 2024
0e4416e
force iTerm to zero when close to target
ctzsnooze Oct 12, 2024
9a70022
allow earth referencing in alt and pos hold
ctzsnooze Oct 12, 2024
80d6318
stop activation until throttle raised, but not require airmode
ctzsnooze Oct 12, 2024
acba1e9
remove unnecessary debug
ctzsnooze Oct 12, 2024
3de71f6
block arming if poshold or althold switches are on
ctzsnooze Oct 13, 2024
6664f53
basic sanity check and OSD warning
ctzsnooze Oct 14, 2024
564fa55
allow user to fly without mag only if they reverse the default
ctzsnooze Oct 14, 2024
1445614
separate alt and pos hold deadbands
ctzsnooze Oct 14, 2024
487066a
try to prevent position hold if no mag without valid IMU
ctzsnooze Oct 14, 2024
3227c71
retaisn iTerm just attenuate the output
ctzsnooze Oct 12, 2024
bd53f5e
struct for values
ctzsnooze Oct 15, 2024
1da1001
reset position at start when slowed down, retain rotated iTerm back
ctzsnooze Oct 15, 2024
d5406b2
resolve bounceback and remove iTerm attenuation
ctzsnooze Oct 16, 2024
cc43f55
adjust PID gains to 30
ctzsnooze Oct 16, 2024
0eadf30
force unit tests sto work
ctzsnooze Oct 16, 2024
66f0469
tidy up after merge
ctzsnooze Oct 17, 2024
0b69829
Use mpif
ctzsnooze Oct 17, 2024
4e81ca4
conditionally only do compass check if Mag is defined
ctzsnooze Oct 17, 2024
65d1c83
fixe defines and remove const
ctzsnooze Oct 17, 2024
bd30849
comments to explain strange rc multiplier
ctzsnooze Oct 17, 2024
3d9f824
fix small omission when refactoring after throttle raised PR
ctzsnooze Oct 17, 2024
9fb2cf9
licence updates, refactoring from review comments
ctzsnooze Oct 18, 2024
972a9b6
fix issues when pos hold deadband is set to zero
ctzsnooze Oct 18, 2024
8d80009
A for acceleration element, not J
ctzsnooze Oct 18, 2024
933b893
compact the posHoldUpdate() function - thanks K
ctzsnooze Oct 18, 2024
b06bfe6
rename showPosHoldWarning to posHoldFailure
ctzsnooze Oct 18, 2024
fe69c11
Use a function in gps.c to initate the posHold activity on new GPS data
ctzsnooze Oct 18, 2024
dcf7812
Use autopilotAngle in place of posHoldAngle
ctzsnooze Oct 18, 2024
c4d7e9b
separate function for gpsHeading truth
ctzsnooze Oct 18, 2024
7821d3a
use FLIGHT_MODE(POS_HOLD_MODE) in place of isPosHoldRequested
ctzsnooze Oct 18, 2024
155fc3e
removed non-required definitions
ctzsnooze Oct 18, 2024
f54ecf7
fix failure to initiate position hold from error in ifdef
ctzsnooze Oct 18, 2024
cdc051d
refactoring from reviews, rename posHoldReset
ctzsnooze Oct 19, 2024
2ad7628
move deadbands for pos and alt hold to their config files.
ctzsnooze Oct 19, 2024
9b21bee
comment
ctzsnooze Oct 19, 2024
1a28cde
fix for blackbox breakup of GPS values
ctzsnooze Oct 19, 2024
e3e995c
fix for msp change for posHoldConfig
ctzsnooze Oct 19, 2024
ed10cc0
try to constrain aggressiveness at start, smaller deadband
ctzsnooze Oct 20, 2024
9022794
allow greater overshoot at the start for high incoming speed
ctzsnooze Oct 20, 2024
a04a4b8
dynamically update smoothing at the start
ctzsnooze Oct 20, 2024
6f2ae69
retain iTerm when moving sticks, to keep attitude in the wind
ctzsnooze Oct 20, 2024
e338731
fix unit tests
ctzsnooze Oct 20, 2024
43fbc25
finally retain iTerm correctly while moving sticks, but reset at start
ctzsnooze Oct 20, 2024
34b131b
Fix iTerm reset and parameter rotation
ctzsnooze Oct 20, 2024
a176e99
absolute rotation vs incremental rotation, fix spike after resetting …
ctzsnooze Oct 21, 2024
46877be
don't rotate D or A, it reverses their sign inappropriately
ctzsnooze Oct 21, 2024
42b96ee
Block yaw, allow in CLI, option to apply yaw correction code
ctzsnooze Oct 21, 2024
f57a04f
restore debug
ctzsnooze Oct 22, 2024
85fc9c0
calc D from groundspeed and drift angle
ctzsnooze Oct 22, 2024
062345b
add back some target based D
ctzsnooze Oct 22, 2024
e9ed82a
Earth Frame iTerm vector
ctzsnooze Oct 22, 2024
aace0f6
fix unit test
ctzsnooze Oct 24, 2024
48f289d
lower PID gains, slowly leak iTerm while sticks move
ctzsnooze Oct 25, 2024
312ca9d
earth ref Dterm, not from GPS Speed
ctzsnooze Oct 25, 2024
d15bb13
stronger PIDs
ctzsnooze Oct 25, 2024
55f4ec5
adjust debug
ctzsnooze Oct 25, 2024
2df90e8
shoehorn the unit tests
ctzsnooze Oct 25, 2024
8ea3a66
Proper earth referencing, at last
ctzsnooze Oct 26, 2024
ec11784
clean up a bit
ctzsnooze Oct 26, 2024
6c9b39e
no need to duplicate wrapping done in sin_approx
ctzsnooze Oct 26, 2024
b51e3fd
add note about PT1 gain on PT2 filters
ctzsnooze Oct 26, 2024
b590cae
avoid unnecessary float conversions
ctzsnooze Oct 26, 2024
e8b4079
Remove unnecessary CLI testing params
ctzsnooze Oct 26, 2024
2cd2dad
update PID gains, stronger tilt angle correction
ctzsnooze Oct 26, 2024
cade4c6
improved distance to target. thanks to demvlad
ctzsnooze Oct 27, 2024
71e2437
Terminate start individually on each axis
ctzsnooze Oct 27, 2024
36740f6
refactoring to avoid code duplication
ctzsnooze Oct 27, 2024
9ab8fd9
implement reviews, reduce PID gains
ctzsnooze Oct 27, 2024
4819510
upsampling filter at 5Hz
ctzsnooze Oct 28, 2024
eb9b4ac
warn if posHold mode requested but throttle not above airmode activat…
ctzsnooze Oct 28, 2024
f9d2db4
disable angle feedforward in position hold
ctzsnooze Oct 29, 2024
7a1b01a
rebase, pass unit test
ctzsnooze Oct 29, 2024
ff0506a
sequential PT1's, refactoring from reviews
ctzsnooze Oct 30, 2024
6872ee0
PID and filter revision
ctzsnooze Oct 30, 2024
7fa9379
bane of my life
ctzsnooze Oct 30, 2024
a91db36
lenient sanity check, message for noMag, possible DA vector limit code
ctzsnooze Oct 31, 2024
a007c76
replace angleTarget in pid.c only when autopilot is active
ctzsnooze Oct 31, 2024
d2671e2
rearrange status checks
ctzsnooze Oct 31, 2024
f14415d
fix debug, tidy up EF axis names, add comments about sign and direction
ctzsnooze Oct 31, 2024
fb2b866
stop more cleanly, easier sanity check, phases, debugs complete
ctzsnooze Nov 1, 2024
826cb56
extend sanity check distance while sticks move; refactor; comments
ctzsnooze Nov 1, 2024
e853171
fix instability on hard stop, allow activation after arming but befor…
ctzsnooze Nov 2, 2024
953cc77
make altHoldState_t local, getter to pass unit tests.
ctzsnooze Nov 2, 2024
b62b5c5
hopefully the last cleanup of this test file
ctzsnooze Nov 3, 2024
f7f2025
implement review from PL - thank you!
ctzsnooze Nov 5, 2024
023af4c
restore angle limiting in pid.c , max of 80 degrees allowed in CLI
ctzsnooze Nov 5, 2024
33a3df1
fixes after review changes weren't right
ctzsnooze Nov 5, 2024
6024a20
fix braces
ctzsnooze Nov 6, 2024
a5a0b64
limit max angle to 50 by vector length
ctzsnooze Nov 6, 2024
953763f
Fix curly brackets, comments and debug mistake
ctzsnooze Nov 6, 2024
a7a67f6
in autopilot modes, allow up to 85 deg for pos hold
ctzsnooze Nov 6, 2024
3e7315d
limit pilot angle in position hold to half the configured position ho…
ctzsnooze Nov 6, 2024
1b30a08
use smaller of angle_limit or half the autopilot limit
ctzsnooze Nov 6, 2024
c695486
increase alt_hold sensitivity 5x and narrow deadband to 20
ctzsnooze Nov 7, 2024
98b25c2
make altitude control 5x stronger with narrower deadband and new name
ctzsnooze Nov 7, 2024
758c886
GPS stamp
ledvinap Nov 8, 2024
b535747
Adapt GPS rescue
ledvinap Nov 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions mk/source.mk
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ PG_SRC = \
pg/piniobox.c \
pg/pinio.c \
pg/pin_pull_up_down.c \
pg/pos_hold.c \
pg/rcdevice.c \
pg/rpm_filter.c \
pg/rx.c \
Expand Down Expand Up @@ -172,6 +173,7 @@ COMMON_SRC = \
flight/pid.c \
flight/pid_init.c \
flight/position.c \
flight/pos_hold.c \
flight/rpm_filter.c \
flight/servos.c \
flight/servos_tricopter.c \
Expand Down
34 changes: 24 additions & 10 deletions src/main/blackbox/blackbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
#include "flight/mixer.h"
#include "flight/pid.h"
#include "flight/position.h"
#include "flight/pos_hold.h"
#include "flight/rpm_filter.h"
#include "flight/servos.h"

Expand Down Expand Up @@ -1627,25 +1628,32 @@ static bool blackboxWriteSysinfo(void)
BLACKBOX_PRINT_HEADER_LINE(PARAM_NAME_ACC_HARDWARE, "%d", accelerometerConfig()->acc_hardware);
#endif
#ifdef USE_BARO
BLACKBOX_PRINT_HEADER_LINE(PARAM_NAME_BARO_HARDWARE, "%d", barometerConfig()->baro_hardware);
BLACKBOX_PRINT_HEADER_LINE(PARAM_NAME_BARO_HARDWARE, "%d", barometerConfig()->baro_hardware);
#endif
BLACKBOX_PRINT_HEADER_LINE(PARAM_NAME_ALTITUDE_SOURCE, "%d", positionConfig()->altitude_source);
BLACKBOX_PRINT_HEADER_LINE(PARAM_NAME_ALTITUDE_PREFER_BARO, "%d", positionConfig()->altitude_prefer_baro);
BLACKBOX_PRINT_HEADER_LINE(PARAM_NAME_ALTITUDE_LPF, "%d", positionConfig()->altitude_lpf);
BLACKBOX_PRINT_HEADER_LINE(PARAM_NAME_ALTITUDE_D_LPF, "%d", positionConfig()->altitude_d_lpf);

BLACKBOX_PRINT_HEADER_LINE(PARAM_NAME_LANDING_ALTITUDE, "%d", autopilotConfig()->landing_altitude_m);
BLACKBOX_PRINT_HEADER_LINE(PARAM_NAME_HOVER_THROTTLE, "%d", autopilotConfig()->hover_throttle);
BLACKBOX_PRINT_HEADER_LINE(PARAM_NAME_THROTTLE_MIN, "%d", autopilotConfig()->throttle_min);
BLACKBOX_PRINT_HEADER_LINE(PARAM_NAME_THROTTLE_MAX, "%d", autopilotConfig()->throttle_max);
BLACKBOX_PRINT_HEADER_LINE(PARAM_NAME_ALTITUDE_P, "%d", autopilotConfig()->altitude_P);
BLACKBOX_PRINT_HEADER_LINE(PARAM_NAME_ALTITUDE_I, "%d", autopilotConfig()->altitude_I);;
BLACKBOX_PRINT_HEADER_LINE(PARAM_NAME_ALTITUDE_D, "%d", autopilotConfig()->altitude_D);;
BLACKBOX_PRINT_HEADER_LINE(PARAM_NAME_ALTITUDE_F, "%d", autopilotConfig()->altitude_F);
BLACKBOX_PRINT_HEADER_LINE(PARAM_NAME_LANDING_ALTITUDE, "%d", autopilotConfig()->landing_altitude_m);
BLACKBOX_PRINT_HEADER_LINE(PARAM_NAME_HOVER_THROTTLE, "%d", autopilotConfig()->hover_throttle);
BLACKBOX_PRINT_HEADER_LINE(PARAM_NAME_THROTTLE_MIN, "%d", autopilotConfig()->throttle_min);
BLACKBOX_PRINT_HEADER_LINE(PARAM_NAME_THROTTLE_MAX, "%d", autopilotConfig()->throttle_max);
BLACKBOX_PRINT_HEADER_LINE(PARAM_NAME_ALTITUDE_P, "%d", autopilotConfig()->altitude_P);
BLACKBOX_PRINT_HEADER_LINE(PARAM_NAME_ALTITUDE_I, "%d", autopilotConfig()->altitude_I);
BLACKBOX_PRINT_HEADER_LINE(PARAM_NAME_ALTITUDE_D, "%d", autopilotConfig()->altitude_D);
BLACKBOX_PRINT_HEADER_LINE(PARAM_NAME_ALTITUDE_F, "%d", autopilotConfig()->altitude_F);
BLACKBOX_PRINT_HEADER_LINE(PARAM_NAME_POSITION_P, "%d", autopilotConfig()->position_P);
BLACKBOX_PRINT_HEADER_LINE(PARAM_NAME_POSITION_I, "%d", autopilotConfig()->position_I);
BLACKBOX_PRINT_HEADER_LINE(PARAM_NAME_POSITION_D, "%d", autopilotConfig()->position_D);
BLACKBOX_PRINT_HEADER_LINE(PARAM_NAME_POSITION_A, "%d", autopilotConfig()->position_A);
BLACKBOX_PRINT_HEADER_LINE(PARAM_NAME_POSITION_CUTOFF, "%d", autopilotConfig()->position_cutoff);
BLACKBOX_PRINT_HEADER_LINE(PARAM_NAME_AP_MAX_ANGLE, "%d", autopilotConfig()->max_angle);

#ifdef USE_MAG
BLACKBOX_PRINT_HEADER_LINE(PARAM_NAME_MAG_HARDWARE, "%d", compassConfig()->mag_hardware);
#endif

BLACKBOX_PRINT_HEADER_LINE(PARAM_NAME_GYRO_CAL_ON_FIRST_ARM, "%d", armingConfig()->gyro_cal_on_first_arm);
BLACKBOX_PRINT_HEADER_LINE("airmode_activate_throttle", "%d", rxConfig()->airModeActivateThreshold);
BLACKBOX_PRINT_HEADER_LINE(PARAM_NAME_SERIAL_RX_PROVIDER, "%d", rxConfig()->serialrx_provider);
Expand Down Expand Up @@ -1749,7 +1757,13 @@ static bool blackboxWriteSysinfo(void)
#endif // USE_GPS

#ifdef USE_ALT_HOLD_MODE
BLACKBOX_PRINT_HEADER_LINE(PARAM_NAME_ALT_HOLD_TARGET_ADJUST_RATE, "%d", altholdConfig()->alt_hold_target_adjust_rate);
BLACKBOX_PRINT_HEADER_LINE(PARAM_NAME_ALT_HOLD_THROTTLE_RESPONSE, "%d", altHoldConfig()->alt_hold_adjust_rate);
BLACKBOX_PRINT_HEADER_LINE(PARAM_NAME_ALT_HOLD_DEADBAND, "%d", altHoldConfig()->alt_hold_deadband);
#endif

#ifdef USE_POS_HOLD_MODE
BLACKBOX_PRINT_HEADER_LINE(PARAM_NAME_POS_HOLD_WITHOUT_MAG, "%d", posHoldConfig()->pos_hold_without_mag);
BLACKBOX_PRINT_HEADER_LINE(PARAM_NAME_POS_HOLD_DEADBAND, "%d", posHoldConfig()->pos_hold_deadband);
#endif

#ifdef USE_WING
Expand Down
1 change: 1 addition & 0 deletions src/main/build/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,5 @@ const char * const debugModeNames[DEBUG_COUNT] = {
[DEBUG_S_TERM] = "S_TERM",
[DEBUG_SPA] = "SPA",
[DEBUG_TASK] = "TASK",
[DEBUG_AUTOPILOT_POSITION] = "AUTOPILOT_POSITION",
};
1 change: 1 addition & 0 deletions src/main/build/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ typedef enum {
DEBUG_S_TERM,
DEBUG_SPA,
DEBUG_TASK,
DEBUG_AUTOPILOT_POSITION,
DEBUG_COUNT
} debugType_e;

Expand Down
1 change: 0 additions & 1 deletion src/main/cli/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ bool cliMode = false;
#include "fc/rc_controls.h"
#include "fc/runtime_config.h"

#include "flight/autopilot.h"
#include "flight/failsafe.h"
#include "flight/imu.h"
#include "flight/mixer.h"
Expand Down
21 changes: 17 additions & 4 deletions src/main/cli/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@
#include "fc/rc_adjustments.h"
#include "fc/rc_controls.h"

#include "flight/alt_hold.h"
#include "flight/autopilot.h"
#include "flight/failsafe.h"
#include "flight/gps_rescue.h"
#include "flight/imu.h"
Expand All @@ -80,6 +78,8 @@
#include "osd/osd.h"

#include "pg/adc.h"
#include "pg/alt_hold.h"
#include "pg/autopilot.h"
#include "pg/beeper.h"
#include "pg/beeper_dev.h"
#include "pg/bus_i2c.h"
Expand All @@ -96,6 +96,7 @@
#include "pg/pg_ids.h"
#include "pg/pinio.h"
#include "pg/piniobox.h"
#include "pg/pos_hold.h"
#include "pg/rx.h"
#include "pg/rx_pwm.h"
#include "pg/rx_spi.h"
Expand Down Expand Up @@ -1104,7 +1105,13 @@ const clivalue_t valueTable[] = {
{ "yaw_control_reversed", VAR_INT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_RC_CONTROLS_CONFIG, offsetof(rcControlsConfig_t, yaw_control_reversed) },

#ifdef USE_ALT_HOLD_MODE
{ PARAM_NAME_ALT_HOLD_TARGET_ADJUST_RATE, VAR_UINT8 | MASTER_VALUE, .config.minmaxUnsigned = { 0, 200 }, PG_ALTHOLD_CONFIG, offsetof(altholdConfig_t, alt_hold_target_adjust_rate) },
{ PARAM_NAME_ALT_HOLD_THROTTLE_RESPONSE, VAR_UINT8 | MASTER_VALUE, .config.minmaxUnsigned = { 0, 200 }, PG_ALTHOLD_CONFIG, offsetof(altHoldConfig_t, alt_hold_adjust_rate) },
{ PARAM_NAME_ALT_HOLD_DEADBAND, VAR_UINT8 | MASTER_VALUE, .config.minmaxUnsigned = { 5, 50 }, PG_ALTHOLD_CONFIG, offsetof(altHoldConfig_t, alt_hold_deadband) },
#endif

#ifdef USE_POS_HOLD_MODE
{ PARAM_NAME_POS_HOLD_WITHOUT_MAG, VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_POSHOLD_CONFIG, offsetof(posHoldConfig_t, pos_hold_without_mag) },
{ PARAM_NAME_POS_HOLD_DEADBAND, VAR_UINT8 | MASTER_VALUE, .config.minmaxUnsigned = { 0, 50 }, PG_POSHOLD_CONFIG, offsetof(posHoldConfig_t, pos_hold_deadband) },
#endif

// PG_PID_CONFIG
Expand Down Expand Up @@ -1194,7 +1201,7 @@ const clivalue_t valueTable[] = {
{ PARAM_NAME_ANGLE_P_GAIN, VAR_UINT8 | PROFILE_VALUE, .config.minmaxUnsigned = { 0, 200 }, PG_PID_PROFILE, offsetof(pidProfile_t, pid[PID_LEVEL].P) },
{ PARAM_NAME_ANGLE_FEEDFORWARD, VAR_UINT8 | PROFILE_VALUE, .config.minmaxUnsigned = { 0, 200 }, PG_PID_PROFILE, offsetof(pidProfile_t, pid[PID_LEVEL].F) },
{ PARAM_NAME_ANGLE_FF_SMOOTHING_MS, VAR_UINT8 | PROFILE_VALUE, .config.minmaxUnsigned = { 10, 250 }, PG_PID_PROFILE, offsetof(pidProfile_t, angle_feedforward_smoothing_ms) },
{ PARAM_NAME_ANGLE_LIMIT, VAR_UINT8 | PROFILE_VALUE, .config.minmaxUnsigned = { 10, 85 }, PG_PID_PROFILE, offsetof(pidProfile_t, angle_limit) },
{ PARAM_NAME_ANGLE_LIMIT, VAR_UINT8 | PROFILE_VALUE, .config.minmaxUnsigned = { 10, 80 }, PG_PID_PROFILE, offsetof(pidProfile_t, angle_limit) },
{ PARAM_NAME_ANGLE_EARTH_REF, VAR_UINT8 | PROFILE_VALUE, .config.minmaxUnsigned = { 0, 100 }, PG_PID_PROFILE, offsetof(pidProfile_t, angle_earth_ref) },

{ PARAM_NAME_HORIZON_LEVEL_STRENGTH, VAR_UINT8 | PROFILE_VALUE, .config.minmaxUnsigned = { 0, 100 }, PG_PID_PROFILE, offsetof(pidProfile_t, pid[PID_LEVEL].I) },
Expand Down Expand Up @@ -1845,6 +1852,12 @@ const clivalue_t valueTable[] = {
{ PARAM_NAME_ALTITUDE_I, VAR_UINT8 | MASTER_VALUE, .config.minmaxUnsigned = { 0, 200 }, PG_AUTOPILOT, offsetof(autopilotConfig_t, altitude_I) },
{ PARAM_NAME_ALTITUDE_D, VAR_UINT8 | MASTER_VALUE, .config.minmaxUnsigned = { 0, 200 }, PG_AUTOPILOT, offsetof(autopilotConfig_t, altitude_D) },
{ PARAM_NAME_ALTITUDE_F, VAR_UINT8 | MASTER_VALUE, .config.minmaxUnsigned = { 0, 200 }, PG_AUTOPILOT, offsetof(autopilotConfig_t, altitude_F) },
{ PARAM_NAME_POSITION_P, VAR_UINT8 | MASTER_VALUE, .config.minmaxUnsigned = { 0, 200 }, PG_AUTOPILOT, offsetof(autopilotConfig_t, position_P) },
{ PARAM_NAME_POSITION_I, VAR_UINT8 | MASTER_VALUE, .config.minmaxUnsigned = { 0, 200 }, PG_AUTOPILOT, offsetof(autopilotConfig_t, position_I) },
{ PARAM_NAME_POSITION_D, VAR_UINT8 | MASTER_VALUE, .config.minmaxUnsigned = { 0, 200 }, PG_AUTOPILOT, offsetof(autopilotConfig_t, position_D) },
{ PARAM_NAME_POSITION_A, VAR_UINT8 | MASTER_VALUE, .config.minmaxUnsigned = { 0, 200 }, PG_AUTOPILOT, offsetof(autopilotConfig_t, position_A) },
{ PARAM_NAME_POSITION_CUTOFF, VAR_UINT8 | MASTER_VALUE, .config.minmaxUnsigned = { 10, 250 }, PG_AUTOPILOT, offsetof(autopilotConfig_t, position_cutoff) },
{ PARAM_NAME_AP_MAX_ANGLE, VAR_UINT8 | MASTER_VALUE, .config.minmaxUnsigned = { 10, 70 }, PG_AUTOPILOT, offsetof(autopilotConfig_t, max_angle) },

// PG_MODE_ACTIVATION_CONFIG
#if defined(USE_CUSTOM_BOX_NAMES)
Expand Down
2 changes: 0 additions & 2 deletions src/main/common/axis.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,4 @@ typedef enum {
AI_PITCH
} angle_index_t;

#define ANGLE_INDEX_COUNT 2

#define GET_DIRECTION(isReversed) ((isReversed) ? -1 : 1)
19 changes: 13 additions & 6 deletions src/main/common/maths.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,21 @@
#define sinPolyCoef7 -1.980661520e-4f // Double: -1.980661520135080504411629636078917643846e-4
#define sinPolyCoef9 2.600054768e-6f // Double: 2.600054767890361277123254766503271638682e-6
#endif

float sin_approx(float x)
{
int32_t xint = x;
if (xint < -32 || xint > 32) return 0.0f; // Stop here on error input (5 * 360 Deg)
while (x > M_PIf) x -= (2.0f * M_PIf); // always wrap input angle to -PI..PI
while (x < -M_PIf) x += (2.0f * M_PIf);
if (x > (0.5f * M_PIf)) x = (0.5f * M_PIf) - (x - (0.5f * M_PIf)); // We just pick -90..+90 Degree
else if (x < -(0.5f * M_PIf)) x = -(0.5f * M_PIf) - ((0.5f * M_PIf) + x);
// Wrap angle to 2π with range [-π π]
x = fmodf(x, 2.0f * M_PIf);
if (x <= -M_PIf) x += 2.0f * M_PIf;
if (x > M_PIf) x -= 2.0f * M_PIf;

// Use axis symmetry around x = ±π/2 for polynomial outside of range [-π/2 π/2]
if (x > M_PIf / 2) {
x = M_PIf - x; // Reflect
} else if (x < -M_PIf / 2) {
x = -M_PIf - x; // Reflect
}

float x2 = x * x;
return x + x * x2 * (sinPolyCoef3 + x2 * (sinPolyCoef5 + x2 * (sinPolyCoef7 + x2 * sinPolyCoef9)));
}
Expand Down
51 changes: 43 additions & 8 deletions src/main/fc/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
#include "flight/failsafe.h"
#include "flight/gps_rescue.h"
#include "flight/alt_hold.h"
#include "flight/pos_hold.h"

#if defined(USE_DYN_NOTCH_FILTER)
#include "flight/dyn_notch_filter.h"
Expand Down Expand Up @@ -243,6 +244,7 @@ static bool accNeedsCalibration(void)
if (isModeActivationConditionPresent(BOXANGLE) ||
isModeActivationConditionPresent(BOXHORIZON) ||
isModeActivationConditionPresent(BOXALTHOLD) ||
isModeActivationConditionPresent(BOXPOSHOLD) ||
isModeActivationConditionPresent(BOXGPSRESCUE) ||
isModeActivationConditionPresent(BOXCAMSTAB) ||
isModeActivationConditionPresent(BOXCALIB) ||
Expand Down Expand Up @@ -319,6 +321,18 @@ void updateArmingStatus(void)
unsetArmingDisabled(ARMING_DISABLED_BOXFAILSAFE);
}

if (IS_RC_MODE_ACTIVE(BOXALTHOLD)) {
setArmingDisabled(ARMING_DISABLED_ALTHOLD);
} else {
unsetArmingDisabled(ARMING_DISABLED_ALTHOLD);
}

if (IS_RC_MODE_ACTIVE(BOXPOSHOLD)) {
setArmingDisabled(ARMING_DISABLED_POSHOLD);
} else {
unsetArmingDisabled(ARMING_DISABLED_POSHOLD);
}

if (calculateThrottleStatus() != THROTTLE_LOW) {
setArmingDisabled(ARMING_DISABLED_THROTTLE);
} else {
Expand Down Expand Up @@ -611,7 +625,7 @@ void tryArm(void)
//beep to indicate arming
if (featureIsEnabled(FEATURE_GPS)) {
GPS_reset_home_position();

canUseGPSHeading = false; // block use of GPS Heading in position hold after each arm, until quad can set IMU to GPS COG
if (STATE(GPS_FIX) && gpsSol.numSat >= gpsRescueConfig()->minSats) {
beeper(BEEPER_ARMING_GPS_FIX);
} else {
Expand Down Expand Up @@ -770,7 +784,6 @@ uint8_t calculateThrottlePercentAbs(void)
}

static bool throttleRaised = false;

bool wasThrottleRaised(void)
{
return throttleRaised;
Expand Down Expand Up @@ -1007,6 +1020,9 @@ void processRxModes(timeUs_t currentTimeUs)
|| failsafeIsActive()
#ifdef USE_ALT_HOLD_MODE
|| FLIGHT_MODE(ALT_HOLD_MODE)
#endif
#ifdef USE_POS_HOLD_MODE
|| FLIGHT_MODE(POS_HOLD_MODE)
#endif
) && (sensors(SENSOR_ACC))) {
// bumpless transfer to Level mode
Expand All @@ -1020,17 +1036,17 @@ void processRxModes(timeUs_t currentTimeUs)
}

#ifdef USE_ALT_HOLD_MODE
// only if armed
// only if armed; can coexist with position hold
if (ARMING_FLAG(ARMED)
// and either the alt_hold switch is activated, or are in failsafe
&& (IS_RC_MODE_ACTIVE(BOXALTHOLD) || failsafeIsActive())
// but not in GPS_RESCUE_MODE, ie if failsafe is active, must be in Landing Mode
// and not in GPS_RESCUE_MODE, to give it priority over Altitude Hold
&& !FLIGHT_MODE(GPS_RESCUE_MODE)
// and either the alt_hold switch is activated, or are in failsafe landing mode
&& (IS_RC_MODE_ACTIVE(BOXALTHOLD) || failsafeIsActive())
// and we have Acc for self-levelling
&& sensors(SENSOR_ACC)
// and we have altitude data
&& isAltitudeAvailable()
// prevent activation until after takeoff
// but not until throttle is raised
&& wasThrottleRaised()) {
if (!FLIGHT_MODE(ALT_HOLD_MODE)) {
ENABLE_FLIGHT_MODE(ALT_HOLD_MODE);
Expand All @@ -1040,6 +1056,25 @@ void processRxModes(timeUs_t currentTimeUs)
}
#endif

#ifdef USE_POS_HOLD_MODE
// only if armed; can coexist with altitude hold
if (ARMING_FLAG(ARMED)
// and not in GPS_RESCUE_MODE, to give it priority over Position Hold
&& !FLIGHT_MODE(GPS_RESCUE_MODE)
// and either the alt_hold switch is activated, or are in failsafe landing mode
&& (IS_RC_MODE_ACTIVE(BOXPOSHOLD) || failsafeIsActive())
// and we have Acc for self-levelling
&& sensors(SENSOR_ACC)
// but not until throttle is raised
&& wasThrottleRaised()) {
if (!FLIGHT_MODE(POS_HOLD_MODE)) {
ENABLE_FLIGHT_MODE(POS_HOLD_MODE);
}
} else {
DISABLE_FLIGHT_MODE(POS_HOLD_MODE);
}
#endif

if (IS_RC_MODE_ACTIVE(BOXHORIZON) && canUseHorizonMode && sensors(SENSOR_ACC)) {
DISABLE_FLIGHT_MODE(ANGLE_MODE);
if (!FLIGHT_MODE(HORIZON_MODE)) {
Expand All @@ -1059,7 +1094,7 @@ void processRxModes(timeUs_t currentTimeUs)
}
#endif

if (FLIGHT_MODE(ANGLE_MODE | ALT_HOLD_MODE | HORIZON_MODE)) {
if (FLIGHT_MODE(ANGLE_MODE | ALT_HOLD_MODE | POS_HOLD_MODE | HORIZON_MODE)) {
LED1_ON;
// increase frequency of attitude task to reduce drift when in angle or horizon mode
rescheduleTask(TASK_ATTITUDE, TASK_PERIOD_HZ(acc.sampleRateHz / (float)imuConfig()->imu_process_denom));
Expand Down
5 changes: 5 additions & 0 deletions src/main/fc/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
#include "flight/pid.h"
#include "flight/pid_init.h"
#include "flight/position.h"
#include "flight/pos_hold.h"
#include "flight/servos.h"

#include "io/asyncfatfs/asyncfatfs.h"
Expand Down Expand Up @@ -1009,6 +1010,10 @@ void init(void)
altHoldInit();
#endif

#ifdef USE_POS_HOLD_MODE
posHoldInit();
#endif

#ifdef USE_GPS_RESCUE
if (featureIsEnabled(FEATURE_GPS)) {
gpsRescueInit();
Expand Down
16 changes: 14 additions & 2 deletions src/main/fc/parameter_names.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,12 @@
#define PARAM_NAME_ALTITUDE_I "autopilot_altitude_I"
#define PARAM_NAME_ALTITUDE_D "autopilot_altitude_D"
#define PARAM_NAME_ALTITUDE_F "autopilot_altitude_F"
#define PARAM_NAME_POSITION_P "autopilot_position_P"
#define PARAM_NAME_POSITION_I "autopilot_position_I"
#define PARAM_NAME_POSITION_D "autopilot_position_D"
#define PARAM_NAME_POSITION_A "autopilot_position_A"
#define PARAM_NAME_POSITION_CUTOFF "autopilot_position_cutoff"
#define PARAM_NAME_AP_MAX_ANGLE "autopilot_max_angle"

#define PARAM_NAME_ANGLE_FEEDFORWARD "angle_feedforward"
#define PARAM_NAME_ANGLE_FF_SMOOTHING_MS "angle_feedforward_smoothing_ms"
Expand Down Expand Up @@ -241,8 +247,14 @@
#endif // USE_GPS

#ifdef USE_ALT_HOLD_MODE
#define PARAM_NAME_ALT_HOLD_TARGET_ADJUST_RATE "alt_hold_target_adjust_rate"
#endif // USE_ALT_HOLD_MODE
#define PARAM_NAME_ALT_HOLD_DEADBAND "alt_hold_deadband"
#define PARAM_NAME_ALT_HOLD_THROTTLE_RESPONSE "alt_hold_throttle_response"
#endif

#ifdef USE_POS_HOLD_MODE
#define PARAM_NAME_POS_HOLD_WITHOUT_MAG "pos_hold_without_mag"
#define PARAM_NAME_POS_HOLD_DEADBAND "pos_hold_deadband"
#endif

#define PARAM_NAME_IMU_DCM_KP "imu_dcm_kp"
#define PARAM_NAME_IMU_DCM_KI "imu_dcm_ki"
Expand Down
Loading