Skip to content

Commit

Permalink
Support complex types via branches
Browse files Browse the repository at this point in the history
This commit is a proof of concept update of vss-tools to support
higher order/complex types via a variation of the approach outlined in https://github.com/COVESA/vehicle_signal_specification/wiki/Proposal-%22struct%22:-Just-model-as-branches,-the-rest-is-deployment

Ref: COVESA/vehicle_signal_specification#326

**Description  **
The main idea is that we are trying to model a sensor of Complex type - `ObstacleList` as a branch.
The current limitation with branches is that you cannot have arrays of branches.

With the understanding that branches are to be treated as a data type (like primitive and their array equivalent),
what we need is a way to convey the fact that the branch represents a collection/array.
In the case of primitives, we use the operator `[]` for this purpose. For example, an array type `uint8` is denoted by adding the suffix `[]`.

On a similar path, we can utilize the already available `arraysize` property of a VSS node to specify the array size of a branch typed node.

In this commit, the VSS tools are updated to proceess the `arraysize` key for branch typed nodes.

For reference, the type is defined as follows:
```
ObstacleClass
{
    uint64 class
}

Obstacle
{
    uint64 id
    ObstacleClass class
    float64 probability
}

ObstacleList
{
    Obstacle[] data
}
```

All the relevant files are included in the commit.

vspec -> json: `python vspec2json.py ObstacleArray.vspec --json-pretty out.json`

The resulting JSON output contains the attribute "arraysize" for the branch typed nodes if defined.
  • Loading branch information
Krishna Koppolu committed Aug 2, 2022
1 parent 19531d2 commit a544eff
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Obstacle.vspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Id:
type: attribute
datatype: int64

Probability:
type: attribute
datatype: float

ObstacleClass:
type: branch
#include ObstacleClass.vspec ObstacleClass
17 changes: 17 additions & 0 deletions ObstacleArray.vspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Vehicle:
type: branch

Vehicle.ADAS:
type: branch

Vehicle.ADAS.Lidar:
type: branch

Vehicle.ADAS.Lidar.Front:
type: branch

Vehicle.ADAS.Lidar.Front.Obstacles:
type: branch
arraysize: 10

#include ObstacleData.vspec Vehicle.ADAS.Lidar.Front.Obstacles
3 changes: 3 additions & 0 deletions ObstacleClass.vspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Class:
type: attribute
datatype: uint64
4 changes: 4 additions & 0 deletions ObstacleData.vspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Data:
type: branch

#include Obstacle.vspec Data
70 changes: 70 additions & 0 deletions out.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"Vehicle": {
"children": {
"ADAS": {
"children": {
"Lidar": {
"children": {
"Front": {
"children": {
"Obstacles": {
"arraysize": 10,

This comment has been minimized.

Copy link
@kkoppolu1

kkoppolu1 Aug 3, 2022

Owner

The idea is to use a property to signify that the branch is an array.
For dynamic arrays, a new property is needed or a "marker" value can be used for arraysize such as "None"

"children": {
"Data": {
"children": {
"Id": {
"datatype": "int64",
"description": null,
"type": "attribute",
"uuid": "31f7ac1946da58a194c1c6a8dad9cf1d"
},
"ObstacleClass": {
"children": {
"Class": {
"datatype": "uint64",
"description": null,
"type": "attribute",
"uuid": "c30ce72db64057fd99ac502190bf5fcb"
}
},
"description": null,
"type": "branch",
"uuid": "9ea15f3abd1656e096bcdc5ee6dcbba3"
},
"Probability": {
"datatype": "float",
"description": null,
"type": "attribute",
"uuid": "32e416f193d250d3a5f96f0f4789bee3"
}
},
"description": null,
"type": "branch",
"uuid": "9646d03cc6845c42834aa74fc91a1cfa"
}
},
"description": null,
"type": "branch",
"uuid": "6ae7d48f9cd25ff694dc5ebd02f90522"
}
},
"description": null,
"type": "branch",
"uuid": "f96d319c62615760861d8abe645081af"
}
},
"description": null,
"type": "branch",
"uuid": "aac706a4d4ca599c824ebc479c47540c"
}
},
"description": null,
"type": "branch",
"uuid": "14c2b2e1297b513197d320a5ce58f42e"
}
},
"description": null,
"type": "branch",
"uuid": "ccc825f94139544dbb5f4bfd033bece6"
}
}
3 changes: 3 additions & 0 deletions vspec/model/vsstree.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ def __init__(self, name, source_dict: dict, parent=None, children=None, break_on
if "instances" in source_dict.keys():
self.instances = source_dict["instances"]

if "arraysize" in source_dict.keys():
self.arraysize = source_dict["arraysize"]

if "deprecation" in source_dict.keys():
self.deprecation = source_dict["deprecation"]

Expand Down
2 changes: 2 additions & 0 deletions vssexporters/vss2json.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ def export_node(json_dict, node, generate_uuid):
json_dict[node.name]["default"] = node.default_value
if node.deprecation != "":
json_dict[node.name]["deprecation"] = node.deprecation
if hasattr(node, 'arraysize'):
json_dict[node.name]["arraysize"] = node.arraysize

# in case of unit or aggregate, the attribute will be missing
try:
Expand Down

0 comments on commit a544eff

Please sign in to comment.