C++ Rev V3 color sensor FRC

In FRC’s C++ we are using a Rev V3 color sensor and when ever we use a loop, while do while or for, the sensor won’t sense the colors it is looking at anymore. We are using the example code provided on Rev’s website.

Can you please post your code?


Colorbuddy is a motor (the last line). We tried multiple different while loops there’s just one example of one we tried that doesn’t work. They sensor won’t pick up any other colors except the first one it saw

Short answer: no loops! loops = bad!!

Long answer: The robot code runs in a large time-controlled loop. The idea is that all of your code needs to be able to run over and over again, making micro-adjustments then running again. By adding a loop, you effectively stop execution of that main loop, and therefore stop execution of the rest of your code (including the code that’s interacting with your color sensor).

Super short TL;DR answer: DON’T USE LOOPS!

I’m not screaming at you or anything, just trying to drill it in for everyone that reads this

3 Likes

Another problematic code smell thing I see is that you have a while condition that assigns a variable as the condition.

I don’t know exactly what you’re trying to do on line 165, but:

while(matchedColor = kYellowTarget)

is probably not doing what you want it to do ,and if that is what you want to do, there is probably a more clear, concise way of doing it.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.