Add PID adjustment from AUX transmitter channel (#5584)
* Scale PIDs using aux channels * Add control via variables and documentation * Use USE_TXPID * Removed OWNER_TXPID * Use PWM_RANGE_MIDDLE * Fix typos * Move Tx PID arrays into pidProfile_t * Move macro to pidUpdateRate function * Enable TXPID on REVONANO * Add support for direct setting of adjustments from aux channel * Change variable name from adjustmentScale to adjustmentScale to avoid confusion * Update documentation * Change variable name from adjustmentScale to adjustmentScale to avoid confusion * Only adjust settings if adjustment channel has changed value * Fix formatting * Use pidAudioModes_e type in ADJUSTMENT_PID_AUDIO setting. Only allow absolute override of settings of ADJUSTMENT_MODE_STEP. * Add example 6 * Fix checking of adjustment mode * Fix USE_PID_AUDIO code. Broke SPRACINGF7DUAL.
This commit is contained in:
parent
a1d10b49f4
commit
6f088d0fd2
|
@ -17,9 +17,27 @@ Changing settings during flight can make your aircraft unstable and crash if you
|
|||
|
||||
## Overview
|
||||
|
||||
There are two modes of operation. The first supports adjusting settings by incrementing/decrementing them through use of an aux channel, typically a three position switch, where the middle position makes no change, and the other positions either increment or decrement the selected setting.
|
||||
|
||||
The other mode is Absolute mode where a pot (knob/slider) may be directly mapped and changes the selected setting to a value based on a center value, coresponding to mid-postion on the switch and a range of ± adjustment at the min/max positions of the pot.
|
||||
|
||||
Both modes utilise two channels to make an adjustment.
|
||||
|
||||
| Channel | Use |
|
||||
| ------- | --- |
|
||||
| Range | This channel is used to enable an adjustment. When the channel is set to fall withing the specified range, then the corresponding adjustment is enabled. This is similar to mode setting where a given mode is enabled when a channel is within a lower and upper range. |
|
||||
| Adjustment | This channel is used to control the change to the specified setting|
|
||||
|
||||
Settings are not saved automatically, connect a GUI, refresh and save or save using stick position when disarmed.
|
||||
Powering off without saving will discard the adjustments.
|
||||
|
||||
Settings can be saved when disarmed using stick positions: Throttle Low, Yaw Left, Pitch Low, Roll Right.
|
||||
|
||||
### Increment/Decrement mode
|
||||
|
||||
Up to 4 RX channels can be used to make different adjustments at the same time.
|
||||
|
||||
The adjustment a channel makes can be controlled by another channel.
|
||||
The adjustment the Adjustment Channel makes is controlled by the Range Channel.
|
||||
|
||||
The following adjustments can be made, in flight, as well as on the ground.
|
||||
|
||||
|
@ -37,21 +55,21 @@ A single 2/3/4/5/6/x position switch can be used to make one 3 position switch a
|
|||
|
||||
Any combination of switches and pots can be used. So you could have 6 POS switch.
|
||||
|
||||
Settings are not saved automatically, connect a GUI, refresh and save or save using stick position when disarmed.
|
||||
Powering off without saving will discard the adjustments.
|
||||
#### Adjustment switches
|
||||
|
||||
Settings can be saved when disarmed using stick positions: Throttle Low, Yaw Left, Pitch Low, Roll Right.
|
||||
|
||||
## Adjustment switches
|
||||
|
||||
The switch can be a ON-OFF-ON, POT or momentary ON-OFF-ON switch. The latter is recommended.
|
||||
The Adjustment switch is associated with the Adjustment Channel. The switch can be a ON-OFF-ON, POT or momentary ON-OFF-ON switch. The latter is recommended.
|
||||
|
||||
When the switch is returned to the center position the value will not be increased/decreased.
|
||||
|
||||
Each time you can press the switch high/low and then return it to the middle the value will change at least once, you do not have to wait before pressing the switch again if you want to increase/decrease at a faster rate. While the adjustment switch held is high/low, the adjustment function applies and increases/decreases the value being adjusted twice a second and the flight controller will beep shorter/longer, respectively. The system works similar to how a keyboard repeat delay works.
|
||||
|
||||
Hint: With OpenTX transmitters you can combine two momentary OFF-ON switches to control a single channel. You could make it so that a momentary switch on the left of your transmitter decreases the value and a momentary switch on the right increases the value. Experiment with your mixer!
|
||||
|
||||
|
||||
### Absolute mode
|
||||
|
||||
The adjustment is made where the Adjustment Channel is an Aux channel connected to a pot (knob/slider). This provides an easier approach than using the Increment/Decrement mode as it is easier to keep track of the setting.
|
||||
|
||||
Note that if the same pot is used as the Adjustment Channel to make multiple adjustments, there is a risk of a jump in values of the second setting when switching from the first if the pot is not centered. To avoid this it is recommended that if adjusting two different settings using the same pot, a three position switch be used for the Range Channel, with neither setting associated with the middle position.
|
||||
|
||||
## Configuration
|
||||
|
||||
|
@ -79,6 +97,8 @@ Configure a range using:
|
|||
| Range End | 900 - 2100 | End of range |
|
||||
| Adjustment function | 0 - 11 | See Adjustment function table |
|
||||
| Adjustment channel | 0 based index, AUX1 = 0, AUX2 = 1 | The channel that is controlled by a 3 Position switch/Pot |
|
||||
| Center Value | If this is non-zero then Absolute Mode is used for this range otherwise Increment/Decrement Mode is used. In Absolute Mode this value is the value which will be assigned to the setting when the Adjustment Channel is set to mid-position. |
|
||||
| Scale Value | This specifies the amount that will be subtracted/added to the center value when the Adjustment Channel is at min/max respectively. |
|
||||
|
||||
Range Start/End values should match the values sent by your receiver.
|
||||
|
||||
|
@ -124,21 +144,22 @@ this reason ensure that you define enough ranges to cover the range channel's us
|
|||
### Example 1 - 3 Position switch used to adjust pitch/roll rate
|
||||
|
||||
```
|
||||
adjrange 0 0 3 900 2100 4 3
|
||||
adjrange 0 0 3 900 2100 4 3 0 0
|
||||
```
|
||||
|
||||
explained:
|
||||
|
||||
* configure adjrange 0 to use adjustment slot 1 (0) so that when aux4
|
||||
(3) in the range 900-2100 then use adjustment 4 (pitch/roll rate) when aux 4 (3)
|
||||
is in the appropriate position.
|
||||
is in the appropriate position.
|
||||
* note that Center/Scale values are both zero, so this range will use increment/decrement mode.
|
||||
|
||||
|
||||
### Example 2 - 2 Position switch used to enable adjustment of RC rate via a 3 position switch
|
||||
|
||||
```
|
||||
adjrange 1 1 0 900 1700 0 2
|
||||
adjrange 2 1 0 1700 2100 1 2
|
||||
adjrange 1 1 0 900 1700 0 2 0 0
|
||||
adjrange 2 1 0 1700 2100 1 2 0 0
|
||||
```
|
||||
explained:
|
||||
|
||||
|
@ -148,6 +169,7 @@ position.
|
|||
* configure adjrange 2 to use adjustment slot 2 (1) so that when aux1
|
||||
(0) in the range 1700-2100 then use adjustment rc rate (1) when aux 3
|
||||
(2) is in the appropriate position.
|
||||
* note that Center/Scale values are both zero, so this range will use increment/decrement mode.
|
||||
|
||||
Without the entire range of aux1 being defined there is nothing that
|
||||
would stop aux 3 adjusting the pitch/roll rate once aux 1 wasn't in the higher
|
||||
|
@ -156,12 +178,12 @@ range.
|
|||
### Example 3 - 6 Position switch used to select PID tuning adjustments via a 3 position switch
|
||||
|
||||
```
|
||||
adjrange 3 2 1 900 1150 6 3
|
||||
adjrange 4 2 1 1150 1300 7 3
|
||||
adjrange 5 2 1 1300 1500 8 3
|
||||
adjrange 6 2 1 1500 1700 9 3
|
||||
adjrange 7 2 1 1700 1850 10 3
|
||||
adjrange 8 2 1 1850 2100 11 3
|
||||
adjrange 3 2 1 900 1150 6 3 0 0
|
||||
adjrange 4 2 1 1150 1300 7 3 0 0
|
||||
adjrange 5 2 1 1300 1500 8 3 0 0
|
||||
adjrange 6 2 1 1500 1700 9 3 0 0
|
||||
adjrange 7 2 1 1700 1850 10 3 0 0
|
||||
adjrange 8 2 1 1850 2100 11 3 0 0
|
||||
```
|
||||
|
||||
explained:
|
||||
|
@ -184,24 +206,58 @@ explained:
|
|||
* configure adjrange 8 to use adjustment slot 3 (2) so that when aux2
|
||||
(1) in the range 1850-2100 then use adjustment Yaw D (11) when aux 4
|
||||
(3) is in the appropriate position.
|
||||
* note that Center/Scale values are both zero, so this range will use increment/decrement mode.
|
||||
|
||||
### Example 4 - Use a single 3 position switch to change between 3 different rate profiles
|
||||
|
||||
adjrange 11 3 3 900 2100 12 3
|
||||
```
|
||||
adjrange 11 3 3 900 2100 12 3 0 0
|
||||
```
|
||||
|
||||
explained:
|
||||
|
||||
* configure adjrange 11 to use adjustment slot 4 (3) so that when aux4
|
||||
(3) in the range 900-2100 then use adjustment Rate Profile (12) when aux 4
|
||||
(3) is in the appropriate position.
|
||||
* note that Center/Scale values are both zero, so this range will use increment/decrement mode.
|
||||
|
||||
When the switch is low, rate profile 0 is selcted.
|
||||
When the switch is medium, rate profile 1 is selcted.
|
||||
When the switch is high, rate profile 2 is selcted.
|
||||
|
||||
### Example 5 - Use a single switch to enable absolute setting of Roll/Pitch P terms from two pots
|
||||
|
||||
```
|
||||
adjrange 0 0 4 1450 1550 18 0 40 10
|
||||
adjrange 1 0 4 1450 1550 15 1 58 20
|
||||
```
|
||||
|
||||
explained:
|
||||
|
||||
* note that Center value is non-zero, so this range will use absolute mode.
|
||||
* configure adjrange 0 so that when aux5 (3) in the range 1450-1550 then use aux 1 (0) to adjust Roll P Adjustment (18) such that the value will be 40 with the pot centered and 30/50 at min/max.
|
||||
* configure adjrange 1 so that when aux5 (3) in the range 1450-1550 then use aux 2 (0) to adjust Pitch P Adjustment (15) such that the value will be 58 with the pot centered and 38/78 at min/max.
|
||||
|
||||
### Example 6 - Use a single switch to enable absolute setting of Roll/Pitch P/I/D terms from three pots, selected using a single switch
|
||||
|
||||
```
|
||||
adjrange 0 0 4 950 1050 18 0 40 20
|
||||
adjrange 1 0 4 950 1050 19 1 107 53
|
||||
adjrange 2 0 4 950 1050 20 2 76 38
|
||||
adjrange 3 0 4 1950 2050 15 0 63 16
|
||||
adjrange 4 0 4 1950 2050 16 1 138 69
|
||||
adjrange 5 0 4 1950 2050 17 2 66 33
|
||||
```
|
||||
explained:
|
||||
|
||||
* note that Center value is non-zero, so this range will use absolute mode.
|
||||
|
||||
This assigns pots aux 1, aux 2, and aux 3 respectively to control P, I and D settings with the center values at default at set to provide a range of adjustment of +/- 50%. When the aux 5 switch is in one end position then roll P/I/D will be adjusted and when the aux 5 switch is in the other end position, pitch P/I/D will be adjusted. In the aux 5 switch middle position nether will be adjusted. Thus one could center the pots, select roll on aux 5 and then adjust the P/I/D values in flight. Then land, move the aux 5 switch to center, center the pots, select pitch on the switch and then again adjust P/I/D in flight.
|
||||
|
||||
### Configurator examples
|
||||
|
||||
Note that the configurator does not currently support the Center/Scale values, however it may still be used to setup the ranges and then the CLI may be used to set the Center/Scale values.
|
||||
|
||||
The following 5 images show valid configurations. In all cales the enture usable range for the Range Channel is used.
|
||||
|
||||

|
||||
|
|
|
@ -415,21 +415,168 @@ static int applyStepAdjustment(controlRateConfig_t *controlRateConfig, uint8_t a
|
|||
return newValue;
|
||||
}
|
||||
|
||||
static uint8_t applySelectAdjustment(uint8_t adjustmentFunction, uint8_t position)
|
||||
static int applyAbsoluteAdjustment(controlRateConfig_t *controlRateConfig, adjustmentFunction_e adjustmentFunction, int value)
|
||||
{
|
||||
int newValue;
|
||||
|
||||
if ( !controlRateConfig || !pidProfile) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch (adjustmentFunction) {
|
||||
case ADJUSTMENT_RC_RATE:
|
||||
case ADJUSTMENT_ROLL_RC_RATE:
|
||||
newValue = constrain(value, 0, CONTROL_RATE_CONFIG_RC_RATES_MAX);
|
||||
controlRateConfig->rcRates[FD_ROLL] = newValue;
|
||||
blackboxLogInflightAdjustmentEvent(ADJUSTMENT_ROLL_RC_RATE, newValue);
|
||||
if (adjustmentFunction == ADJUSTMENT_ROLL_RC_RATE) {
|
||||
break;
|
||||
}
|
||||
// fall through for combined ADJUSTMENT_RC_EXPO
|
||||
FALLTHROUGH;
|
||||
case ADJUSTMENT_PITCH_RC_RATE:
|
||||
newValue = constrain(value, 0, CONTROL_RATE_CONFIG_RC_RATES_MAX);
|
||||
controlRateConfig->rcRates[FD_PITCH] = newValue;
|
||||
blackboxLogInflightAdjustmentEvent(ADJUSTMENT_PITCH_RC_RATE, newValue);
|
||||
break;
|
||||
case ADJUSTMENT_RC_EXPO:
|
||||
case ADJUSTMENT_ROLL_RC_EXPO:
|
||||
newValue = constrain(value, 0, CONTROL_RATE_CONFIG_RC_EXPO_MAX);
|
||||
controlRateConfig->rcExpo[FD_ROLL] = newValue;
|
||||
blackboxLogInflightAdjustmentEvent(ADJUSTMENT_ROLL_RC_EXPO, newValue);
|
||||
if (adjustmentFunction == ADJUSTMENT_ROLL_RC_EXPO) {
|
||||
break;
|
||||
}
|
||||
// fall through for combined ADJUSTMENT_RC_EXPO
|
||||
FALLTHROUGH;
|
||||
case ADJUSTMENT_PITCH_RC_EXPO:
|
||||
newValue = constrain(value, 0, CONTROL_RATE_CONFIG_RC_EXPO_MAX);
|
||||
controlRateConfig->rcExpo[FD_PITCH] = newValue;
|
||||
blackboxLogInflightAdjustmentEvent(ADJUSTMENT_PITCH_RC_EXPO, newValue);
|
||||
break;
|
||||
case ADJUSTMENT_THROTTLE_EXPO:
|
||||
newValue = constrain(value, 0, 100); // FIXME magic numbers repeated in cli.c
|
||||
controlRateConfig->thrExpo8 = newValue;
|
||||
initRcProcessing();
|
||||
blackboxLogInflightAdjustmentEvent(ADJUSTMENT_THROTTLE_EXPO, newValue);
|
||||
break;
|
||||
case ADJUSTMENT_PITCH_ROLL_RATE:
|
||||
case ADJUSTMENT_PITCH_RATE:
|
||||
newValue = constrain(value, 0, CONTROL_RATE_CONFIG_RATE_MAX);
|
||||
controlRateConfig->rates[FD_PITCH] = newValue;
|
||||
blackboxLogInflightAdjustmentEvent(ADJUSTMENT_PITCH_RATE, newValue);
|
||||
if (adjustmentFunction == ADJUSTMENT_PITCH_RATE) {
|
||||
break;
|
||||
}
|
||||
// fall through for combined ADJUSTMENT_PITCH_ROLL_RATE
|
||||
FALLTHROUGH;
|
||||
case ADJUSTMENT_ROLL_RATE:
|
||||
newValue = constrain(value, 0, CONTROL_RATE_CONFIG_RATE_MAX);
|
||||
controlRateConfig->rates[FD_ROLL] = newValue;
|
||||
blackboxLogInflightAdjustmentEvent(ADJUSTMENT_ROLL_RATE, newValue);
|
||||
break;
|
||||
case ADJUSTMENT_YAW_RATE:
|
||||
newValue = constrain(value, 0, CONTROL_RATE_CONFIG_RATE_MAX);
|
||||
controlRateConfig->rates[FD_YAW] = newValue;
|
||||
blackboxLogInflightAdjustmentEvent(ADJUSTMENT_YAW_RATE, newValue);
|
||||
break;
|
||||
case ADJUSTMENT_PITCH_ROLL_P:
|
||||
case ADJUSTMENT_PITCH_P:
|
||||
newValue = constrain(value, 0, 200); // FIXME magic numbers repeated in cli.c
|
||||
pidProfile->pid[PID_PITCH].P = newValue;
|
||||
blackboxLogInflightAdjustmentEvent(ADJUSTMENT_PITCH_P, newValue);
|
||||
|
||||
if (adjustmentFunction == ADJUSTMENT_PITCH_P) {
|
||||
break;
|
||||
}
|
||||
// fall through for combined ADJUSTMENT_PITCH_ROLL_P
|
||||
FALLTHROUGH;
|
||||
case ADJUSTMENT_ROLL_P:
|
||||
newValue = constrain(value, 0, 200); // FIXME magic numbers repeated in cli.c
|
||||
pidProfile->pid[PID_ROLL].P = newValue;
|
||||
blackboxLogInflightAdjustmentEvent(ADJUSTMENT_ROLL_P, newValue);
|
||||
break;
|
||||
case ADJUSTMENT_PITCH_ROLL_I:
|
||||
case ADJUSTMENT_PITCH_I:
|
||||
newValue = constrain(value, 0, 200); // FIXME magic numbers repeated in cli.c
|
||||
pidProfile->pid[PID_PITCH].I = newValue;
|
||||
blackboxLogInflightAdjustmentEvent(ADJUSTMENT_PITCH_I, newValue);
|
||||
if (adjustmentFunction == ADJUSTMENT_PITCH_I) {
|
||||
break;
|
||||
}
|
||||
// fall through for combined ADJUSTMENT_PITCH_ROLL_I
|
||||
FALLTHROUGH;
|
||||
case ADJUSTMENT_ROLL_I:
|
||||
newValue = constrain(value, 0, 200); // FIXME magic numbers repeated in cli.c
|
||||
pidProfile->pid[PID_ROLL].I = newValue;
|
||||
blackboxLogInflightAdjustmentEvent(ADJUSTMENT_ROLL_I, newValue);
|
||||
break;
|
||||
case ADJUSTMENT_PITCH_ROLL_D:
|
||||
case ADJUSTMENT_PITCH_D:
|
||||
newValue = constrain(value, 0, 200); // FIXME magic numbers repeated in cli.c
|
||||
pidProfile->pid[PID_PITCH].D = newValue;
|
||||
blackboxLogInflightAdjustmentEvent(ADJUSTMENT_PITCH_D, newValue);
|
||||
if (adjustmentFunction == ADJUSTMENT_PITCH_D) {
|
||||
break;
|
||||
}
|
||||
// fall through for combined ADJUSTMENT_PITCH_ROLL_D
|
||||
FALLTHROUGH;
|
||||
case ADJUSTMENT_ROLL_D:
|
||||
newValue = constrain(value, 0, 200); // FIXME magic numbers repeated in cli.c
|
||||
pidProfile->pid[PID_ROLL].D = newValue;
|
||||
blackboxLogInflightAdjustmentEvent(ADJUSTMENT_ROLL_D, newValue);
|
||||
break;
|
||||
case ADJUSTMENT_YAW_P:
|
||||
newValue = constrain(value, 0, 200); // FIXME magic numbers repeated in cli.c
|
||||
pidProfile->pid[PID_YAW].P = newValue;
|
||||
blackboxLogInflightAdjustmentEvent(ADJUSTMENT_YAW_P, newValue);
|
||||
break;
|
||||
case ADJUSTMENT_YAW_I:
|
||||
newValue = constrain(value, 0, 200); // FIXME magic numbers repeated in cli.c
|
||||
pidProfile->pid[PID_YAW].I = newValue;
|
||||
blackboxLogInflightAdjustmentEvent(ADJUSTMENT_YAW_I, newValue);
|
||||
break;
|
||||
case ADJUSTMENT_YAW_D:
|
||||
newValue = constrain(value, 0, 200); // FIXME magic numbers repeated in cli.c
|
||||
pidProfile->pid[PID_YAW].D = newValue;
|
||||
blackboxLogInflightAdjustmentEvent(ADJUSTMENT_YAW_D, newValue);
|
||||
break;
|
||||
case ADJUSTMENT_RC_RATE_YAW:
|
||||
newValue = constrain(value, 0, CONTROL_RATE_CONFIG_RC_RATES_MAX);
|
||||
controlRateConfig->rcRates[FD_YAW] = newValue;
|
||||
blackboxLogInflightAdjustmentEvent(ADJUSTMENT_RC_RATE_YAW, newValue);
|
||||
break;
|
||||
case ADJUSTMENT_D_SETPOINT:
|
||||
newValue = constrain(value, 0, 254); // FIXME magic numbers repeated in cli.c
|
||||
pidProfile->dtermSetpointWeight = newValue;
|
||||
blackboxLogInflightAdjustmentEvent(ADJUSTMENT_D_SETPOINT, newValue);
|
||||
break;
|
||||
case ADJUSTMENT_D_SETPOINT_TRANSITION:
|
||||
newValue = constrain(value, 1, 100); // FIXME magic numbers repeated in cli.c
|
||||
pidProfile->setpointRelaxRatio = newValue;
|
||||
blackboxLogInflightAdjustmentEvent(ADJUSTMENT_D_SETPOINT_TRANSITION, newValue);
|
||||
break;
|
||||
default:
|
||||
newValue = -1;
|
||||
break;
|
||||
};
|
||||
|
||||
return newValue;
|
||||
}
|
||||
|
||||
static uint8_t applySelectAdjustment(adjustmentFunction_e adjustmentFunction, uint8_t position)
|
||||
{
|
||||
uint8_t beeps = 0;
|
||||
|
||||
switch (adjustmentFunction) {
|
||||
case ADJUSTMENT_RATE_PROFILE:
|
||||
{
|
||||
if (getCurrentControlRateProfileIndex() != position) {
|
||||
changeControlRateProfile(position);
|
||||
blackboxLogInflightAdjustmentEvent(ADJUSTMENT_RATE_PROFILE, position);
|
||||
if (getCurrentControlRateProfileIndex() != position) {
|
||||
changeControlRateProfile(position);
|
||||
blackboxLogInflightAdjustmentEvent(ADJUSTMENT_RATE_PROFILE, position);
|
||||
|
||||
beeps = position + 1;
|
||||
}
|
||||
break;
|
||||
beeps = position + 1;
|
||||
}
|
||||
break;
|
||||
case ADJUSTMENT_HORIZON_STRENGTH:
|
||||
{
|
||||
uint8_t newValue = constrain(position, 0, 200); // FIXME magic numbers repeated in serial_cli.c
|
||||
|
@ -438,18 +585,21 @@ static uint8_t applySelectAdjustment(uint8_t adjustmentFunction, uint8_t positio
|
|||
pidProfile->pid[PID_LEVEL].D = newValue;
|
||||
blackboxLogInflightAdjustmentEvent(ADJUSTMENT_HORIZON_STRENGTH, position);
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case ADJUSTMENT_PID_AUDIO:
|
||||
{
|
||||
#ifdef USE_PID_AUDIO
|
||||
uint8_t newMode = pidAudioPositionToModeMap[position];
|
||||
{
|
||||
pidAudioModes_e newMode = pidAudioPositionToModeMap[position];
|
||||
if (newMode != pidAudioGetMode()) {
|
||||
pidAudioSetMode(newMode);
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (beeps) {
|
||||
|
@ -469,13 +619,14 @@ void processRcAdjustments(controlRateConfig_t *controlRateConfig)
|
|||
|
||||
const bool canUseRxData = rxIsReceivingSignal();
|
||||
|
||||
// Process Increment/Decrement adjustments
|
||||
for (int adjustmentIndex = 0; adjustmentIndex < MAX_SIMULTANEOUS_ADJUSTMENT_COUNT; adjustmentIndex++) {
|
||||
adjustmentState_t *adjustmentState = &adjustmentStates[adjustmentIndex];
|
||||
|
||||
if (!adjustmentState->config) {
|
||||
continue;
|
||||
}
|
||||
const uint8_t adjustmentFunction = adjustmentState->config->adjustmentFunction;
|
||||
const adjustmentFunction_e adjustmentFunction = adjustmentState->config->adjustmentFunction;
|
||||
if (adjustmentFunction == ADJUSTMENT_NONE) {
|
||||
continue;
|
||||
}
|
||||
|
@ -533,6 +684,27 @@ void processRcAdjustments(controlRateConfig_t *controlRateConfig)
|
|||
#endif
|
||||
MARK_ADJUSTMENT_FUNCTION_AS_BUSY(adjustmentIndex);
|
||||
}
|
||||
|
||||
// Process Absolute adjustments
|
||||
for (int index = 0; index < MAX_ADJUSTMENT_RANGE_COUNT; index++) {
|
||||
static int16_t lastRcData[MAX_ADJUSTMENT_RANGE_COUNT] = { 0 };
|
||||
|
||||
const adjustmentRange_t * const adjustmentRange = adjustmentRanges(index);
|
||||
const uint8_t channelIndex = NON_AUX_CHANNEL_COUNT + adjustmentRange->auxSwitchChannelIndex;
|
||||
const adjustmentConfig_t *adjustmentConfig = &defaultAdjustmentConfigs[adjustmentRange->adjustmentFunction - ADJUSTMENT_FUNCTION_CONFIG_INDEX_OFFSET];
|
||||
|
||||
// If setting is defined for step adjustment and center value has been specified, apply values directly (scaled) from aux channel
|
||||
if ((rcData[channelIndex] != lastRcData[index]) &&
|
||||
adjustmentRange->adjustmentCenter &&
|
||||
(adjustmentConfig->mode == ADJUSTMENT_MODE_STEP) &&
|
||||
isRangeActive(adjustmentRange->auxChannelIndex, &adjustmentRange->range)) {
|
||||
int value = (((rcData[channelIndex] - PWM_RANGE_MIDDLE) * adjustmentRange->adjustmentScale) / (PWM_RANGE_MIDDLE - PWM_RANGE_MIN)) + adjustmentRange->adjustmentCenter;
|
||||
|
||||
lastRcData[index] = rcData[channelIndex];
|
||||
applyAbsoluteAdjustment(controlRateConfig, adjustmentRange->adjustmentFunction, value);
|
||||
pidInitConfig(pidProfile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void resetAdjustmentStates(void)
|
||||
|
@ -544,7 +716,9 @@ void updateAdjustmentStates(void)
|
|||
{
|
||||
for (int index = 0; index < MAX_ADJUSTMENT_RANGE_COUNT; index++) {
|
||||
const adjustmentRange_t * const adjustmentRange = adjustmentRanges(index);
|
||||
if (isRangeActive(adjustmentRange->auxChannelIndex, &adjustmentRange->range)) {
|
||||
// Only use slots if center value has not been specified, otherwise apply values directly (scaled) from aux channel
|
||||
if (isRangeActive(adjustmentRange->auxChannelIndex, &adjustmentRange->range) &&
|
||||
(adjustmentRange->adjustmentCenter == 0)) {
|
||||
const adjustmentConfig_t *adjustmentConfig = &defaultAdjustmentConfigs[adjustmentRange->adjustmentFunction - ADJUSTMENT_FUNCTION_CONFIG_INDEX_OFFSET];
|
||||
configureAdjustment(adjustmentRange->adjustmentIndex, adjustmentRange->auxSwitchChannelIndex, adjustmentConfig);
|
||||
}
|
||||
|
|
|
@ -66,8 +66,8 @@ typedef union adjustmentConfig_u {
|
|||
} adjustmentData_t;
|
||||
|
||||
typedef struct adjustmentConfig_s {
|
||||
uint8_t adjustmentFunction;
|
||||
uint8_t mode;
|
||||
adjustmentFunction_e adjustmentFunction;
|
||||
adjustmentMode_e mode;
|
||||
adjustmentData_t data;
|
||||
} adjustmentConfig_t;
|
||||
|
||||
|
@ -84,6 +84,8 @@ typedef struct adjustmentRange_s {
|
|||
|
||||
// ... via slot
|
||||
uint8_t adjustmentIndex;
|
||||
uint16_t adjustmentCenter;
|
||||
uint16_t adjustmentScale;
|
||||
} adjustmentRange_t;
|
||||
|
||||
PG_DECLARE_ARRAY(adjustmentRange_t, MAX_ADJUSTMENT_RANGE_COUNT, adjustmentRanges);
|
||||
|
|
|
@ -1053,7 +1053,7 @@ static void cliSerialPassthrough(char *cmdline)
|
|||
|
||||
static void printAdjustmentRange(uint8_t dumpMask, const adjustmentRange_t *adjustmentRanges, const adjustmentRange_t *defaultAdjustmentRanges)
|
||||
{
|
||||
const char *format = "adjrange %u %u %u %u %u %u %u";
|
||||
const char *format = "adjrange %u %u %u %u %u %u %u %u %u";
|
||||
// print out adjustment ranges channel settings
|
||||
for (uint32_t i = 0; i < MAX_ADJUSTMENT_RANGE_COUNT; i++) {
|
||||
const adjustmentRange_t *ar = &adjustmentRanges[i];
|
||||
|
@ -1065,7 +1065,9 @@ static void printAdjustmentRange(uint8_t dumpMask, const adjustmentRange_t *adju
|
|||
&& ar->range.endStep == arDefault->range.endStep
|
||||
&& ar->adjustmentFunction == arDefault->adjustmentFunction
|
||||
&& ar->auxSwitchChannelIndex == arDefault->auxSwitchChannelIndex
|
||||
&& ar->adjustmentIndex == arDefault->adjustmentIndex;
|
||||
&& ar->adjustmentIndex == arDefault->adjustmentIndex
|
||||
&& ar->adjustmentCenter == arDefault->adjustmentCenter
|
||||
&& ar->adjustmentScale == arDefault->adjustmentScale;
|
||||
cliDefaultPrintLinef(dumpMask, equalsDefault, format,
|
||||
i,
|
||||
arDefault->adjustmentIndex,
|
||||
|
@ -1073,7 +1075,9 @@ static void printAdjustmentRange(uint8_t dumpMask, const adjustmentRange_t *adju
|
|||
MODE_STEP_TO_CHANNEL_VALUE(arDefault->range.startStep),
|
||||
MODE_STEP_TO_CHANNEL_VALUE(arDefault->range.endStep),
|
||||
arDefault->adjustmentFunction,
|
||||
arDefault->auxSwitchChannelIndex
|
||||
arDefault->auxSwitchChannelIndex,
|
||||
arDefault->adjustmentCenter,
|
||||
arDefault->adjustmentScale
|
||||
);
|
||||
}
|
||||
cliDumpPrintLinef(dumpMask, equalsDefault, format,
|
||||
|
@ -1083,7 +1087,9 @@ static void printAdjustmentRange(uint8_t dumpMask, const adjustmentRange_t *adju
|
|||
MODE_STEP_TO_CHANNEL_VALUE(ar->range.startStep),
|
||||
MODE_STEP_TO_CHANNEL_VALUE(ar->range.endStep),
|
||||
ar->adjustmentFunction,
|
||||
ar->auxSwitchChannelIndex
|
||||
ar->auxSwitchChannelIndex,
|
||||
ar->adjustmentCenter,
|
||||
ar->adjustmentScale
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -1142,6 +1148,23 @@ static void cliAdjustmentRange(char *cmdline)
|
|||
memset(ar, 0, sizeof(adjustmentRange_t));
|
||||
cliShowParseError();
|
||||
}
|
||||
|
||||
// Optional arguments
|
||||
ar->adjustmentCenter = 0;
|
||||
ar->adjustmentScale = 0;
|
||||
|
||||
ptr = nextArg(ptr);
|
||||
if (ptr) {
|
||||
val = atoi(ptr);
|
||||
ar->adjustmentCenter = val;
|
||||
validArgumentCount++;
|
||||
}
|
||||
ptr = nextArg(ptr);
|
||||
if (ptr) {
|
||||
val = atoi(ptr);
|
||||
ar->adjustmentScale = val;
|
||||
validArgumentCount++;
|
||||
}
|
||||
} else {
|
||||
cliShowArgumentRangeError("index", 0, MAX_ADJUSTMENT_RANGE_COUNT - 1);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue