Skip to content

Commit

Permalink
Improve mapping documentation
Browse files Browse the repository at this point in the history
Adding some background info on how to decide on mapping.
Change name of file to README to make it easier to
view in github web ui

Signed-off-by: Erik Jaegervall <erik.jaegervall@se.bosch.com>
  • Loading branch information
erikbosch committed Feb 27, 2024
1 parent f1b5eb4 commit 025e68a
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ $ pip install -r requirements-dev.txt
The CAN provider requires a mapping file as input.
The mapping file describes mapping between VSS signals and CAN (DBC) signals.
It shall be a JSON file with VSS syntax with metadata for dbc information.
Please see [mapping documentation](mapping/mapping.md) for more information.
Please see [mapping documentation](mapping/README.md) for more information.

## Configuring and Using the CAN Provider

Expand Down
53 changes: 43 additions & 10 deletions mapping/mapping.md → mapping/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ for the DBC feeder, like in the example below.
"math": "(x+100)/40"
}
}
}
```

Two types of mapping exists.
Expand Down Expand Up @@ -147,19 +148,53 @@ If transform is not specified values will be transformed as is.

A Math transformation can be defined by the `math` attribute.
It accepts [py-expression-eval](https://github.com/AxiaCore/py-expression-eval/) formulas as argument.
The DBC feeder expects the DBC value to be represented as `x` like in the example below.
The DBC feeder expects the DBC value to be represented as `x`.

When evaluating what transformation that is needed one must study both the DBC signal and the VSS signal. An example is given below for mirror tilt of left mirror.

**DBC**

The signal `VCLEFT_mirrorTiltYPosition` provide mirror tilt.

```
SG_ VCLEFT_mirrorTiltYPosition : 41|8@1+ (0.02,0) [0|5] "V" Receiver
```

An introduction to DBC file syntax can be found [here](https://www.csselectronics.com/pages/can-dbc-file-database-intro). The specification above shows that on CAN the tilt is represented as 0-5 Volts. The value is sent with a scaling of 0.02 and uses 8 bits, i.e. 5 Volts is transmitted as 250, but that information is not needed for the can-provider transformation as the DBC scaling/offset is performed automatically by the CAN middleware.

The


**VSS**

The corresponding signal in VSS use -100 percent to +100 percent as range and int8 as datatype:

```
Vehicle.Body.Mirrors.DriverSide.Tilt:
datatype: int8
unit: percent
min: -100
max: 100
type: actuator
description: Mirror tilt as a percent. 0 = Center Position. 100 = Fully Upward Position. -100 = Fully Downward Position.
```

With an assumptions that 5 Volts corresponds to fully upward (+100%) and 0 Volts corresponds to
fully downward (-100%) then one could define mapping like in the example below. This is based on the assumption that the DBC signal contain actual value and we want to inject actual value to VSS.

```yaml
Vehicle.OBD.EngineLoad:
type: sensor
datatype: float
dbc:
signal: RearPower266
interval_ms: 4000
Vehicle.Body.Mirrors.DriverSide.Tilt:
datatype: int8
type: actuator
dbc2vss:
signal: VCLEFT_mirrorTiltYPosition
interval_ms: 100
transform:
math: "floor(abs(x/5))"
math: "floor((x*40)-100)"
```
I.e. 2 Volts corresponds to `(2*40)-100` = -20%.

Transformation may fail. Typical reasons may include that the DBC value is not numerical,
or that the transformation fails on certain values like division by zero.
If transformation fails the signal will be ignored.
Expand Down Expand Up @@ -239,7 +274,6 @@ There are some minor changes in what constructs that are possible to specify in
* It was previously theoretically possible to have a mapping multiple DBC signals to the same VSS signal.
That is no longer possible as each VSS signal must appear at most once in the new format.


### Math Migration

Migrating Math-mapping is straightforward as shown in this example:
Expand Down Expand Up @@ -278,7 +312,6 @@ Vehicle.Chassis.SteeringWheel.Angle:
Migrating mapping is also relative straightforward.
The example below also shows how to migrate a mapping where one DBC signal maps to multiple VSS signals.


Old format:

```yaml
Expand Down

0 comments on commit 025e68a

Please sign in to comment.