Distance Sensing#
To make Distance Sensor blocks appear in VEXcode V5, a Distance Sensor must be configured in the Devices window.
For more information, refer to these articles:
Object Distance#
The Object Distance block is used to report the distance of the nearest object from the Distance Sensor.
([Distance10 v] object distance in [mm v])
The Object Distance block reports a range from 20mm to 2000mm.
Choose which Distance Sensor to use.
Choose what units to report in: millimeters (mm) or inches.
In this example, the Distance Sensor will report the current distance between it and the closest object.
when started :: hat events
print ([Distance10 v] object distance in [mm v]) on [Brain v] ◀ and set cursor to next row
Object Velocity#
The Object Velocity block is used to report the current velocity of an object in meters per second (m/s).
([Distance10 v] object velocity in m/s)
Choose which Distance Sensor to use.
In this example, the Distance Sensor will report the current velocity of an object moving in front of it.
when started :: hat events
print ([Distance10 v] object velocity in m/s) on [Brain v] ◀ and set cursor to next row
Object Size Is#
The Object Size Is block is used to report if the Distance Sensor detects the specified object size.
<[Distance10 v] object size is [small v] ?>
The Distance Sensor determines the size of the object detected (none, small, medium, large) based on the amount of light reflected and returned to the sensor.
The Object Size Is block reports True
when the Distance Sensor detects the specified size.
The Object Size Is block reports False
when the Distance Sensor doesn’t detect the specified size.
Choose which Distance Sensor to use.
Choose which size of the object you want the Object Sensor to check for.
small
medium
large
In this example, if the Distance Sensor detects a small object, it will drive forward until the object is large.
when started :: hat events
[Check if the Distance Sensor sees a small object .]
if <[Distance10 v] object size is [small v] ?> then
[If a small object is detected, drive forward.]
drive [forward v]
[Wait until the small detected object is large.]
wait until <[Distance10 v] object size is [large v] ? >
[When the object size is large, stop driving.]
stop driving
end
Distance Sensor Found Object#
The Distance Sensor Found Object block is used to report if the Distance Sensor sees an object within its field of view.
<[Distance10 v] found an object?>
The Distance Sensor Found Object block reports True
when the Distance Sensor sees an object or surface within its field of view.
The Distance Sensor Found Object block reports False
when the Distance Sensor does not detect an object or surface.
Choose which Distance Sensor to use.
In this example, when the Distance Sensor detects an object, it will print a message to the Brain.
when started :: hat events
[Don't print the message until the Distance Sensor finds an object.]
wait until <[Distance10 v] found an object?>
print [Distance Sensor has detected an object.] on [Brain v] ◀ and set cursor to next row