To achieve this algorithm the NXT needs at least two light sensors, out in front and spaced apart from each other, one on left side and the other located on the right.
We read the value from both sensors, the sensor that reads more light is the direction the NXT should turn. For example, if the left light sensor reads more light than the right one, the NXT would turn or tend towards the left. If both values are almost equal, then the NXT would drive straight.
pseudocode:
read left_light sensor
read right_light sensor
if left_light sensor detects more light than right_light sensor
then turn robot left
if right_light sensor detects more light than left_light sensor
then turn robot right
if right_light sensor detects about the same as left_light sensor
then robot goes straight
loop
Modification to give the ability to avoid objects will be added. Also, modifications to the turning will be made so the robot will no longer just have the three modes of turn left, turn right, and go straight. Instead will have commands like 'turn left by 10 degrees' or 'turn right really fast'.
pseudocode:
read left_light sensor
read right_light sensor
left_motor = (left_light sensor - right_light sensor) * arbitrary_constant
right_motor = (right_light sensor - left_light sensor) * arbitrary_constant
loop
pseudocode:
read left_light sensor
read right_light sensor
move left_wheel_speed = right_light sensor * arbitrary_constant
move right_wheel_speed = left_light sensor * arbitrary_constant
Also, I am interested in the ability to use more than a light sensor such as IR emitter/detectors and others.
Time: 6.5 hrs.
No comments:
Post a Comment