Skip to content

Distance Sensor

Distance Sensor

By default, Distance Sensor points to the front of the vehicle. It can be pointed in any direction by modifying the settings

Configurable Parameters -

Parameter Description
X Y Z Position of the sensor relative to the vehicle (in NED, in meters) (Default (0,0,0)-Multirotor, (0,0,-1)-Car)
Yaw Pitch Roll Orientation of the sensor relative to the vehicle (degrees) (Default (0,0,0))
MinDistance Minimum distance measured by distance sensor (metres, only used to fill Mavlink message for PX4) (Default 0.2m)
MaxDistance Maximum distance measured by distance sensor (metres) (Default 40.0m)
ExternalController Whether data is to be sent to external controller such as ArduPilot or PX4 if being used (default true)

For example, to make the sensor point towards the ground (for altitude measurement similar to barometer), the orientation can be modified as follows -

"Distance": {
    "SensorType": 5,
    "Enabled" : true,
    "Yaw": 0, "Pitch": -90, "Roll": 0
}

Note: For Cars, the sensor is placed 1 meter above the vehicle center by default. This is required since otherwise the sensor gives strange data due it being inside the vehicle. This doesn't affect the sensor values say when measuring the distance between 2 cars. See PythonClient/car/distance_sensor_multi.py for an example usage.

Client API

Use getDistanceSensorData(sensor name, vehicle name) API to retrieve the current distance measurement and sensor pose.

The simSetDistanceSensorPose API allows changing the pose of a distance sensor at runtime, taking an input pose as a combination of position and a quaternion, always relative to the vehicle (unlike Lidar/GPU Lidar/Echo, the distance sensor does not currently support an External world-relative mode). For example:

distance_sensor_pose = airsim.Pose(airsim.Vector3r(0, 0, 0), airsim.to_quaternion(-1.5708, 0, 0))  #PRY in radians
client.simSetDistanceSensorPose("Distance", distance_sensor_pose)