Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for seat-adjuster example #85

Merged
merged 8 commits into from
Jun 12, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ The `Vehicle App SDK` reduces the effort required to implement Vehicle Apps by u

This includes the following packages:

* [sdv.vehicle_app](./sdv/vehicle_app.py) - Vehicle App abstraction
* [sdv.model](./sdv/model.py) - Vehicle Model ontology
* [sdv.config](./sdv/config.py) - Vehicle App configuration
* [sdv.base](./sdv/base.py) - Base classes for middleware abstraction
* [sdv.dapr](./sdv/dapr) - Dapr middleware integration
* [sdv.conf](./sdv/config.py) - Vehicle App configuration
* [sdv.vehicle_app](./sdv/vehicle_app.py) - Vehicle App abstraction
* [sdv.native](./sdv/native) - Native middleware definition
* [sdv.vdb](./sdv/vdb) - Vehicle Data Broker integration
* [sdv.test](./sdv/test) - Integration test support
* [sdv.util](./sdv/util) - Logging and other utilities
Expand Down Expand Up @@ -52,7 +54,7 @@ These examples demonstrate how to use the Python Vehicle App SDK:
| [Dynamic Rule](./examples/dynamic-rule/) | Create a Vehicle Data Broker rule with the fluent query methods.
| [Static Rule](./examples/static-rule/) | Create a Vehicle Data Broker rule with the subscribe_to_data_point annotation.
| [VDB Queries](./examples/vdb-queries/) | Demonstrates various aspects of creating Vehicle Data Broker queries.
| [Seat Adjuster](./examples/seat-adjuster/) | Seat-Adjuster App that demonstrates MQTT communication and seat control via actuator data points.<br>(i) This example can only be run from the [Vehicle App Template](https://github.com/eclipse-velocitas/vehicle-app-python-template).
| [Seat Adjuster](./examples/seat-adjuster/) | Seat-Adjuster App that demonstrates MQTT communication and seat control via actuator data points.<br>:point_right: This example can only be run from the [Vehicle App Template](https://github.com/eclipse-velocitas/vehicle-app-python-template). :point_left:

All examples (except the Seat Adjuster) can be run via
```bash
Expand Down
6 changes: 4 additions & 2 deletions examples/seat-adjuster/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ FROM --platform=$TARGETPLATFORM python:3.10-slim-bullseye@sha256:1ee6094f44c6778
RUN apt-get update && apt-get install -y binutils

COPY ./app /app
COPY ./gen/vehicle_model /vehicle_model
BjoernAtBosch marked this conversation as resolved.
Show resolved Hide resolved

# Remove this installation for Arm64 once staticx has a prebuilt wheel for Arm64
RUN /bin/bash -c 'set -ex && \
Expand All @@ -31,11 +32,12 @@ RUN /bin/bash -c 'set -ex && \
fi'

RUN apt-get install -y git
RUN pip3 install --no-cache-dir pyinstaller \
RUN pip3 install --no-cache-dir pyinstaller==5.9.0 \
&& pip3 install --no-cache-dir patchelf==0.17.0.0 \
&& pip3 install --no-cache-dir staticx \
BjoernAtBosch marked this conversation as resolved.
Show resolved Hide resolved
&& pip3 install --no-cache-dir -r ./app/requirements.txt \
&& pip3 install --no-cache-dir -r ./app/requirements-links.txt
&& pip3 install --no-cache-dir -r ./app/requirements-links.txt \
&& pip3 install --no-cache-dir /vehicle_model

WORKDIR /app

Expand Down
46 changes: 42 additions & 4 deletions examples/seat-adjuster/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,48 @@
# Seat-adjuster example

:warning: This example is currently not executable from within the vehicle-app-pytthon-sdk's devContainer. Please use the "import example" feature of the related [vehicle-app-python-template repository](https://github.com/eclipse-velocitas/vehicle-app-python-template). Also, building the docker container for this example needs to be done after the import within the Python template's devContainer.

## Launch the seat-adjuster example

```bash
cd examples/seat-adjuster/src
## Run this example from your Python app development repo

dapr run --app-id seatadjuster --app-protocol grpc --app-port 50008 --config ../../.dapr/config.yaml --resources-path ../../.dapr/components python3 main.py
It is possible to import and run this example from your app development repository, which you already have created or could create from our [vehicle-app-python-template repository](https://github.com/eclipse-velocitas/vehicle-app-python-template).

1. Importing the example

Use the VS Code task `Import example app from SDK` (to get there press `Ctrl+Shift+P` and select `Tasks: Run Task`) and choose `seat-adjuster` from the list.

:warning: Make sure you have commited or stash all your possible changes within the `app` folder, because the files of that folder will be overwritten by the files of this example.

2. Running this example with Dapr middleware

Use the VS Code tasks `Local Runtime - Up` and `Local Runtime - Run VehicleApp` to start the necessary runtime components and this app itself.

Alternatively, the app can also be deployed in a k3d runtime - use task `K3D Runtime - Deploy VehicleApp`.


## Executing with "native" middleware (without Dapr runtime)

If you like to run this example without using Dapr as middleware, you may need to provide some environment variables to the seat-adjuster process, which define the middleware type being _native_ and where to find the required runtime components:

| Variable name | Default value | Description
|---------------------------------|----------------------------|-------------
| `SDV_MIDDLEWARE_TYPE` | `"dapr"` | Defines the middleware type -> set to `"native"`
| `SDV_MQTT_ADDRESS` | `"mqtt://localhost:1883"` | Address (and port) of the MQTT broker
| `SDV_VEHICLEDATABROKER_ADDRESS` | `"grpc://localhost:55555"` | Address (and port) of the KUKSA Data Broker


## Building a Docker image

This example app provides a Dockerfile to enable creating a Docker container image to run it.
The image must be build passing the repositories root folder as build context, e.g.:

``` bash
docker build -f app/Dockerfile .
```

:warning: If your build environment works behind (corporate) **proxy**, please remember telling docker your proxy configuration.
If you've set the respective environment variables, this might work:

``` bash
docker build -f app/Dockerfile . --build-arg http_proxy --build-arg HTTP_PROXY --build-arg https_proxy --build-arg HTTPS_PROXY --build-arg no_proxy --build-arg NO_PROXY
```
2 changes: 1 addition & 1 deletion examples/seat-adjuster/requirements-links.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
git+https://github.com/eclipse-velocitas/vehicle-app-python-sdk.git@v0.9.0
git+https://github.com/eclipse-velocitas/vehicle-app-python-sdk.git@v0.9.1
8 changes: 2 additions & 6 deletions examples/seat-adjuster/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def __init__(self, vehicle_client: Vehicle):

async def on_start(self):
"""Run when the vehicle app starts"""
await self.Vehicle.Cabin.Seat.Row(1).Pos(1).Position.subscribe(
await self.Vehicle.Cabin.Seat.Row1.Pos1.Position.subscribe(
self.on_seat_position_changed
)

Expand All @@ -62,11 +62,7 @@ async def on_seat_position_changed(self, data: DataPointReply):
await self.publish_event(
response_topic,
json.dumps(
{
"position": data.get(
self.Vehicle.Cabin.Seat.Row(1).Pos(1).Position
).value
}
{"position": data.get(self.Vehicle.Cabin.Seat.Row1.Pos1.Position).value}
),
)

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@

setup(
name="sdv",
version="0.9.0",
version="0.9.1",
description="A Python SDK for Vehicle app",
long_description=long_description,
long_description_content_type="text/markdown",
Expand Down