Overview
BeamNG.tech ships with a simulated RADAR sensor, which can provide various types of RADAR readings and the raw data with which the user can process themselves.
Note: For now, we recommend to use the RADAR sensor through the BeamNGPy interface, which provides ready-made functions to process and visualise the data. The data returned to Lua is currently in binary string format.
Usage
RADAR sensors are exposed to Lua through the sensors extension in the tech folder. Using this API, a RADAR sensor can be created with various desired properties, and either attached to a vehicle or to a fixed point on the map.
We can create the RADAR with the following command:
sensorId = extensions.tech_sensors.createRadar(vehicleId, args)
Args:
vehicleID(int): The vehicle ID. This can be nil if the RADAR is not to be attached to any 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 RADAR with args being an empty table. What follows is a complete list of these arguments:
updateTime(float): How often the RADAR sensor should update its readings in the simulator (in seconds).
updatePriority(float): A scheduling priority value for this RADAR sensor, in range 0 to 1. 0 is highest priority, 1 is least.
pos(Point3F): The position of the RADAR sensor either in vehicle space (if attached to vehicle) or in world space (if fixed to the map).
dir(Point3F): The forward direction in which the RADAR sensor points.
up(Point3F): The up direction of the RADAR sensor (with ‘dir’, provides a frame of reference for the sensor).
size(table): The horizontal and vertical resolution of the RADAR sensor.
fovY(float): The vertical field of view of the RADAR sensor, in degrees.
nearFarPlanes(table): The near and far plane distances of the RADAR sensor, in metres.
rangeRoundness(float): The general roundness of the RADAR sensors range shape. Can be negative.
rangeCutoffSensitivity(float): A cutoff sensitivity parameter for the RADAR sensor range-shape.
rangeShape(float): The shape of the RADAR sensor range-shape in the range [0, 1], going from conical to spherical.
rangeFocus(float): The focus parameter for the RADAR sensor range-shape.
rangeMinCutoff(float): The minimum cut-off distance for the RADAR sensor range-shape. Nothing closer than this will be detected.
rangeDirectMaxCutoff(float): The maximum cut-off distance for the RADAR sensor range-shape. This parameter is a hard cutoff - nothing further than this will be detected, although other parameters can also control the maximum distance.
range_bins(int): The number of bins to use in the range dimension (when processing the data to image).
azimuth_bins(int): The number of bins to use in the azimuth dimension (when processing the data to image).
vel_bins(int): The number of bins to use for velocity (when processing the data to image).
range_min(float): The minimum range which can be detected by the RADAR sensor, in metres.
range_max(float): The maximum range which can be detected by the RADAR sensor, in metres.
half_angle_deg(float): The ‘half angle’ azimuth range, in degrees. Eg, if the azimuth range is 140 degrees, this should be 70 degrees, etc.
isVisualised(bool): A flag which indicates if the RADAR sensor should be visualised.
isStatic(bool): True if the RADAR sensor is fixed to a point on the map, false if it is attached to a vehicle.
isSnappingDesired(bool): True if the RADAR sensor position should be forced onto the surface of the vehicle, at its closest vehicle point. This is useful if finding it hard to have the RADAR on the vehicle itself. False, otherwise, eg if the RADAR should be suspended at a fixed point relative to the vehicle.
isForceInsideTriangle(bool): Used with isSnappingDesired. True, if the RADAR should be forced to be inside its nearest vehicle triangle. Otherwise false.
Returns: sensorId(int): The unique Id number of this sensor, in order to refer to it later eg when closing it.
points = extensions.tech_sensors.getRadarReadings(sensorId)
Args:
sensorId(int): The ID number of the RADAR sensor.
Returns: table: The most-recent data from the RADAR sensor.
sensorDirection = extensions.tech_sensors.getRadarSensorDirection(sensorId)
Args:
sensorId(int): The ID number of the RADAR sensor.
Returns: sensorDirection(Point3F): The current direction of the RADAR sensor.
maxPendingGpuRequests = extensions.tech_sensors.getRADARMaxPendingGpuRequests(sensorId)
Args:
sensorId(int): The ID number of the RADAR sensor.
Returns: maxPendingGpuRequests(int): The maximum number of pending GPU requests for this RADAR sensor.
requestedUpdateTime = extensions.tech_sensors.getRADARRequestedUpdateTime(sensorId)
Args:
sensorId(int): The ID number of the RADAR sensor.
Returns: requestedUpdateTime(float): The current requested update time used by this RADAR sensor.
updatePriority = extensions.tech_sensors.getRADARUpdatePriority(sensorId)
Args:
sensorId(int): The ID number of the RADAR sensor.
Returns: updatePriority(float): The current update priority used by this RADAR sensor.
extensions.tech_sensors.setRADARMaxPendingGpuRequests(sensorId, maxPendingGpuRequests)
Args:
sensorId(int): The ID number of the RADAR sensor.
maxPendingGpuRequests(int): The new maximum number of pending GPU requests for this RADAR sensor.
extensions.tech_sensors.setRADARRequestedUpdateTime(sensorId, requestedUpdateTime)
Args:
sensorId(int): The ID number of the RADAR sensor.
requestedUpdateTime(float): The new requested update time for this RADAR sensor.
extensions.tech_sensors.setRADARUpdatePriority(sensorId, updatePriority)
Args:
sensorId(int): The ID number of the RADAR sensor.
updatePriority(float): The new update priority for this RADAR sensor.
The following three functions can be used to send ad-hoc polling requests to a RADAR sensor. This is when we just want an occasional reading. We need to first send a request using sendRADARRequest
, then wait for it. We can check it is complete using isRequestComplete
(see below), then retrieve it using collectRADARRequest
.
requestId = extensions.tech_sensors.sendRADARRequest(sensorId)
Args:
sensorId(int): The ID number of the RADAR sensor.
Returns: The unique Id number of the ad-hoc sensor polling request which is being sent.
isComplete = extensions.tech_sensors.isRequestComplete(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.collectRADARRequest(requestId)
Args:
requestId(int): The ID number of the ad-hoc sensor polling request.
Returns: data(table): The RADAR readings.
extensions.tech_sensors.removeSensor(sensorId)
Args:
sensorId(int): The ID number of the RADAR sensor to remove.
Returns: nil.