Announcement

Collapse
No announcement yet.

Color sensor program help!

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

  • Color sensor program help!

    is there an example program for using a color sensor to determine red and blue. We can use it as a distance sensor using the example program but can't figure out the color sensor part.

  • #2
    Did you check the samples that are provided in BOTH Android Studio and OnBotJava?

    The Android Studio samples are located in the FTCRobotControler module, under /external/samples.
    The OnBotJava samples can be found in the pulldown "samples" list when you are adding a new file.

    There are examples for most (if not all) of the color sensors.

    Phil.

    Comment


    • #3
      Absolutely we checked and read both of those examples, they provide no help for block programming.

      Comment


      • #4
        Are you using the Rev or Moden Robotics sensor? Perhaps post the link to the exact sensor and to your code.

        Comment


        • #5
          Originally posted by thensley View Post
          Absolutely we checked and read both of those examples, they provide no help for block programming.
          thensley,

          with the version 3.4 software that was released just prior to kickoff, there is now included in the Blocks software a sample op mode that shows how to use the REV color distance sensor to guess what color an object is based on the sensor readings.

          To access this example op mode, when you create a new file in the Blocks user interface, there is a drop down control in the bottom of the new file dialog box. If you click on it, the control lists available sample op modes that you can use as a template for your new op mode file.

          You want to select the sample op mode called "SensorREVColorDistance". I've attached an image showing the Create New Op Mode dialog box with this sample op mode selected.

          This op mode shows how to access the component (red, green, blue) color values from the sensor. It then demonstrates how to convert these component red, green, blue color values into a variable called "colorHSV". The colorHSV variable expresses color in the Hue Saturation Value (HSV) model. The HSV model takes these red, green, and blue colors, and then converts it into a "hue" value. This hue value can then be used to determine what the detected color is by comparing the calculated hue value to know values of the HSV model

          Screen Shot 2017-09-14 at 10.13.26 AM.png
          .

          You can find more about the HSV color model here:

          https://en.wikipedia.org/wiki/HSL_and_HSV

          I did a quick Google search and found this website that has a neat online app that shows you the relationship with the red, green, and blue values and the hue values:

          http://colorizer.org/

          Also, I uploaded a copy of the sample app to a temporary google drive folder... you can download it with the following link:

          https://drive.google.com/open?id=0B_...nhEbURuNUdOckU

          I hope this info helps. Let us know if you have additional questions.

          Tom
          Attached Files

          Comment


          • #6
            We are using the REV module and this is our first year using the blocks programming tool. The sensor we are using is the one that cam with the rev module. we know it works by using the distance program example in the rev book but don't even have an idea where to start with the color sensor to determine red or blue.

            Comment


            • #7
              I forgot to mention, this example color sensor program shows how to use blocks to calculate the hue value, then "guess" and inform the user what the detected color is:

              You can see in this screenshot that there is a set of if-else-if statements that check the computed hue value and depending on its value, inform the user what color it is:

              Screen Shot 2017-09-14 at 10.36.02 AM.png

              Comment


              • #8
                Originally posted by thensley View Post
                We are using the REV module and this is our first year using the blocks programming tool. The sensor we are using is the one that cam with the rev module. we know it works by using the distance program example in the rev book but don't even have an idea where to start with the color sensor to determine red or blue.
                thensley,

                please take a look at the example op mode that i reference in my previous posts.

                tom

                Comment


                • #9
                  That is awesome Tom Thank You! we will definitely put this to the test today!

                  Comment


                  • #10
                    There are two new videos on using Blocks with color sensors on the FIRST Blocks Programming playlist: https://www.youtube.com/playlist?lis...tGcK7q0od0LYov

                    Comment


                    • #11
                      Thanks schaferbw -- those two videos (particularly the first one) were super helpful. I was trying to understand why the tutorials were using HSV and RGB, that cleared it up immensely.

                      Comment

                      Working...
                      X