Hello.
I was trying to figure out how to get the team color from the field.
Since we re trying to use the color sensor to recognize the ball color and determine whether if it is our team color ball or the opposing team color ball.
I tried to dig through some documentation and api and I just couldn’t figure it out
send help
Here is the code we used this year. we just do it during disabled period and put it to a RobotContainer variable, so we don’t have to poll the FMS all the time.
I would recommend reading the alliance color periodically. If you do it just once, if the DS wasn’t connected to the FMS you’ll be stuck with invalid or the wrong color alliance. We updated this every 1 second, so even in the case of a code reset (where disabledPeriodic() might not run), everything would be fine.
Here is what that code snippet would look like (goes in robotInit() in Robot.java):
// Update alliance color every second (just in case we lose comms or power).
addPeriodic(() -> robot_state_.setAlliance(DriverStation.getAlliance()), 1);