Page 195 - CodePilot V5.0 C8
P. 195
The explanation of the code is as follows:
USING EYE SENSING BLOCKS
The program begins when the when started block is triggered.
The Eye sensing blocks enable the robot to detect colours and objects using its Front or Down Eye The robot’s drive and turn velocity are set to 40% for moderate speed.
sensors. These blocks are located in the Sensing category under Sensing – Eye. A forever loop runs continuously, checking the Front Eye sensor.
Some of the key blocks are as follows: It turns right 90° for green, turns left 90° for blue and stops for red.
Blocks Description
Eye sensor near object? This block detects a specific object (like an object shape USING DISTANCE SENSING BLOCKS
FrontEye is near object? or a symbol) in the robot’s visual field.
Distance sensing blocks use the robot’s distance sensor to measure the space between the robot
Eye Sensor detects [color]? This block detects a specific colour in the robot’s view. and obstacles. These blocks are located in the Sensing - Distance section in the Sensing block
category. Some of the important distance sensing blocks are as follows:
FrontEye detects red ?
Block Description
Eye Sensor brightness in % This block detects the brightness of the surface in front
FrontEye brightness in % of the robot. distance found an object block This block checks if the FrontDistance sensor can see
FrontDistance found an object? something in front of the robot.
Program 5 Make the robot move and respond according to the detected colour. distance from block This block measures how far the robot is from the object
This program shows how a robot uses colour detection to make movement decisions. When it FrontDistance in mm from the front in millimetres.
detects green, it turns right 90°, blue makes it turn left 90° and red makes it stop. The code and
its output are shown below: Program 6 Make the robot navigate a Maze.
when started The task is for the robot to navigate through a maze and reach the red goal tile at the top of the
playground (in our case Dynamic Wall Maze) using its sensors and programmed logic.
set drive velocity to 40 %
The code and output of the given task are as follows:
set turn velocity to 40 %
drive forward
when started
forever
set drive velocity to 80 %
if FrontEye detects green ? then
set turn velocity to 80 %
turn right for 90 degrees
turn right for 90 degrees
drive forward
while not DownEye detects red ?
if FrontDistance in mm > 200 then
if FrontEye detects blue ? then
drive forward for 200 mm
turn left for 90 degrees
turn right for 90 degrees
drive forward
else
if FrontEye detects red ? then turn left for 90 degrees
stop driving
stop driving
193
VEXcode VR: Drive, Sense and Create

