Skip to content
This repository has been archived by the owner on Sep 2, 2024. It is now read-only.

Introducing eCAL Feeder for KUKSA.val Integration #161

Merged
merged 18 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions ecal2val/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# eCAL Feeder
The purpose of this implementation is to input data received via `eCAL` into a `KUKSA.val` databroker. The topics transmitted by eCAL are in the form of protobuf, and based on the VSS description and data outlined in this format, it is possible to provide data to the data broker via the kuksa_client.

## Usage
1. Install Python requirements for both eCAL and KUKSA.val

```
sudo add-apt-repository ppa:ecal/ecal-5.12
sudo apt-get update
sudo apt-get install ecal
sudo apt install python3-ecal5

pip install kuksa-client
```

2. Generate vss_data_pb2.py in proto_struct directory with following method

```
sudo apt-get install protobuf-compiler

protoc --python_out=. vss_data.proto
```

3. Use the following command to run the ecal2val.py

```
export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python

python3 ecal2val.py
```

This assumes a running `KUKSA.val` databroker at `127.0.0.1:55555`.

4. For testing, run the mock_publisher.py

```
export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python

python3 mock_publisher.py
```

This was successfully tested on Ubuntu 20.04 and eCAL 5.12
63 changes: 63 additions & 0 deletions ecal2val/ecal2val.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#! /usr/bin/env python3

########################################################################
# Copyright (c) 2023 Contributors to the Eclipse Foundation
#
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
#
# This program and the accompanying materials are made available under the
# terms of the Apache License 2.0 which is available at
# http://www.apache.org/licenses/LICENSE-2.0
#
# SPDX-License-Identifier: Apache-2.0
########################################################################

'''
Subscriber subscribing topics through ECAL communication and sending to KUKSA.val
'''

import sys
import time

import ecal.core.core as ecal_core
from ecal.core.subscriber import ProtoSubscriber

import proto_struct.vss_data_pb2 as vss_data_pb2

from kuksa_client.grpc import VSSClient
from kuksa_client.grpc import Datapoint


ecal_core.initialize(sys.argv, "Python Protobuf")

sub = ProtoSubscriber("vss_data_python_protobuf_topic", vss_data_pb2.VssData)


'''This callback function subscribes topics
and writes the date in the protobuf
to the data broker through the client.'''


def callback(topic_name, vss_data_proto_msg, time):
with VSSClient('127.0.0.1', 55555) as client:
if vss_data_proto_msg.data_int != 0:
client.set_current_values({
vss_data_proto_msg.description: Datapoint(vss_data_proto_msg.data_int),
})
elif vss_data_proto_msg.data_float != 0:
client.set_current_values({
vss_data_proto_msg.description: Datapoint(vss_data_proto_msg.data_float),
})
else:
client.set_current_values({
vss_data_proto_msg.description: Datapoint(0),
})


sub.set_callback(callback)

while ecal_core.ok():
time.sleep(1)

ecal_core.finalize()
20 changes: 20 additions & 0 deletions ecal2val/mock_data.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Vehicle.Speed 1.0
Vehicle.Chassis.SteeringWheel.Angle -40
Vehicle.Speed 1.2
Vehicle.Chassis.SteeringWheel.Angle -30
Vehicle.Speed 1.4
Vehicle.Chassis.SteeringWheel.Angle -20
Vehicle.Speed 1.6
Vehicle.Chassis.SteeringWheel.Angle -10
Vehicle.Speed 1.8
Vehicle.Chassis.SteeringWheel.Angle 0
Vehicle.Speed 2.0
Vehicle.Chassis.SteeringWheel.Angle 10
Vehicle.Speed 2.2
Vehicle.Chassis.SteeringWheel.Angle 20
Vehicle.Speed 2.4
Vehicle.Chassis.SteeringWheel.Angle 30
Vehicle.Speed 2.6
Vehicle.Chassis.SteeringWheel.Angle 40
Vehicle.Speed 2.8
Vehicle.Chassis.SteeringWheel.Angle 50
55 changes: 55 additions & 0 deletions ecal2val/mock_publisher.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#! /usr/bin/env python3

########################################################################
# Copyright (c) 2023 Contributors to the Eclipse Foundation
#
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
#
# This program and the accompanying materials are made available under the
# terms of the Apache License 2.0 which is available at
# http://www.apache.org/licenses/LICENSE-2.0
#
# SPDX-License-Identifier: Apache-2.0
########################################################################

'''
Publisher publishing topics via protobuf message through eCAL communication.
'''

import sys
import time

import ecal.core.core as ecal_core
from ecal.core.publisher import ProtoPublisher

import proto_struct.vss_data_pb2 as vss_data_pb2


ecal_core.initialize(sys.argv, "Python Protobuf")

pub = ProtoPublisher("vss_data_python_protobuf_topic", vss_data_pb2.VssData)

'''Reads arbitrary data from 'mock_data.txt'
and publishes it in the form of a protobuf message.'''
while ecal_core.ok():
with open("mock_data.txt", 'r', encoding='utf-8') as file:
for line in file:
description, data = line.rstrip().split()

protobuf_message = vss_data_pb2.VssData()
protobuf_message.description = description
protobuf_message.data_int = 0
protobuf_message.data_float = 0

try:
protobuf_message.data_int = int(data)
except ValueError:
protobuf_message.data_float = float(data)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if it's a string/bool etc.?


pub.send(protobuf_message)
print("{} published".format(description))

time.sleep(1)

ecal_core.finalize()
10 changes: 10 additions & 0 deletions ecal2val/proto_struct/vss_data.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
syntax = "proto3";

package proto_struct;

message VssData
{
string description = 1;
int32 data_int = 2;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't you leverage the structure of https://github.com/eclipse/kuksa.val/blob/master/proto/kuksa/val/v1/types.proto so for example use Datapoint etc. directly and then you not need to handle that much for float/bool/string etc.

float data_float = 3;
}
Loading