# Non-linear mapping of device variables

This guide explains how to transform analog signals into a non-linear function for example to generate different Fuel level outputs into a variable that could be used on the interface, a graph or a report.

### Introduction

It is possible to map analog inputs to variables in a non-linear function. This can be useful when taking a sensor value from a vehicle (e.g. a fuel tank) and mapping it to a variable like Fuel level. The variable Fuel level could be used later on FU reports.

• This method is useful when the sensor value is not proportional/linear to the actual fuel volume.

### Setup

1. Open Admin > Device Mapper and search for your device type.

Make sure you have mapped the fuel input from the device to an analog variable using the device mapper.

Example 1 of a possible mapping: AnalogInput1 > Fuel level

Example 2 of a possible mapping: FuelGauge > Fuel level

2. Take notes of the readings from the fuel indicator on the vehicle and the equivalent values obtained in GpsGate. The terminal can be used to check out these values.

3. Starting with the fuel tank full and from the observations taken, make a table like this:

Generating a graph of the function it could be seen that the consumption is non-linear:

4. At this point a formula with the following syntax needs to be created:

`IN1:IN2#OUT1:OUT2,IN3:IN4#OUT3:OUT4,...`
• INx and OUTx are numbers, which defines intervals.
• The IN-interval maps to the OUT-interval.

For the example used before the formula would be:

`5.80:5.20#70:60,5.20:4.60#60:40,4.60:2.50#40:30,2.50:1.20#30:10,1.20:0.14#10:5`
• A value 5.80 from the tracker will map to 70 in the GpsGate Variable.
• A value 5.20 will map to 60 and any value in between 5.80 and 5.25 would be mapped according to a linear function.

### Device mapper scripting

A script has to be added using Device Mapper Scripting to get the proper values.

1. Go to Admin> Device Mapper and select Fuel level variable.

2. Click on Edit button.

3. Insert the formula into the editor.

4. Click on Test Script to validate the result (you can select a Track Point from any of your device's tracks to generate a sampling output for your script. This allows you testing with real data).

 `var formula = ``'5.80:5.20#70:60,5.20:4.60#60:40,4.60:2.50#40:30,2.50:1.20#30:10,1.20:0.14#10:5'``;` `var fuelRaw = fields.get(``'FuelGauge'``,``null``);` `return` `nonLinear(formula,fuelRaw);`

5. Click on Save.

Now the Fuel level variable is displayed in liters and should be ready to use in event rules and reports.

### Troubleshooting

If the expected values are not being obtained then it might be caused by wrong data or the calibration is not correct.

• Make sure the readings make sense.
• If the vehicle is consuming fuel, the readings should be lower so the Input should be decreasing until the next refill of the fuel tank.
• If the values show zero-like readings, they might be producing wrong information in reports. In that case, those readings can be ignored by adding 0:0#null at the beginning of the formula used on device mapper scripting.
• In case the signals from the device are right, then the values for the variable Fuel level (which is the output of the script) should be checked. If they are wrong, then the calibration is not right and the formula needs to be changed on Device Mapper Scripting.
• It is important to remember that after changing the script it will be needed to reprocess data to get the new values.