I’m at a total loss on how to program the color sensor to do anything useful. I need a motor to spin until a certain color is read. Can anyone please give me any guidance beyond the sample code that rev published?
Again: We got the sample Labview code that rev robotics published to work. It reads and displays the color values like gangbusters. But where do we go from here.
All of the info about programming the other sensors hasn’t been terribly useful.
Once again, all the sample code on https://github.com/REVrobotics/Color-Sensor-v3-Examples for Labview is fine; it works to read to and show the colors. We need to know how to use the color sensor to control things like motors.
Growing weary…
PS: we definitely checked out, downloaded, installed and sucessfully ran the sample code from https://github.com/REVrobotics/Color-Sensor-v3-Examples
A lot of programming is breaking down a problem into manageable steps.
Do you know how to run a motor?
Do you know how to tell if the color sensor is detecting a certain color?
Do you know how to stop a motor on demand?
1 Like
I can run a motor and make it stop on demand.
I can only tell what the color sensor reads in the sample code from rev. I cannot find how to place the sensor code on begin or teleop VIs.
Read the sensor in a loop in Periodic Tasks.vi and write the color to a variable you created in “Robot Global Data.vi”.
Now in teleop you can simply see the color the sensor sees by reading the RGD variable and control your motor appropriately. There are other ways to go about it but this is the easiest to get going.
You can do the color check in either Teleop or Periodic tasks.
Did you end up with something like this in Begin?

or

and something like this in Teleop?

To make a decision and drive or stop driving a motor based on the “Matched Color Name”
You have to use the GameData to do a comparison check.
You can simplify the color names by changing them from “Green” to “G” to match the GameData you’ll be receiving.
It will also depend on where your color sensor will be pointing.
Most teams will not be looking at the same spot on the color wheel as the field sensor, so you will have to translate the GameData color into the corresponding color where the robot is.
E.g., if the GameData color is Yellow, your robot may be looking for Green (2 colors away from the field sensor).
In this photo, the field sensor is in the aluminum bar running across the top of the color wheel,
but the robot may be looking at the overhanging edge at the top or bottom of the photo.
So, when yellow is under the field sensor, green will be at the overhanging edge.

2 Likes
Thank you so much—this is so helpful.
For the begin vi I tried to do both of the examples you gave, but I wasn’t sure if a I needed specific RGB values, but I’ll use the ones in your example to start out.
The second pic you have of the begin vi, what are those brown wires/icons called, as in what do I select when I right click the color match box? A constant didn’t give me that.
Thank you again for your time!
The RGB constants shown are just those from the Rev example project and seem to work well enough.
The second Begin example snippet is identical to the first one, except instead of Create->Constant choose Create->Control.
The difference is that the control method puts the RGB values on the front panel where they are easier to tune/adjust while running your LabVIEW project in Debug (white arrow) mode at home.
If you don’t plan to play with the values, then making them constants is sufficient.
If you use controls then:
- You will have to enter the Rev example constants into the front panel to start with.
- Once values are entered on the front panel use the Edit menu and choose “Make current values default” (Otherwise they will revert to zeros when you close the project).

During competition you’ll be using fixed constant values, but they can remain as controls with the values you want made set as defaults.
1 Like
Would you mind explaining what you mean by fixed constant values during competition? I’m not trying to be dense, I swear.
Can you give me any information about GameData? Where do I put that, or find that?
Can you tell me where you got those color blocks in your image
Right click, WPI robots library, sensors, third party.
If you don’t see them reply and I’ll walk you how to install the Rev v3 library, ok?
That link is not especially informative. But for other people struggling:
WPI Robotics Library -> Driver Station palette is where to start, I guess. I’ll update when I can get to our FRC laptop!
Do you have suggestions for improving the documentation?
Poor phrasing on my part.
I just mean that long before we get to competition we will have decided on our color values.
After matches begin at competition, we won’t be doing any tuning, we’ll be hard-coding the values like in the first Begin example.
One way to control the motor is to use Periodic Tasks with a structure similar to this (but without all that example code controlling a catapult):
http://www.team358.org/files/programming/ControlSystem2015-2019/labview/index.php#ButtonStartofTimedAction
- Create a big loop that checks constantly for a human’s button press
- After the button press, start your color picker motor in a first frame
- In the second frame use that snippet of code from the GameData webpage.
- Inside each of the cases check for that color in a loop and stop the motor (and loop) when the color matches.
The first time you learn to do some new programming can be difficult until you have had time to adjust to that way of thinking.
Thanks! I’ve never programmed anything with Periodic Tasks. About to learn how!
I would like to know what the brown boxes are on the Teleop & the Begin because my friend and I are working on it.
The brown boxes are clusters. So it represents several values smushed together in one wire.
In my picture you see what the brown box in the code view looks like on the front panel.
To add on here.
You get those clusters by
- right-click on the left brown node on the Add Color Match vi
- Choose Create->Control from the pop-up menu
1 Like
So, I’ve added the sample code in: I’ve put the initialization information in Begin, I’m tracking the sensor information in a Loop in Periodic Task, I am writing that resulting information to a Global Variable and pulling that information into Teleop, I’ve did my logic for the sensor and Game Data to control my motor and the cases are only being activated on a button press but it’s only reading the outside case which is “when Game Data sends ‘B’, stop the motor when the color sensor reads ‘R’”.
I wrote variables for several steps in the process to the dashboard to make sure information is following through: the sensor is seeing and sending the different colors in Periodic Task, the logic is seeing the Game Data in Teleop and the Game Data is going into the case structures.
This is really the final step in making all of this work for us, aside from tweaking each color’s values which is a whole other beast in itself. Any help would be greatly appreciated.