Announcement

Collapse
No announcement yet.

Color sensor reasonable values and no API for a sensor function

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

  • Color sensor reasonable values and no API for a sensor function

    Looking to see if the values I'm seeing are what are expected from the color sensors.

    LED is off for each sensor, sensors are aimed horizontally away from light sources, home level lighting.

    MR sensor reads 0 without the beacon, with the beacon in its dim setting the sensor reads 1 about 6" away, but no more than 2 when touching the beacon for both colors. (If I find the exact right spot blue can sometimes report 3.)

    Adafruit without beacon reads under 200, with beacon 1 cm away 540 for red and 760 for blue.


    Are these values similar to what others are seeing? Thanks.

    Also I noticed in the spec sheet that the MR sensor can output a number that indicates color. 2 for blue, 10 for red, etc. I don't see an SDK command that uses this function. It seems to work well trying it with the Core Discovery software.

  • #2
    Our numbers back from the .red() and .blue() functions were similar - I have no idea of what the range is supposed to be, but for us at least it would consistently return a larger integer for the matching color function. So our IsRed() function that we wrote just returned .red() > .blue().

    Comment


    • #3
      Originally posted by FTC3805 View Post
      Looking to see if the values I'm seeing are what are expected from the color sensors.

      LED is off for each sensor, sensors are aimed horizontally away from light sources, home level lighting.

      MR sensor reads 0 without the beacon, with the beacon in its dim setting the sensor reads 1 about 6" away, but no more than 2 when touching the beacon for both colors. (If I find the exact right spot blue can sometimes report 3.)

      Adafruit without beacon reads under 200, with beacon 1 cm away 540 for red and 760 for blue.


      Are these values similar to what others are seeing? Thanks.

      Also I noticed in the spec sheet that the MR sensor can output a number that indicates color. 2 for blue, 10 for red, etc. I don't see an SDK command that uses this function. It seems to work well trying it with the Core Discovery software.
      From the Rescue beacon instructions:

      "To make the LEDs most visible add two
      strips of tape on each ridge on the side of the Rescue
      Beacon opposite the Electronics Board. "

      If this is not done then the light from one LED will bleed into the next. I've also seen teams install the beacon backwards where most of light emulates out the back where the reset button is.

      Can you share your code?

      Comment


      • #4
        Originally posted by dlevy View Post
        From the Rescue beacon instructions:

        "To make the LEDs most visible add two
        strips of tape on each ridge on the side of the Rescue
        Beacon opposite the Electronics Board. "

        If this is not done then the light from one LED will bleed into the next. I've also seen teams install the beacon backwards where most of light emulates out the back where the reset button is.

        Can you share your code?
        I didn't even think to check if the beacons were built correctly. Checked and it is built correctly, but the tape isn't there. I'll add that and check again, but without tape, the MR the sensitivity is low enough that I don't see any red response from the blue side or vice versa. There is a response from the opposite color on the Adafruit though.

        This code is all cut and and paste from Imperial Robotics and FTC example code --

        package com.qualcomm.ftcrobotcontroller.opmodes;

        import android.util.Log;

        import com.qualcomm.robotcore.eventloop.opmode.OpMode;
        import com.qualcomm.robotcore.exception.RobotCoreExceptio n;
        import com.qualcomm.robotcore.hardware.ColorSensor;
        import com.qualcomm.robotcore.hardware.DeviceInterfaceMod ule;
        import com.qualcomm.robotcore.hardware.DigitalChannelCont roller;
        import com.qualcomm.robotcore.hardware.GyroSensor;

        //import newinventions.AdafruitIMU;


        /**
        * Created by Owner on 8/31/2015.
        */
        public class JohnIMUColorAdaTest extends OpMode {

        AdafruitIMU boschBNO055;
        GyroSensor sensorGyro;
        ColorSensor sensorRGB;
        ColorSensor sensorRGBADA;
        DeviceInterfaceModule cdim;
        static final int LED_CHANNEL = 5;

        //The following arrays contain both the Euler angles reported by the IMU (indices = 0) AND the
        // Tait-Bryan angles calculated from the 4 components of the quaternion vector (indices = 1)
        volatile double[] rollAngle = new double[2], pitchAngle = new double[2], yawAngle = new double[2];

        long systemTime;//Relevant values of System.nanoTime

        /************************************************** **********************************************
        * The following method was introduced in the 3 August 2015 FTC SDK beta release and it runs
        * before "start" runs.
        */
        @Override
        public void init() {
        systemTime = System.nanoTime();
        try {
        boschBNO055 = new AdafruitIMU(hardwareMap, "bno055", (byte)(AdafruitIMU.BNO055_ADDRESS_A * 2),
        (byte)AdafruitIMU.OPERATION_MODE_IMU);
        } catch (RobotCoreException e){
        Log.i("FtcRobotController", "Exception: " + e.getMessage());
        }
        //ADDRESS_B is the "standard" I2C bus address for the Bosch BNO055 (IMU data sheet, p. 90).
        //BUT DAVID PIERCE, MENTOR OF TEAM 8886, HAS EXAMINED THE SCHEMATIC FOR THE ADAFRUIT BOARD ON
        //WHICH THE IMU CHIP IS MOUNTED. SINCE THE SCHEMATIC SHOWS THAT THE COM3 PIN IS PULLED LOW,
        //ADDRESS_A IS THE IMU'S OPERATIVE I2C BUS ADDRESS
        //IMU is an appropriate operational mode for FTC competitions. (See the IMU datasheet, Table
        // 3-3, p.20 and Table 3-5, p.21.)
        sensorGyro = hardwareMap.gyroSensor.get("gyro");
        sensorRGB = hardwareMap.colorSensor.get("mr");
        sensorRGBADA = hardwareMap.colorSensor.get("colorADA");
        cdim = hardwareMap.deviceInterfaceModule.get("dim");

        cdim.setDigitalChannelMode(LED_CHANNEL, DigitalChannelController.Mode.OUTPUT);
        }

        /************************************************** **********************************************
        * Code to run when the op mode is first enabled goes here
        * @see OpMode#start()
        */
        @Override
        public void start() {
        /*
        * Use the hardwareMap to get the dc motors, servos and other sensors by name. Note
        * that the names of the devices must match the names used when you
        * configured your robot and created the configuration file. The hardware map
        * for this OpMode is not initialized until the OpModeManager's "startActiveOpMode" method
        * runs.
        */
        systemTime = System.nanoTime();
        boschBNO055.startIMU();//Set up the IMU as needed for a continual stream of I2C reads.
        Log.i("FtcRobotController", "IMU Start method finished in: "
        + (-(systemTime - (systemTime = System.nanoTime()))) + " ns.");

        sensorGyro.calibrate();
        sensorRGB.enableLed(true);
        cdim.setDigitalChannelState(LED_CHANNEL, true);
        }

        /************************************************** *********************************************
        * This method will be called repeatedly in a loop
        * @see OpMode#loop()
        * NOTE: BECAUSE THIS "loop" METHOD IS PART OF THE OVERALL OpMode/EventLoop/ReadWriteRunnable
        * MECHANISM, ALL THAT THIS METHOD WILL BE USED FOR, IN AUTONOMOUS MODE, IS TO:
        * 1. READ SENSORS AND ENCODERS AND STORE THEIR VALUES IN SHARED VARIABLES
        * 2. WRITE MOTOR POWER AND CONTROL VALUES STORED IN SHARED VARIABLES BY "WORKER" THREADS, AND
        * 3. SEND TELELMETRY DATA TO THE DRIVER STATION
        * THIS "loop" METHOD IS THE ONLY ONE THAT "TOUCHES" ANY SENSOR OR MOTOR HARDWARE.
        */
        @Override
        public void loop() {
        //Log.i("FtcRobotController", "Loop method starting at: " +
        // -(systemTime - (systemTime = System.nanoTime())) + " since last loop start.");

        // write the values computed by the "worker" threads to the motors (if any)

        //Read the encoder values that the "worker" threads will use in their computations
        boschBNO055.getIMUGyroAngles(rollAngle, pitchAngle, yawAngle);
        /*
        * Send whatever telemetry data you want back to driver station.
        */
        //telemetry.addData("Text", "*** Robot Data***");
        telemetry.addData("Headings(yaw): ",
        String.format("Eul= %4.5f, Quat= %4.5f", yawAngle[0], yawAngle[1]));
        telemetry.addData("z MR H:", String.format("%03d", sensorGyro.getHeading()));

        telemetry.addData("vClear", sensorRGB.alpha());
        telemetry.addData("wRed ", sensorRGB.red());
        telemetry.addData("xGreen", sensorRGB.green());
        telemetry.addData("yBlue ", sensorRGB.blue());

        telemetry.addData("mClear", sensorRGBADA.alpha());
        telemetry.addData("nRed ", sensorRGBADA.red());
        telemetry.addData("oGreen", sensorRGBADA.green());
        telemetry.addData("pBlue ", sensorRGBADA.blue());

        }

        /*
        * Code to run when the op mode is first disabled goes here
        * @see com.qualcomm.robotcore.eventloop.opmode.OpMode#sto p()
        */
        @Override
        public void stop() {
        //When the FTC Driver Station's "Start with Timer" button commands autonomous mode to start,
        //then stop after 30 seconds, stop the motors immediately!
        //Following this method, the underlying FTC system will call a "stop" routine of its own
        systemTime = System.nanoTime();
        Log.i("FtcRobotController", "IMU Stop method finished in: "
        + (-(systemTime - (systemTime = System.nanoTime()))) + " ns.");
        }
        }

        Comment


        • #5
          From the example Opmode: ColorSensorDrive
          Code:
                switch (device) {
                  case HITECHNIC_NXT:
                    Color.RGBToHSV(colorSensor.red(), colorSensor.green(), colorSensor.blue(), hsvValues);
                    break;
                  case ADAFRUIT:
                    Color.RGBToHSV((colorSensor.red() * 255) / 800, (colorSensor.green() * 255) / 800, (colorSensor.blue() * 255) / 800, hsvValues);
                    break;
                  case MODERN_ROBOTICS_I2C:
                    Color.RGBToHSV(colorSensor.red()*8, colorSensor.green()*8, colorSensor.blue()*8, hsvValues);
                    break;
                }

          To me this implies that colorSensor.red(),green(),blue() will only return 0-255 values for the HITECHNIC_NXT sensor.

          However my last test with the MR Sensor against the ResQ beacon ( no tape to to separate the two leds) , returned a reading of 8 for the red light and 24 for the blue. ( after multiplying by 8 as is the above example)

          Comment


          • #6
            I just tried running the color sensor driver example and got no response from the sensor.

            So are you getting 1 and 3 and then multiplying by 8 to get 8 and 24? If these are integers this doesn't seem to make any difference in making things work.

            Comment


            • #7
              Originally posted by dlevy View Post
              "To make the LEDs most visible add two
              strips of tape on each ridge on the side of the Rescue
              Beacon opposite the Electronics Board. "
              Is this a step that is merely recommended by the instructions, or required on all competition fields? We received the beacon without a set of instructions; would you mind sharing a link to them?
              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


              • #8
                Originally posted by hexafraction View Post
                Is this a step that is merely recommended by the instructions, or required on all competition fields? We received the beacon without a set of instructions; would you mind sharing a link to them?
                page 19

                http://www.usfirst.org/sites/default...mbly-Guide.pdf

                Comment


                • #9
                  Originally posted by FTC3805 View Post
                  I just tried running the color sensor driver example and got no response from the sensor.

                  So are you getting 1 and 3 and then multiplying by 8 to get 8 and 24? If these are integers this doesn't seem to make any difference in making things work.
                  I'm just wondering why the MR Sensor is multiplying by eight in that example opmode.

                  Comment


                  • #10
                    I did some testing with the hitechnic v2 color sensor running the HTRGBExample code provided in the download. The sensor seems to have a "sweet spot" about 2"-4" away from the beacon. In contact with the beacon we had the following readings:

                    Red contact
                    Blue 42
                    Clear 0
                    Green 0
                    Hue 330
                    Red 80-85

                    Blue contact
                    Blue 129
                    Clear 0
                    Green 0
                    Hue 250
                    Red 20

                    We then moved it away and got the following readings

                    Red 2" away
                    Blue 33
                    Clear 0
                    Green 0
                    Hue 350
                    Red 200


                    Blue 2" away
                    Blue 85
                    Clear 0
                    Green 0
                    Hue 260
                    Red 26

                    Comment

                    Working...
                    X