Distance#
Introduction#
The Distance Sensor allows your robot to detect the presence of an object and measure its distance.
Below is a list of available blocks:
Distance found object? – Returns whether any object is currently detected.
object distance – Returns the distance of the nearest object from the Distance Sensor.
Distance found object?#
The Distance found object? block returns a Boolean indicating whether the Distance Sensor has detected an object within 2000 mm.
True – The Distance Sensor has detected an object.
False – The Distance Sensor has not detected an object.
<[FrontDistance v] found an object?>
Parameters |
Description |
|---|---|
distance sensor |
Which Distance Sensor to use. |
Example
when started :: hat events
[Spin until the Distance Sensor detects an object.]
turn [right v]
wait until <[FrontDistance v] found an object?>
stop driving
object distance#
The object distance returns the distance of the nearest object from the Distance Sensor.
([FrontDistance v] distance in [mm v])
Parameters |
Description |
|---|---|
distance sensor |
Which Distance Sensor to use. |
unit |
The unit of measurement, which can be one of the following:
|
Example
when started :: hat events
[Don't print the message until the Distance Sensor detects an object.]
turn [right v]
wait until <[FrontDistance v] found an object?>
stop driving
print ([FrontDistance v] distance in [mm v]) ▶