Skip to content

Commit be9e33c

Browse files
authored
Merge pull request #6108 from iNavFlight/dzikuvx-new-lc-functions
New functions: sin, cos, tan and range scaling
2 parents 7a7fcf3 + 9714f05 commit be9e33c

File tree

3 files changed

+79
-11
lines changed

3 files changed

+79
-11
lines changed

docs/Programming Framework.md

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,22 @@ IPF can be edited using INAV Configurator user interface, of via CLI
5252
| 19 | GVAR INC | Increase the GVAR indexed by `Operand A` with value from `Operand B` |
5353
| 20 | GVAR DEC | Decrease the GVAR indexed by `Operand A` with value from `Operand B` |
5454
| 21 | IO PORT SET | Set I2C IO Expander pin `Operand A` to value of `Operand B`. `Operand A` accepts values `0-7` and `Operand B` accepts `0` and `1` |
55-
| 22 | OVERRIDE_ARMING_SAFETY | Allows to arm on any angle even without GPS fix |
56-
| 23 | OVERRIDE_THROTTLE_SCALE | Override throttle scale to the value defined by operand. Operand type `0` and value `50` means throttle will be scaled by 50%. |
57-
| 24 | SWAP_ROLL_YAW | basically, when activated, yaw stick will control roll and roll stick will control yaw. Required for tail-sitters VTOL during vertical-horizonral transition when body frame changes |
58-
| 25 | SET_VTX_POWER_LEVEL | Sets VTX power level. Accepted values are `0-3` for SmartAudio and `0-4` for Tramp protocol |
59-
| 26 | INVERT_ROLL | Inverts ROLL axis input for PID/PIFF controller |
60-
| 27 | INVERT_PITCH | Inverts PITCH axis input for PID/PIFF controller |
61-
| 28 | INVERT_YAW | Inverts YAW axis input for PID/PIFF controller |
62-
| 29 | OVERRIDE_THROTTLE | Override throttle value that is fed to the motors by mixer. Operand is scaled in us. `1000` means throttle cut, `1500` means half throttle |
63-
| 30 | SET_VTX_BAND | Sets VTX band. Accepted values are `1-5` |
64-
| 31 | SET_VTX_CHANNEL | Sets VTX channel. Accepted values are `1-8` |
55+
| 22 | OVERRIDE_ARMING_SAFETY | Allows to arm on any angle even without GPS fix |
56+
| 23 | OVERRIDE_THROTTLE_SCALE | Override throttle scale to the value defined by operand. Operand type `0` and value `50` means throttle will be scaled by 50%. |
57+
| 24 | SWAP_ROLL_YAW | basically, when activated, yaw stick will control roll and roll stick will control yaw. Required for tail-sitters VTOL during vertical-horizonral transition when body frame changes |
58+
| 25 | SET_VTX_POWER_LEVEL | Sets VTX power level. Accepted values are `0-3` for SmartAudio and `0-4` for Tramp protocol |
59+
| 26 | INVERT_ROLL | Inverts ROLL axis input for PID/PIFF controller |
60+
| 27 | INVERT_PITCH | Inverts PITCH axis input for PID/PIFF controller |
61+
| 28 | INVERT_YAW | Inverts YAW axis input for PID/PIFF controller |
62+
| 29 | OVERRIDE_THROTTLE | Override throttle value that is fed to the motors by mixer. Operand is scaled in us. `1000` means throttle cut, `1500` means half throttle |
63+
| 30 | SET_VTX_BAND | Sets VTX band. Accepted values are `1-5` |
64+
| 31 | SET_VTX_CHANNEL | Sets VTX channel. Accepted values are `1-8` |
6565
| 32 | SET_OSD_LAYOUT | Sets OSD layout. Accepted values are `0-3` |
66+
| 33 | SIN | Computes SIN of `Operand A` value in degrees. Output is multiplied by `Operand B` value. If `Operand B` is `0`, result is multiplied by `500` |
67+
| 34 | COS | Computes COS of `Operand A` value in degrees. Output is multiplied by `Operand B` value. If `Operand B` is `0`, result is multiplied by `500` |
68+
| 35 | TAN | Computes TAN of `Operand A` value in degrees. Output is multiplied by `Operand B` value. If `Operand B` is `0`, result is multiplied by `500` |
69+
| 36 | MAP_INPUT | Scales `Operand A` from [`0` : `Operand B`] to [`0` : `1000`]. Note: input will be constrained and then scaled |
70+
| 37 | MAP_OUTPUT | Scales `Operand A` from [`0` : `1000`] to [`0` : `Operand B`]. Note: input will be constrained and then scaled |
6671

