Optical Sensor Not Working

When I run this program, I have four robots that will not drive forward. I’ve tried:

  • Taking the robots in the hall where there is NOTHING in front of them

  • Switching out optical sensors

  • Robots will run if just a drive forward block is used

  • Optical sensor on Dashboard shows a setting of NEAR for 3 of them and one robot flickers NEAR/FAR

  • One robot just updated, but it is still not working properly

Again, the robots will not drive forward at all. Is there a setting or something that needs changed? The rest of the robots work just fine. These four are not driving.

Optical Sensor

Hello Cristina Jones!

It looks like the problem is in the logic of the code. From the looks of it, you are trying make the robot drive forward until the optical sensor detects an object then turn right 90* and continue driving forward.

The main reason the robot isn’t driving forward is because “drive block” image is non blocking command. Meaning the command is going to run until another command is ready to execute. So it technically skipping to next command every time, thus never executing the drive forward command.

To get best use of “drive block”, I recommend combining it with “wait until” block
image. This will wait until given conditions are met to execute the next command.

For example, this should work with no problem:

If you have any questions, please do let me know.

Thank you!

1 Like

Unfortunately, that still does not work. I tried the code you shared with two robots. It worked with one but did not work with the other. View this video of the robots in action. Please advise.

Looking at the video it looks like the sensor is broken. Possibly that gasket that covers IR has shifted and blocking the sensor, thus it is always returning TRUE for found an object?. Which is why the robot is turning forever. So the optical sensor needs to be replaced.

Please contact support to possibly RMA the sensor at: Support - VEX Robotics

Thank you!