Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically pitch down in angle mode when throttle is bellow cruise throttle #3290

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions src/main/fc/settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,10 @@ groups:
field: appliedMixerPreset
min: -1
max: INT16_MAX
- name: fw_min_throttle_down_pitch
field: fwMinThrottleDownPitchAngle
min: 0
max: 450

- name: PG_MOTOR_3D_CONFIG
type: flight3DConfig_t
Expand Down
3 changes: 2 additions & 1 deletion src/main/flight/mixer.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ PG_RESET_TEMPLATE(mixerConfig_t, mixerConfig,
.yaw_jump_prevention_limit = 200,
.platformType = PLATFORM_MULTIROTOR,
.hasFlaps = false,
.appliedMixerPreset = -1 //This flag is not available in CLI and used by Configurator only
.appliedMixerPreset = -1, //This flag is not available in CLI and used by Configurator only
.fwMinThrottleDownPitchAngle = 0
);

#ifdef BRUSHED_MOTORS
Expand Down
3 changes: 2 additions & 1 deletion src/main/flight/mixer.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ typedef struct mixerConfig_s {
uint8_t platformType;
bool hasFlaps;
int16_t appliedMixerPreset;
uint16_t fwMinThrottleDownPitchAngle;
} mixerConfig_t;

PG_DECLARE(mixerConfig_t, mixerConfig);
Expand Down Expand Up @@ -97,4 +98,4 @@ void mixTable(void);
void writeMotors(void);
void processServoAutotrim(void);
void stopMotors(void);
void stopPwmAllMotors(void);
void stopPwmAllMotors(void);
7 changes: 6 additions & 1 deletion src/main/flight/pid.c
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,12 @@ static float calcHorizonRateMagnitude(void)
static void pidLevel(pidState_t *pidState, flight_dynamics_index_t axis, float horizonRateMagnitude)
{
// This is ROLL/PITCH, run ANGLE/HORIZON controllers
const float angleTarget = pidRcCommandToAngle(rcCommand[axis], pidProfile()->max_angle_inclination[axis]);
float angleTarget = pidRcCommandToAngle(rcCommand[axis], pidProfile()->max_angle_inclination[axis]);

// Automatically pitch down if the throttle is manually controlled and reduced bellow cruise throttle
if ((axis == FD_PITCH) && STATE(FIXED_WING) && FLIGHT_MODE(ANGLE_MODE) && !navigationIsControllingThrottle())
angleTarget += scaleRange(MAX(0, navConfig()->fw.cruise_throttle - rcCommand[THROTTLE]), 0, navConfig()->fw.cruise_throttle - PWM_RANGE_MIN, 0, mixerConfig()->fwMinThrottleDownPitchAngle);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should start thinking about unifying configuration for navigation and other things into "platform configuration". We can have separate airplaneConfig and rotorcraftConfig plus unified platformConfig to keep common values. These structures will hold platform capabilities like max inclination, cruise throttle, hover throttle, reference airspeed etc.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's definitely out of scope of current PR, but we should really look into it.


const float angleErrorDeg = DECIDEGREES_TO_DEGREES(angleTarget - attitude.raw[axis]);

float angleRateTarget = constrainf(angleErrorDeg * (pidBank()->pid[PID_LEVEL].P / FP_PID_LEVEL_P_MULTIPLIER), -currentControlRateProfile->stabilized.rates[axis] * 10.0f, currentControlRateProfile->stabilized.rates[axis] * 10.0f);
Expand Down