Powertrain

Overview

The Powertrain sensor provides the user with the ability to retreive all powertrain data from the vehicle, at a rate up to 2000Hz.

The sensor data readings are a collection of time-stamped tables and will contain all powertrain properties for the vehicle to which this sensor is attached (this may vary somewhat between different vehicles).

Usage

The Powertrain sensor code is written in Lua directly, rather than C++. It has a very similar API to the other sensors in our suite.

For other usage examples with this sensor, please look at the beamNGpy scripts.


sensorId = extensions.tech_sensors.createPowertrainSensor(vehicleId, args)

Args:

vehicleID(int): The vehicle ID. This cannot be nil - the Powertrain sensor must be attached to a vehicle.

The args parameter is a Lua table containing as many of the following properties as required. If any property is not set manually then a default value is used, so it is entirely possible to create the Powertrain sensor with args being an empty table. What follows is a complete list of these arguments:

GFXUpdateTime(float): How often the Powertrain sensor should update its readings in the simulator (in seconds). This determines how often the user will be able to retrieve a new reading from the sensor.

physicsUpdateTime(float): How often in the simulator’s physics step, we should update the Powertrain readings (in seconds). This parameter should be smaller than GFXUpdateTime, and can be as small as 1/2000 seconds, since this is currently the rate at which the physics steps cycles. This value determines how often we poll the Powertrain to get a snapshot of data at a given time, so the smaller this is, the more accurate the readings will be (at the cost of computation load in the simulation - for a small number of sensors this should not matter, either way).

Returns: sensorId(int): The unique Id number of this sensor, in order to refer to it later eg when closing it.


readings = extensions.tech_sensors.getPowertrainReadings(sensorId)

Args:

sensorId(int): The ID number of the Powertrain sensor.

Returns: readings(vec3): The latest readings from the sensor.


extensions.tech_sensors.setPowertrainUpdateTime(sensorId, updateTime)

Args:

sensorId(int): The ID number of the Powertrain sensor.

updateTime(float): The new update time for this sensor.

Returns: nil


The following three functions can be used to send ad-hoc polling requests to a Powertrain sensor. This is for when we just want an occasional reading. We need to first send a request using sendPowertrainRequest, then wait for it. We can check it is complete using isVluaRequestComplete (see below), then retrieve it using collectPowertrainRequest.

requestId = extensions.tech_sensors.sendPowertrainRequest(sensorId)

Args:

sensorId(int): The ID number of the Powertrain sensor.

Returns: The unique Id number of the ad-hoc sensor polling request which is being sent.


isComplete = extensions.tech_sensors.isVluaRequestComplete(requestId)

Args:

requestId(int): The ID number of the ad-hoc sensor polling request to check on.

Returns: isComplete(bool): True if the ad-hoc polling request has been completed, otherwise false.


data = extensions.tech_sensors.collectPowertrainRequest(requestId)

Args:

requestId(int): The ID number of the ad-hoc sensor polling request.

Returns: data(vec3): The Powertrain sensor readings.


extensions.tech_sensors.removePowertrain(sensorId)

Args:

sensorId(int): The ID number of the Powertrain sensor to remove.

Returns: nil.


Last modified: 13/12/2022 12:06
On this page:

Any further questions?

Join our discord