eclipse-velocitas / vehicle-app-python-template

Vehicle App template for Python
Apache License 2.0
17 stars 25 forks source link

[Q]: Why all vehicle signals other than the speed are zeros? #178

Closed MohammedShokr closed 1 year ago

MohammedShokr commented 1 year ago

Question

When I try to get any data point value from the vehicle model, I get 0 for numerical data points and false for Boolean ones.

Notably, I subscribed to the data point in the on_start() function and I added the data point name in the AppManifest.json

kse3hi commented 1 year ago

Hello @MohammedShokr , You need to have provider for particular datapoint. Currently we have "can feeder" that provides set of datapoint values based on recorded dataset. Also you can use our Mock Service that provides framework to generate expected behaviour for particular datapoints.

CanFeeder information: https://eclipse.dev/velocitas/docs/concepts/development_model/val/#data-providers--data-feeders Service Integration: https://eclipse.dev/velocitas/docs/tutorials/prototyping/service_integration/

MohammedShokr commented 1 year ago

Hello @kse3hi , Can you please elaborate more? For example, if I want to access the vehicle acceleration, what are the exact steps that I should follow?

glm2bg commented 1 year ago

Hello @MohammedShokr , By default Vehicle.Speed is set to have values by the Mock Service. You can change the "mock.py" file to mock more datapoints. You can see everything about the service here: https://github.com/eclipse/kuksa.val.services/blob/main/mock_service/README.md

If by any chance you do not have a "mock.py" file in your repository, simply use this one as a template and add it to the root directory of your repository. mock.py: https://github.com/eclipse/kuksa.val.services/blob/main/mock_service/mock.py

After you add the file, start the app and you should see values of the particular data point you mocked in the "mock.py". If you have any problems, please don't hesitate to ask.

MohammedShokr commented 1 year ago

Hello @glm2bg, My app didn't contain the mock.py file, I added it as you said but nothing changed. I also added the lib folder as I saw that mock.py calls files from the lib folder.

I also noticed that the values of the speed in the app differs from the values in the mock.py file so I think the app doesn't see the file.

dennismeister93 commented 1 year ago

Hi @MohammedShokr could you give use a bit more context about your state of the app?

As soon as we get a bit more understanding of what you want to achieve we can easily guide you how to resolve your issue! :) Thanks!

MohammedShokr commented 1 year ago

Hi, @dennismeister93,

I attached the mock.py, AppManifest.json and vapp.py contents as PDF files. PS: When I add the mock.py file to my repository, even the speed stops changing.

AppManifest.pdf mock.pdf vapp.pdf

dennismeister93 commented 1 year ago

Hi @MohammedShokr, Thanks for giving us more information about your code. After using your components I checked the logs inside ./logs/runtime-local/mockservice.txt

== APP == INFO:mock_service:Feeding 'Vehicle.Cabin.Seat.Row1.Pos1.Position' with value 0
== APP == ERROR:base_service:Failed to register datapoints
== APP == Traceback (most recent call last):
== APP ==   File "/lib/baseservice.py", line 106, in _on_broker_connectivity_change
== APP ==     self.on_databroker_connected()
== APP ==   File "/mockservice.py", line 85, in on_databroker_connected
== APP ==     self._feed_initial_values()
== APP ==   File "/mockservice.py", line 139, in _feed_initial_values
== APP ==     self._set_datapoint(
== APP ==   File "/mockservice.py", line 221, in _set_datapoint
== APP ==     setattr(
== APP == TypeError: 'float' object cannot be interpreted as an integer
== APP == INFO:base_service:[127.0.0.1:45129] Connectivity changed to: ChannelConnectivity.READY

Both of your added datapoints inside the mock.py have a wrong initial_value.

Please use the following configuration for the desired behaviour of your mocked datapoints:

For Vehicle.Chassis.Accelerator.PedalPosition please just use an int and not a float:

mock_datapoint(
    path="Vehicle.Chassis.Accelerator.PedalPosition",
    initial_value=0,
    behaviors=[
        create_behavior(
            trigger=EventTrigger(EventType.ACTUATOR_TARGET),
            action=create_set_action("$event.value"),
        )
    ],
)

For Vehicle.IsMoving there are 2 problems:

  1. if you would like to configure it like this you have to use the correct python boolean type spelling "False" which you could also see at the very bottom of the mock.py
  2. Vehicle.IsMoving is a sensor and not an actuator so you wont be able to set the value through the VAPP itself, the mockservice needs to do it with a specific behavior. Right now the mockservice itself has a bug to set exactly this, but we are aware of this and it will be fixed. To progress within your app you can just use any other actuator value as a replacement until you can use the sensor
mock_datapoint(
    path="Vehicle.IsMoving",
    initial_value=False,
    behaviors=[
        create_behavior(
            trigger=EventTrigger(EventType.ACTUATOR_TARGET),
            condition=lambda ctx: get_datapoint_value(ctx, "Vehicle.Speed") > 0,
            action=create_set_action(True),
        ),
    ],
)

Try this out for now and do not hesitate to come back with additional questions!

Thank you! :)

MohammedShokr commented 1 year ago

Hi @dennismeister93,

I sincerely appreciate your detailed response. Now, the mock service is up and running. However, it seems that the app is only receiving the speed signal, while all other signals are assigned their initial values and remain unchanged.

To provide further context, I have attached a snapshot of the terminal and the ./logs/mockservice.txt file.

Thank you once again for your assistance.

Logs-Mockservice1 Logs-Mockservice2 Terminal

dennismeister93 commented 1 year ago

Hi @MohammedShokr,

Relating to your code I think everything looks like it should now. With the correct configuration in your mock.py you are now able to set ACTUATORS within your vehicle application. As I already stated in my last comment, you have to configure actuators and no sensor until now.

Inside your main.py you already get all the initial values in your subscriptions.

If you decided for your actuator datapoints you can now for example do the following in your main.py

self.Vehicle.Chassis.ParkingBrake.IsEngaged.set(True)

This would than also trigger subscriptions if you set them for this datapoint.

MohammedShokr commented 1 year ago

Hi @dennismeister93, Yes now I can set ACTUATORS but I am talking about sensors like the Accelerator.PedalPosition in my app. Its value doesn't change from 0. I tried different sensors but none of them is working except for the Vehicle.speed.

dennismeister93 commented 1 year ago

Hi @MohammedShokr

as stated in my previous comments:

For Vehicle.IsMoving there are 2 problems:

...

  1. Vehicle.IsMoving is a sensor and not an actuator so you wont be able to set the value through the VAPP itself, the mockservice needs to do it with a specific behavior. Right now the mockservice itself has a bug to set exactly this, but we are aware of this and it will be fixed. To progress within your app you can just use any other actuator value as a replacement until you can use the sensor ...

Relating to your code I think everything looks like it should now. With the correct configuration in your mock.py you are now able to set ACTUATORS within your vehicle application. As I already stated in my last comment, you have to configure actuators and no sensor until now.

If you are just developing your VAPP and dont test it with real hardware/data you could for now just use an actuator which can be replaced after the mockservice supports setting values of sensors!

Regards :)

dennismeister93 commented 1 year ago

I think your question is already answered in this issue :) If you have any further questions please do not hesitate to create either another issue or contact us directly via Gitter