Announcement

Collapse
No announcement yet.

Color Sensor Code Error

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Color Sensor Code Error

    Hi. My team is trying to use a modern robotics color sensor, and we have a sample code, but it has an error.
    Here is the code |
    |
    \/
    Code:
     
    public class Beacon extends LinearOpMode {
        ColorSensor colorSensor;
        DeviceInterfaceModule CDI;
    
        @Override
        public void runOpMode() throws InterruptedException {
            colorSensor = hardwareMap.colorSensor.get("color");
            CDI = hardwareMap.deviceInterfaceModule.get("Device Interface Module");
            boolean LEDState = true;
    
            waitForStart();
    
    
            colorSensor.enableLed(!LEDState);
            float hsvValues[] = {0, 0, 0};
    
    
            while (opModeIsActive()) {
                colorSensor.enableLed(LEDState);
               //Here is the error
     Color.RGBToHSV(colorSensor.red() * 8, colorSensor.green() * 8, colorSensor.blue() * 8, hsvValues);
                telemetry.addData("1 Red ", colorSensor.red());
                telemetry.addData("2 Blue ", colorSensor.blue());
    
    
                if (colorSensor.red() > colorSensor.blue()) {
                    //motor moves
                }
                if (colorSensor.blue() > colorSensor.red()) {
                    //other motor moves
                }
                waitOneFullHardwareCycle();
            }
        }
    
            }
    Here is the error code, "Cannot resolve method 'RGBToHSV(int, int, int, float[])'

    I am pretty sure I am just doing a dumb mistake, but I cannot find it. It worked before but has just recently given an error code.

  • #2
    Did you include this import statement? import android.graphics.Color;

    Comment


    • #3
      Originally posted by FTC8564 View Post
      Did you include this import statement? import android.graphics.Color;
      I included all import statements necessary.
      Also, the words "RGBToHSV" are the only letters in red.

      Comment


      • #4
        Make sure you imported the Android color class, not the AWT color class.
        FTC6460 mentor (software+computer vision+electronics), FPGA enthusiast. In favor of allowing custom electronics on FTC bots.
        Co-founder of ##ftc live chat for FTC programming--currently you may need to join and wait some time for help--volunteer basis only.

        Comment


        • #5
          Originally posted by hexafraction View Post
          Make sure you imported the Android color class, not the AWT color class.
          Apparently that was my problem. *sigh* I am not sure how I missed that. Thanks a bunch for replying so quickly.

          Comment

          Working...
          X