Ultrasonic

Overview

BeamNG.tech ships with a simulated Ultrasonic sensor which measures distances to nearby surfaces, commonly as an aid to vehicle parking. The range and detection sensitivity are physically-based and customisable by the user. Single or multiple ultrasonic sensors can be attached to vehicles or places at fixed locations.

Usage

Ultrasonic sensors are exposed to Lua through the sensors extension in the tech folder. Using this API, an ultrasonic sensor can be created with various range and detection properties, and either attached to a vehicle or to a fixed point on the map.


sensorId = extensions.tech_sensors.createUltrasonic(vehicleId, sizeX, sizeY, fieldOfViewX, fieldOfViewY, nearPlane, farPlane, rangeRoundness, rangeCutoffSensitivity, rangeShape, rangeFocus, rangeMinCutoff, rangeDirectMaxCutoff, sensitivity, fixedWindowSize, positionX, positionY, positionZ, directionX, directionY, directionZ, isVisualised, isStatic, isSnappingDesired, isForceInsideTriangle)

Args:

vehicleID(int): The vehicle ID.

sizeX(int): The horizontal resolution of the ultrasonic sensor.

sizeY(int): The vertical resolution of the ultrasonic sensor.

fieldOfViewX(float): The horizontal field of view of the ultrasonic sensor, in radians.

fieldOfViewY(float): The vertical field of view of the ultrasonic sensor, in radians.

nearPlane(float): The near plane distance of the ultrasonic sensor, in metres.

farPlane(float): The far plane distance of the ultrasonic sensor, in metres.

rangeRoundness(float): The general roundness of the ultrasonic sensors range shape. Can be negative.

rangeCutoffSensitivity(float): A cutoff sensitivity parameter for the ultrasonic sensor range-shape.

rangeShape(float): The shape of the ultrasonic sensor range-shape in the range [0, 1], going from conical to spherical.

rangeFocus(float): The focus parameter for the ultrasonic sensor range-shape.

rangeMinCutoff(float): The minimum cut-off distance for the ultrasonic sensor range-shape. Nothing closer than this will be detected.

rangeDirectMaxCutoff(float): The maximum cut-off distance for the ultrasonic 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.

sensitivity(float): The sensitivity of the ultrasonic sensor detection.

fixedWindowSize(float): Used with sensitivity to set how sharply the ultrasonic sensor detects surfaces.

positionX(float): The X-component of the ultrasonic sensor either in vehicle space (if attached to vehicle) or in world space (if fixed to the map).

positionY(float): The Y-component of the ultrasonic sensor either in vehicle space (if attached to vehicle) or in world space (if fixed to the map).

positionZ(float): The Z-component of the ultrasonic sensor either in vehicle space (if attached to vehicle) or in world space (if fixed to the map).

directionX(float): The X-component of the direction in which the ultrasonic sensor points.

directionY(float): The Y-component of the direction in which the ultrasonic sensor points.

directionZ(float): The Z-component of the direction in which the ultrasonic sensor points.

isVisualised(bool): A flag which indicates if the ultrasonic sensor should be visualised.

isStatic(bool): True if the ultrasonic sensor is fixed to a point on the map, false if it is attached to a vehicle.

isSnappingDesired(bool): True if the ultrasonic 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 ultrasonic sensor on the vehicle itself. False, otherwise, eg if the ultrasonic sensor should be suspended at a fixed point relative to the vehicle.

isForceInsideTriangle(bool): Used with isSnappingDesired. True, if the ultrasonic sensor should be forced to be inside its nearest vehicle triangle. Otherwise false.


distance = extensions.tech_sensors.getUltrasonicDistanceMeasurement(sensorId)

Args:

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

Returns: distance(float): The most-recent distance measurement from the ultrasonic sensor, in metres.


windowMin = extensions.tech_sensors.getUltrasonicWindowMin(sensorId)

Args:

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

Returns: windowMin(float): The most-recent minimum value of the detection window (used to detect surfaces).


windowMax = extensions.tech_sensors.getUltrasonicWindowMax(sensorId)

Args:

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

Returns: windowMax(float): The most-recent maximum value of the detection window (used to detect surfaces).


activeSensors = extensions.tech_sensors.getUltrasonicActiveSensors()

Args:

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

Returns: activeSensors(table(int)): The ID numbers of all currently active ultrasonic sensors in the simulation.


isVisualised = extensions.tech_sensors.getUltrasonicIsVisualised(sensorId)

Args:

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

Returns: isVisualised(bool): True if the ultrasonic sensor is being visualised, otherwise false.


extensions.tech_sensors.setUltrasonicIsVisualised(sensorId, isVisualised)

Args:

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

isVisualised(bool): A flag which indicates if the ultrasonic sensor should be visualised or not.

Returns: nil.


sensorPosition = extensions.tech_sensors.getUltrasonicSensorPosition(sensorId)

Args:

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

Returns: sensorPosition(Point3F) The current position of the ultrasonic sensor, in world space.


sensorDirection = extensions.tech_sensors.getUltrasonicSensorDirection(sensorId)

Args:

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

Returns: sensorDirection(Point3F): The current direction of the ultrasonic sensor.


radius = extensions.tech_sensors.getUltrasonicSensorRadius(sensorId, distanceFromSensor)

Args:

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

distanceFromSensor(float): The distance from the ultrasonic sensor, at which the radius should be computed.

Returns: radius(float): The radius of the range shape at the given distance from the ultrasonic sensor.


sensorExists = extensions.tech_sensors.ultrasonicSensorExists(sensorId)

Args:

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

Returns: sensorExists(bool): True if the ultrasonic sensor with the given ID number exists, otherwise false.


extensions.tech_sensors.removeUltrasonicSensor(sensorId)

Args:

sensorId(int): The ID number of the ultrasonic sensor which is to be removed.

Returns: nil.


Last modified: 27/6/2022 17:43
On this page:

Any further questions?

Join our discord