This repository has been archived by the owner on Sep 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
Introducing eCAL Feeder for KUKSA.val Integration #161
Merged
Merged
Changes from 5 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
0ca6d55
Add ecal2val.py
lalywr2000 c144f96
Add mock data publisher
lalywr2000 ded317b
Add mock data
lalywr2000 119a0d5
Add proto struct
lalywr2000 6c5c0d3
Add description of ecal2val
lalywr2000 2373084
Add license to proto file
lalywr2000 5522025
Edit license in proto file
lalywr2000 ee81683
Remove proto_struct directory
lalywr2000 ded6021
Replace proto file from kuksa.val.v1 protobuf API
lalywr2000 08580c5
Replace mock data file with data type
lalywr2000 9048d21
Update publisher to use data entry
lalywr2000 aba00f9
Replace customized proto file
lalywr2000 5a5839b
Update feeder to use data entry
lalywr2000 181ed0e
Add type casting function definition
lalywr2000 3f29b5c
Update README
lalywr2000 6b2e687
Update license
lalywr2000 f6ec7e3
Remove ecal2val for pre-commit
lalywr2000 f390968
Upload ecal2val for pre-commit check
lalywr2000 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
||
pub.send(protobuf_message) | ||
print("{} published".format(description)) | ||
|
||
time.sleep(1) | ||
|
||
ecal_core.finalize() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.?