6772

6873
### Operands
@@ -173,3 +178,36 @@ Sets Thhrottle output to about `50%` when Logic Condition `0` evaluates as `true
173178

174179
If Logic Condition `0` evaluates as `true`, motor throttle control is bound to RC channel 7 instead of throttle channel
175180

181+
### Set VTX channel with a POT
182+
183+
Set VTX channel with a POT on the radio assigned to RC channel 6
184+
185+
```
186+
logic 0 1 -1 15 1 6 0 1000 0
187+
logic 1 1 -1 37 4 0 0 7 0
188+
logic 2 1 -1 14 4 1 0 1 0
189+
logic 3 1 -1 31 4 2 0 0 0
190+
```
191+
192+
Steps:
193+
1. Normalize range `[1000:2000]` to `[0:1000]` by substracting `1000`
194+
2. Scale range `[0:1000]` to `[0:7]`
195+
3. Increase range by `1` to have the range of `[1:8]`
196+
4. Assign LC#2 to VTX channel function
197+
198+
### Set VTX power with a POT
199+
200+
Set VTX power with a POT on the radio assigned to RC channel 6. In this example we scale POT to 4 power level `[1:4]`
201+
202+
```
203+
logic 0 1 -1 15 1 6 0 1000 0
204+
logic 1 1 -1 37 4 0 0 3 0
205+
logic 2 1 -1 14 4 1 0 1 0
206+
logic 3 1 -1 25 4 2 0 0 0
207+
```
208+
209+
Steps:
210+
1. Normalize range [1000:2000] to [0:1000] by substracting `1000`
211+
2. Scale range [0:1000] to [0:3]
212+
3. Increase range by `1` to have the range of [1:4]
213+
4. Assign LC#2 to VTX power function

src/main/programming/logic_condition.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,31 @@ static int logicConditionCompute(
277277
return operandB;
278278
break;
279279
#endif
280+
281+
case LOGIC_CONDITION_SIN:
282+
temporaryValue = (operandB == 0) ? 500 : operandB;
283+
return sin_approx(DEGREES_TO_RADIANS(operandA)) * temporaryValue;
284+
break;
285+
286+
case LOGIC_CONDITION_COS:
287+
temporaryValue = (operandB == 0) ? 500 : operandB;
288+
return cos_approx(DEGREES_TO_RADIANS(operandA)) * temporaryValue;
289+
break;
290+
break;
291+
292+
case LOGIC_CONDITION_TAN:
293+
temporaryValue = (operandB == 0) ? 500 : operandB;
294+
return tan_approx(DEGREES_TO_RADIANS(operandA)) * temporaryValue;
295+
break;
296+
297+
case LOGIC_CONDITION_MAP_INPUT:
298+
return scaleRange(constrain(operandA, 0, operandB), 0, operandB, 0, 1000);
299+
break;
300+
301+
case LOGIC_CONDITION_MAP_OUTPUT:
302+
return scaleRange(constrain(operandA, 0, 1000), 0, 1000, 0, operandB);
303+
break;
304+
280305
default:
281306
return false;
282307
break;

src/main/programming/logic_condition.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,12 @@ typedef enum {
6262
LOGIC_CONDITION_SET_VTX_BAND = 30,
6363
LOGIC_CONDITION_SET_VTX_CHANNEL = 31,
6464
LOGIC_CONDITION_SET_OSD_LAYOUT = 32,
65-
LOGIC_CONDITION_LAST = 33,
65+
LOGIC_CONDITION_SIN = 33,
66+
LOGIC_CONDITION_COS = 34,
67+
LOGIC_CONDITION_TAN = 35,
68+
LOGIC_CONDITION_MAP_INPUT = 36,
69+
LOGIC_CONDITION_MAP_OUTPUT = 37,
70+
LOGIC_CONDITION_LAST = 38,
6671
} logicOperation_e;
6772

6873
typedef enum logicOperandType_s {

0 commit comments

Comments
 (0)