Sensors act as the eyes, ears, and even touch of the robot, providing essential data about the world around it, and enabling the robot to interact with the environment autonomously.
In VEXcode VR, using sensors to code the VR Robot can significantly enhance its performance.
The Role of VR Robot Sensors
In the Coral Reef Cleanup activity, the VR Robot is equipped with various sensors for autonomous programming.
- Eye Sensors
The VR Robot has a Front Eye Sensor and a Down Eye sensor. These sensors can detect if there is an object present as well as detect color (red, green, blue, none). In the Coral Reef Cleanup activity, we can harness the Down Eye Sensor to detect the blue boundary using the DownEye detects blue block(Image 1).
- Distance Sensors
The Distance Sensor on the VR Robot can detect if there is an object in front of the VR Robot and report the distance between the VR Robot and the nearest object.
In the Coral Reef Cleanup activity, we use the Distance Sensor to detect if there is a piece of trash in front of the VR Robot by using the FrontDistance found object block (Image 2), and get the distance between the VR Robot and the nearest trash by using the FrontDistance Reporter block (Image 3).
Take actions based on sensor data
Once we grasp the sensor’s capabilities, we can code the robot to make decisions and perform specific actions based on the sensor data.
Imagine the actions a human will take when collecting trash on the Playground. We only need to replicate the same actions with the VR Robot by coding it to perform the actions based on Sensor data.
These actions can be:
-
If the Down Eye sensor detects blue color ( the blue boundary), drive reverse for a certain distance to avoid falling off the side of the collecting area.
-
If the distance sensor detects a piece of trash in front of the robot, use the FrontDistance Reporter block as the parameter of the drive for block to drive the robot forward for a certain distance to collect it.
Note: To use the FrontDistance Reporter block as the parameter of the drive for block, drag the FrontDistance Reporter block into the circle space of the drive for block (image 5).
- Or if the distance sensor detects a piece of trash in front of the robot, drive the robot forward to collect trash on its way until reaching the boundary.
Trash Collection Algorithm
To collect as much trash as possible before the batteries run out, we can use sensor data to create an algorithm to improve the robot’s performance in the Coral Reef Cleanup activity. The following algorithms are some examples.
Algorithm 1: Drive the robot forward to collect trash until the blue boundary is detected, then drive the robot in reverse for a certain distance and turn to avoid driving into the coral reef. Use the Forever loop to repeat the above actions to code the robot to collect trash continuously and avoid falling off the side of the collecting area.
Algorithm 2: Turn the robot to check if there is a piece of trash in front of it. If a piece of trash is detected, drive the robot forward to the trash to collect it. Use the Forever loop to repeat the above actions to code the robot to collect trash continuously.
Algorithm 3: Turn the robot to check if there is a piece of trash in front of it. If a piece of trash is detected, drive the robot forward to the blue boundary collecting trash along the way. Use the Forever loop to repeat the above actions to code the robot to collect trash continuously.
In addition, as trash keeps randomly falling into the collecting area, to improve the efficiency of trash collection, we can code the robot to wait for a certain period to accumulate more trash on the Playground before initiating the collection actions.
There is not only one way to solve a problem. By being creative and flexible in our approach to using sensors, we can effectively crack the challenges at hand.
Please let us know if you have any questions, comments, or feedback. Thank you!