Math channels¶
Math channels allow you to calculate values based on measured data. For example you can calculate travelled distance from speed channel by using integral function.
Each math channel requires name, sampling rate, unit, decimals and formula
Settings¶
Name¶
Recommendation is to use some naming convention with math channel names that it’s easy to find the math channels when you start to get more channels
Decimals¶
Integer on how many decimals channels require.
Sampling rates¶
| Editor period | Output sampling rate |
|---|---|
| 2 ms | 500 Hz |
| 5 ms | 200 Hz |
| 10 ms | 100 Hz |
| 20 ms | 50 Hz |
| 100 ms | 10 Hz |
| 1 s | 1 Hz |
New channels default to 1 Hz and 0 decimals. Formula results are floored to the configured decimal count, not rounded.
Units¶
Available unit values are km/h, m/s, mm/s, 1/m, V, G, A, deg/s, mm, m, C, %, %/s, deg, deg/s², N, N.m, N/mm, kg, HP/kg, s, and cSt; an empty unit is allowed.
Formula¶
Syntax¶
Operators¶
| Operator | Type | Description |
|---|---|---|
| + | Arithmetic | Plus |
| - | Arithmetic | Subtract |
| * | Arithmetic | Multiply |
| / | Arithmetic | Divide |
| % | Arithmetic | Remainder |
| ^ | Arithmetic | Exponent |
| \< | Comparison | Less than |
| \<= | Comparison | Less than or equal |
| > | Comparison | Greater than |
| >= | Comparison | Greater than or equal |
| == | Comparison | Equal |
| != | Comparison | Not equal |
| \&\& | Logical | And |
| || | Logical | Or |
| ! | Logical | Not |
Functions¶
Available functions are listed below
| Function | Signature / behavior |
|---|---|
| Absolute value | abs(x) |
| Square / square root | sqr(x), sqrt(x) |
| Pi | pi(); zero arguments |
| Trigonometry | sin(x), cos(x), tan(x), asin(x), acos(x), atan(x); inputs and outputs are radians |
| Conditional | if(condition, value_if_true, value_if_false) |
| Comparison aliases | lt(a,b), le(a,b), gt(a,b), ge(a,b), eq(a,b), nq(a,b) |
| Logical aliases | and(a,b), or(a,b) |
| Not-a-number | nan() |
| Derivative | derivative(x); finite difference per second, based on the math channel's sampling rate. Previous value starts at 0, so the first output is x * sampling_rate |
| Integral | integral(x[, lap_reset]); cumulative time integral, adding x / sampling_rate each sample. Optional lap_reset is false/0 by default; 1 resets at lap markers |
| Moving average | moving_avg(x, window_size); trailing window in samples. window_size must be a positive integer constant; output is 0 until the window fills |
| Hold true | hold_true(condition, sample_count[, catch_up]); emits true only after the condition stays true for the required consecutive samples. sample_count must be a positive integer constant; optional catch_up defaults to 0 and, when enabled, returns sample_count instead of 1 on the completion sample |
If condition¶
Function evaluates given condition if the result is true or false. Depending on the calculation results, function outputs the defined result.
js
if({condition}, {value-if-true}, {value-if-false})
| Parameter | Description | Examples |
|---|---|---|
| condition | Expression to evaluate if given condition is true or false. Expression can include aritmethic calculations or various operators to evaluate values against In the expression any operators. | ([RPM] + 1000) > 10000[RPM] > 10000 \&\& [RPM] \< 20000 |
| value-if-true | Value or function to execute in case result from condition is true. It's possible to use channel as output, calculate new value or use static values | |
| value-if-false | It's possible to use channel as output, calculate new value or use static values |
This example shows a simple example how to make condition and use manipulate the output with multiplication. If function is used to separate throttle values from throttle/brake channel.
js
if([throttle-and-brake] > 0,[throttle-and-brake] * 10, 0)
Condition is evaluating if channel value is above 0 and everytime this condition is true, then Throttle and brake channel value multiplied with 10 is used. If condition is false, then value is always 0.
Derivative¶
Integral¶
Function calculates the cumulative sum of channel/statement values. Function also give the possibility to reset calculation after lap changes.
js
integral( {data}, {lap-reset})
| Parameter | Description | Example |
|---|---|---|
| data | ||
| lap-reset | Boolean (true/false) option to enable integral value reset when lap changes. Use value 1 to enable lap reset and 0 to disable lap reset. |
Example shows how to calculate distance over one data file from speed channels by using integrate function.
js
integral( [speed-all], 0)
Example shows how to calculate cumulative sum of steering input over one lap. Difference here is that second parameter is set to 1, so calculation is reset after each lap. This calculation can be used to indicate possible balance change over one run.
js
integral( [steering], 1)