Lesson 1: What is a Distance Sensor?
In this Lesson, you will learn what the Distance Sensor is, and why you would use the Distance Sensor with a VR Robot. You will also learn how the Distance Sensor works and how to use the Distance Sensor in a VEXcode VR Python project.
- Identify that the Distance Sensor reports the distance between the sensor itself and the nearest object.
- Identify that the Distance Sensor determines distance by using the time it takes for a pulse of laser light to reflect off an object and return to the sensor.
- Identify that the found_object command reports a Boolean value if the Distance Sensor has found an object or not.
- Identify that the get_distance command reports the distance of the nearest object from the sensor in millimeters (mm) or inches.
- Describe why the Distance Sensor would be used in a project.
The Distance Sensor can detect if there is an object in front of a VR Robot, and if so, how far away that object is from the Distance Sensor. This can be helpful in navigating a maze without continuously bumping into the walls, to avoid an object, or to drive to an object or wall in the Playgrounds.
In this Unit, you will use the Distance Sensor, a sensor that uses a pulse of laser light to detect objects. The Distance Sensor reports the distance between the front of the Distance Sensor on the VR Robot and the nearest object. The Distance Sensor is located in the Front Eye on the VR Robot. Just like the Bumper Sensor, the VR Robot can use the data from the Distance Sensor to make decisions.
The Distance Sensor calculates distance by using the time it takes for a pulse of laser light to reflect off of an object and return to the sensor. The Distance Sensor can be used to detect how far away VR Robot is from the walls in the Wall Maze Playground.
Distance Found Object Command
The Distance Sensor can be used to detect if there is an object (like a wall) in front of it. This data can then be used in a project so the VR Robot can make a decision when the Distance Sensor detects an object.
Use the found_object command in a Python project to check the condition of the Distance Sensor. The found_object command returns Boolean values of True or False, depending on whether an object is detected by the sensor.
- found_object returns True when the Distance Sensor detects an object or surface within its field of view, and within 3000 mm of the sensor.
- found_object returns False when the Distance Sensor does not detect an object or surface within 3000 mm.
The found_object command is typically used with a Control structure, like a while loop, so that the VR Robot can use the data from the Distance Sensor to make a decision.
Get Distance Command
The Distance Sensor can also report the distance of an object, and use that value to make a decision. The get_distance command returns the numeric distance of the nearest object from the front of a VR Robot.
Choose whether the distance is reported in millimeters (mm) or inches by setting the parameter to "MM" or "INCHES."
The get_distance command can be used with other commands, like a while loop, in a project to instruct a VR Robot to drive a certain distance away from (or toward) an object, or to complete an action when a specific distance is reported.
The Distance Sensor and the Wall Maze Problem
Thinking about the Wall Maze Problem, the goal is to have the VR Robot drive while it is far away from a wall. When the VR Robot gets close to a wall, it then needs to stop or turn without touching the wall, in order to continue through the maze. Using the Distance Sensor will allow a VR Robot to drive up to an object without touching it.
In the following example, the VR Robot will drive forward while the Distance Sensor reports that it is greater than 50 millimeters away from an object. Once it is less than 50 millimeters away, the VR Robot will stop driving. Notice that the VR Robot does not touch the wall.
You will notice that the Dashboard displays the value the Distance Sensor is reporting in real time as the project is run. When the value is greater than 50 millimeters, the VR Robot will continue to drive forward.
When the Distance Sensor reports a value of less than 50 millimeters, the VR Robot is near the wall without touching it, and stops driving.
In this example, the get_distance command is used with a comparison operator to return a Boolean value in a loop. You will learn more about the greater than (>) and less than (>) operators in this Unit.