OpenSimulationInterface / open-simulation-interface

A generic interface for the environmental perception of automated driving functions in virtual scenarios.
Other
269 stars 125 forks source link

Get OSMPSensorViewIn binary variables in python #680

Closed oskr1709 closed 1 year ago

oskr1709 commented 2 years ago

Describe the problem

I want to get OSMPSensorViewIn.base.lo , OSMPSensorViewIn.base.hi and OSMPSensorViewIn.base.size from the serialization:

bytes_buffer = sensorview.SerializeToString()
result = struct.pack("<L", len(bytes_buffer))

That is in order to be the input of an dummy sensor fmu (https://github.com/OpenSimulationInterface/osi-sensor-model-packaging/tree/master/examples/OSMPDummySensor)

Describe what you have already tried

I´m working with this example: https://opensimulationinterface.github.io/open-simulation-interface/ and then got the binary variables in this way:

OSMPSensorViewIn_base_lo = int.from_bytes(result, byteorder='little') OSMPSensorViewIn_base_hi = int.from_bytes(result, byteorder='big') OSMPSensorViewIn_size: = len(bytes_buffer)

it gives me an error that the variable exceeds max system size while setting integers of fmu or it crashed in the OSMPDummySensor line: data.ParseFromArray(buffer,integer_vars[FMI_INTEGER_SENSORVIEW_IN_SIZE_IDX]);

Describe your research

As I mention, I tried with int.from_bytes (https://docs.python.org/3/library/stdtypes.html) and len of bytes buffer I have no found similar problem or approach in any forum

Ask your question

So my basic question is, how do I Get OSMPSensorViewIn binary variables in python to set for dummy sensor fmu?

Does anybody know the correct procedure to do this in python please? Thanks in advance for your help