Color Sensor Programming

I’m using the rev color sensor v3 this year and am struggling with it a tad. I’ve noticed in the video, REV was able to display the color in the smart dashboard. My sensor doesn’t even seem to be able to detect the colors. It displays a small decimal instead of numbers. As for it telling me what color it is, would I use color match?

public class WheelOfPain extends SubsystemBase {
  private final VictorSPX m_wheelOfFortune;

  private final I2C.Port sensorPort;

  private final ColorSensorV3 colorSensor;
  private final Color currentColor;
  private final int rawIr;

  public WheelOfPain() {
    sensorPort = I2C.Port.kOnboard;
    colorSensor = new ColorSensorV3(sensorPort);

    currentColor = colorSensor.getColor();  
    rawIr = colorSensor.getIR();

    m_wheelOfFortune = new VictorSPX(Constants.WHEEL_MOTOR);
  }

  @Override
  public void periodic() {
    SmartDashboard.putNumber("Red", currentColor.red);
    SmartDashboard.putNumber("Blue", currentColor.blue);
    SmartDashboard.putNumber("Green", currentColor.green);
    SmartDashboard.putNumber("IR", rawIr);
  }
}

I would start with the sample code on their GitHub.

https://github.com/REVrobotics/Color-Sensor-v3-Examples

1 Like

I’ve attempted that, still returns the same values. Could it be my sensor? Maybe initiating the color in periodic will fix it so that way it polls every loop.

1 Like

What values is it returning compared to what values you expect it to be returning?

Have you tried the color match example? Does it detect the colors as you expect?

I fixed it by instantiating the color in the periodic method. Didn’t realize I had initialized it in the constructor.

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