mirror of
https://github.com/iNavFlight/inav.git
synced 2025-07-25 01:05:21 +03:00
Refactor
This commit is contained in:
parent
ff46510b75
commit
0a4498dacc
3 changed files with 21 additions and 10 deletions
|
@ -80,5 +80,6 @@ typedef enum {
|
||||||
DEBUG_SPM_VARIO, // Smartport master variometer
|
DEBUG_SPM_VARIO, // Smartport master variometer
|
||||||
DEBUG_PCF8574,
|
DEBUG_PCF8574,
|
||||||
DEBUG_DYNAMIC_GYRO_LPF,
|
DEBUG_DYNAMIC_GYRO_LPF,
|
||||||
|
DEBUG_AUTOLEVEL,
|
||||||
DEBUG_COUNT
|
DEBUG_COUNT
|
||||||
} debugType_e;
|
} debugType_e;
|
||||||
|
|
|
@ -1873,7 +1873,7 @@ groups:
|
||||||
min: 1
|
min: 1
|
||||||
max: 16000
|
max: 16000
|
||||||
- name: fw_level_pitch_trim
|
- name: fw_level_pitch_trim
|
||||||
description: "Pitch trim for self-leveling flight modes. In degrees"
|
description: "Pitch trim for self-leveling flight modes. In degrees. +5 means nose should be raised 5 deg from level"
|
||||||
default_value: "0"
|
default_value: "0"
|
||||||
field: fixedWingLevelTrim
|
field: fixedWingLevelTrim
|
||||||
min: -10
|
min: -10
|
||||||
|
|
|
@ -537,16 +537,26 @@ static void pidLevel(pidState_t *pidState, flight_dynamics_index_t axis, float h
|
||||||
|
|
||||||
// Automatically pitch down if the throttle is manually controlled and reduced bellow cruise throttle
|
// Automatically pitch down if the throttle is manually controlled and reduced bellow cruise throttle
|
||||||
if ((axis == FD_PITCH) && STATE(AIRPLANE) && FLIGHT_MODE(ANGLE_MODE) && !navigationIsControllingThrottle()) {
|
if ((axis == FD_PITCH) && STATE(AIRPLANE) && 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);
|
angleTarget += scaleRange(MAX(0, navConfig()->fw.cruise_throttle - rcCommand[THROTTLE]), 0, navConfig()->fw.cruise_throttle - PWM_RANGE_MIN, 0, mixerConfig()->fwMinThrottleDownPitchAngle);
|
||||||
|
}
|
||||||
|
|
||||||
DEBUG_SET(DEBUG_ALWAYS, 0, angleTarget * 10);
|
//PITCH trim applied by a AutoLevel flight mode and manual pitch trimming
|
||||||
DEBUG_SET(DEBUG_ALWAYS, 1, fixedWingLevelTrim * 10);
|
if (axis == FD_PITCH && STATE(AIRPLANE)) {
|
||||||
DEBUG_SET(DEBUG_ALWAYS, 2, getEstimatedActualVelocity(Z));
|
DEBUG_SET(DEBUG_AUTOLEVEL, 0, angleTarget * 10);
|
||||||
|
DEBUG_SET(DEBUG_AUTOLEVEL, 1, fixedWingLevelTrim * 10);
|
||||||
|
DEBUG_SET(DEBUG_AUTOLEVEL, 2, getEstimatedActualVelocity(Z));
|
||||||
|
|
||||||
//Apply level trim
|
/*
|
||||||
angleTarget -= fixedWingLevelTrim;
|
* fixedWingLevelTrim has opposite sign to rcCommand.
|
||||||
DEBUG_SET(DEBUG_ALWAYS, 3, angleTarget * 10);
|
* Positive rcCommand means nose should point downwards
|
||||||
|
* Negative rcCommand mean nose should point upwards
|
||||||
|
* This is counter intuitive and a natural way suggests that + should mean UP
|
||||||
|
* This is why fixedWingLevelTrim has opposite sign to rcCommand
|
||||||
|
* Positive fixedWingLevelTrim means nose should point upwards
|
||||||
|
* Negative fixedWingLevelTrim means nose should point downwards
|
||||||
|
*/
|
||||||
|
angleTarget -= fixedWingLevelTrim;
|
||||||
|
DEBUG_SET(DEBUG_AUTOLEVEL, 3, angleTarget * 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
const float angleErrorDeg = DECIDEGREES_TO_DEGREES(angleTarget - attitude.raw[axis]);
|
const float angleErrorDeg = DECIDEGREES_TO_DEGREES(angleTarget - attitude.raw[axis]);
|
||||||
|
@ -1170,6 +1180,6 @@ void updateFixedWingLevelTrim(timeUs_t currentTimeUs)
|
||||||
1.0f
|
1.0f
|
||||||
);
|
);
|
||||||
|
|
||||||
DEBUG_SET(DEBUG_ALWAYS, 4, output / 100);
|
DEBUG_SET(DEBUG_AUTOLEVEL, 4, output / 100);
|
||||||
|
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue