diff --git a/src/main/fc/fc_core.c b/src/main/fc/fc_core.c index 5f02e2af49..13e13e63fc 100644 --- a/src/main/fc/fc_core.c +++ b/src/main/fc/fc_core.c @@ -617,7 +617,7 @@ static void subTaskMainSubprocesses(timeUs_t currentTimeUs) } #endif -#if defined(USE_BARO) || defined(USE_SONAR) +#if defined(USE_ALT_HOLD) // updateRcCommands sets rcCommand, which is needed by updateAltHoldState and updateSonarAltHoldState updateRcCommands(); if (sensors(SENSOR_BARO) || sensors(SENSOR_SONAR)) { diff --git a/src/main/fc/fc_tasks.c b/src/main/fc/fc_tasks.c index c576cfc00e..ecc585a160 100644 --- a/src/main/fc/fc_tasks.c +++ b/src/main/fc/fc_tasks.c @@ -140,12 +140,13 @@ static void taskUpdateRxMain(timeUs_t currentTimeUs) processRx(currentTimeUs); isRXDataNew = true; -#if !defined(USE_BARO) && !defined(USE_SONAR) +#if !defined(USE_ALT_HOLD) // updateRcCommands sets rcCommand, which is needed by updateAltHoldState and updateSonarAltHoldState updateRcCommands(); #endif updateArmingStatus(); +#ifdef USE_ALT_HOLD #ifdef USE_BARO if (sensors(SENSOR_BARO)) { updateAltHoldState(); @@ -157,6 +158,7 @@ static void taskUpdateRxMain(timeUs_t currentTimeUs) updateSonarAltHoldState(); } #endif +#endif // USE_ALT_HOLD } #endif @@ -183,7 +185,7 @@ static void taskUpdateBaro(timeUs_t currentTimeUs) } #endif -#if defined(USE_BARO) || defined(USE_SONAR) +#if defined(USE_ALT_HOLD) static void taskCalculateAltitude(timeUs_t currentTimeUs) { if (false @@ -196,7 +198,7 @@ static void taskCalculateAltitude(timeUs_t currentTimeUs) ) { calculateEstimatedAltitude(currentTimeUs); }} -#endif +#endif // USE_ALT_HOLD #ifdef USE_TELEMETRY static void taskTelemetry(timeUs_t currentTimeUs) @@ -295,7 +297,7 @@ void fcTasksInit(void) #ifdef USE_SONAR setTaskEnabled(TASK_SONAR, sensors(SENSOR_SONAR)); #endif -#if defined(USE_BARO) || defined(USE_SONAR) +#ifdef USE_ALT_HOLD setTaskEnabled(TASK_ALTITUDE, sensors(SENSOR_BARO) || sensors(SENSOR_SONAR)); #endif #ifdef USE_DASHBOARD @@ -501,7 +503,7 @@ cfTask_t cfTasks[TASK_COUNT] = { }, #endif -#if defined(USE_BARO) || defined(USE_SONAR) +#if defined(USE_ALT_HOLD) [TASK_ALTITUDE] = { .taskName = "ALTITUDE", .taskFunc = taskCalculateAltitude, diff --git a/src/main/flight/altitude.c b/src/main/flight/altitude.c index 2ddb331441..c8b55db7cd 100644 --- a/src/main/flight/altitude.c +++ b/src/main/flight/altitude.c @@ -52,7 +52,7 @@ static int32_t estimatedVario = 0; // variometer in cm/s static int32_t estimatedAltitude = 0; // in cm -#if defined(USE_BARO) || defined(USE_SONAR) +#if defined(USE_ALT_HOLD) enum { DEBUG_ALTITUDE_ACC, @@ -294,7 +294,7 @@ void calculateEstimatedAltitude(timeUs_t currentTimeUs) altHoldThrottleAdjustment = calculateAltHoldThrottleAdjustment(vel_tmp, accZ_tmp, accZ_old); accZ_old = accZ_tmp; } -#endif // defined(USE_BARO) || defined(USE_SONAR) +#endif // USE_ALT_HOLD int32_t getEstimatedAltitude(void) { diff --git a/src/main/interface/settings.c b/src/main/interface/settings.c index ce6bc2c456..4d306c5bbb 100644 --- a/src/main/interface/settings.c +++ b/src/main/interface/settings.c @@ -616,18 +616,19 @@ const clivalue_t valueTable[] = { { "i_yaw", VAR_UINT8 | PROFILE_VALUE, .config.minmax = { 0, 200 }, PG_PID_PROFILE, offsetof(pidProfile_t, pid[PID_YAW].I) }, { "d_yaw", VAR_UINT8 | PROFILE_VALUE, .config.minmax = { 0, 200 }, PG_PID_PROFILE, offsetof(pidProfile_t, pid[PID_YAW].D) }, +#ifdef USE_ALT_HOLD { "p_alt", VAR_UINT8 | PROFILE_VALUE, .config.minmax = { 0, 200 }, PG_PID_PROFILE, offsetof(pidProfile_t, pid[PID_ALT].P) }, { "i_alt", VAR_UINT8 | PROFILE_VALUE, .config.minmax = { 0, 200 }, PG_PID_PROFILE, offsetof(pidProfile_t, pid[PID_ALT].I) }, { "d_alt", VAR_UINT8 | PROFILE_VALUE, .config.minmax = { 0, 200 }, PG_PID_PROFILE, offsetof(pidProfile_t, pid[PID_ALT].D) }, + { "p_vel", VAR_UINT8 | PROFILE_VALUE, .config.minmax = { 0, 200 }, PG_PID_PROFILE, offsetof(pidProfile_t, pid[PID_VEL].P) }, + { "i_vel", VAR_UINT8 | PROFILE_VALUE, .config.minmax = { 0, 200 }, PG_PID_PROFILE, offsetof(pidProfile_t, pid[PID_VEL].I) }, + { "d_vel", VAR_UINT8 | PROFILE_VALUE, .config.minmax = { 0, 200 }, PG_PID_PROFILE, offsetof(pidProfile_t, pid[PID_VEL].D) }, +#endif { "p_level", VAR_UINT8 | PROFILE_VALUE, .config.minmax = { 0, 200 }, PG_PID_PROFILE, offsetof(pidProfile_t, pid[PID_LEVEL].P) }, { "i_level", VAR_UINT8 | PROFILE_VALUE, .config.minmax = { 0, 200 }, PG_PID_PROFILE, offsetof(pidProfile_t, pid[PID_LEVEL].I) }, { "d_level", VAR_UINT8 | PROFILE_VALUE, .config.minmax = { 0, 200 }, PG_PID_PROFILE, offsetof(pidProfile_t, pid[PID_LEVEL].D) }, - { "p_vel", VAR_UINT8 | PROFILE_VALUE, .config.minmax = { 0, 200 }, PG_PID_PROFILE, offsetof(pidProfile_t, pid[PID_VEL].P) }, - { "i_vel", VAR_UINT8 | PROFILE_VALUE, .config.minmax = { 0, 200 }, PG_PID_PROFILE, offsetof(pidProfile_t, pid[PID_VEL].I) }, - { "d_vel", VAR_UINT8 | PROFILE_VALUE, .config.minmax = { 0, 200 }, PG_PID_PROFILE, offsetof(pidProfile_t, pid[PID_VEL].D) }, - { "level_limit", VAR_UINT8 | PROFILE_VALUE, .config.minmax = { 10, 90 }, PG_PID_PROFILE, offsetof(pidProfile_t, levelAngleLimit) }, { "horizon_tilt_effect", VAR_UINT8 | PROFILE_VALUE, .config.minmax = { 0, 250 }, PG_PID_PROFILE, offsetof(pidProfile_t, horizon_tilt_effect) }, diff --git a/src/main/target/common_fc_post.h b/src/main/target/common_fc_post.h index bf20956a17..ac7cb26ebb 100644 --- a/src/main/target/common_fc_post.h +++ b/src/main/target/common_fc_post.h @@ -61,6 +61,11 @@ #endif #endif +// undefine USE_ALT_HOLD if there is no baro or sonar to support it +#if defined(USE_ALT_HOLD) && !defined(USE_BARO) && !defined(USE_SONAR) +#undef USE_ALT_HOLD +#endif + /* If either VTX_CONTROL or VTX_COMMON is undefined then remove common code and device drivers */ #if !defined(VTX_COMMON) || !defined(VTX_CONTROL) #undef VTX_COMMON diff --git a/src/main/target/common_fc_pre.h b/src/main/target/common_fc_pre.h index 8ef1ec2778..60327c1042 100644 --- a/src/main/target/common_fc_pre.h +++ b/src/main/target/common_fc_pre.h @@ -148,6 +148,7 @@ #define USE_GPS_UBLOX #define USE_GPS_NMEA #define USE_NAV +#define USE_ALT_HOLD #define USE_UNCOMMON_MIXERS #define USE_OSD_ADJUSTMENTS #endif