👨‍💻
ARC Software
  • Introduction
  • The FTC Control System
  • Setting up the Environment
  • The OpMode
    • Introducing the OpMode
    • OpMode vs LinearOpMode
    • Telemetry and Debugging
    • Stopping LinearOpModes
  • Hardware Interaction
    • Hardware Configuration
    • DcMotor
    • Servos
    • Sensors
    • Inertial Measurement Unit
  • TeleOp
    • FTC Match Structure
    • Accessing Gamepads
    • The TeleOp Period
    • Finite State Machines
  • Autonomous
    • The Autonomous Period
  • Virtual Robot Environment
    • Setting Up The Virtual Robot Environment
    • Programming a Mecanum Drive
  • Working with a Team
    • Integrate with your Team
    • Using Git Effectively
Powered by GitBook
On this page
  • The Color Sensor
  • Initializing the Sensor
  • .red(), .green(), and .blue()
  • .alpha()
  • .argb()
  • Check Your Understanding

Was this helpful?

  1. Hardware Interaction

Sensors

A sensor is an electronic device that takes input from the outside environment, whether that's color, temperature, or some other factor, and collects the information so we can use it to make decisions in our program.

The Color Sensor

One common sensor is a color sensor. Color sensors can be useful in a variety of challenges where the robot needs to differentiate differently colored objects.

Here are some important tips you'll need to know in order to use a color sensor:

Initializing the Sensor

Just like any other piece of hardware, you need to initialize a Color Sensor before you can use it.

In your class, you can initialize a variable of type ColorSensor:

ColorSensor color_sensor;

When initializing your hardware devices, you'll need to interface with the hardware map to actually connect it.

color_sensor = hardwareMap.get(ColorSensor.class, "color_sensor");

Now that you have your sensor initialized, you are ready to begin retrieving color values from it.

.red(), .green(), and .blue()

These return the amount of red, green, and blue, respectively, that the sensor is currently detecting as an integer.

.alpha()

This returns the amount of light the sensor is currently detecting as an integer.

.argb()

This returns the combined amounts of red, green, and blue currently detected.

Using these methods, you can compare colors sensed at different points in your OpMode.

Check Your Understanding

  1. Why do we use sensors?

  2. Can you provide an example of a game challenge that could be solved with a Color Sensor?

  3. What does the .alpha() method do?

PreviousServosNextInertial Measurement Unit

Last updated 4 years ago

Was this helpful?

To learn more about sensors, you can use the code examples found in the FtcRobotController > java > org.firstinspires.ftc.robotcontroller > external.samples folder, or use the .

official FTC JavaDocs