Skip to content

Sensors

johnmeshulam edited this page Nov 10, 2019 · 3 revisions

Overview

FLL-leJOS has 4 sensor types:

  • Gyro
  • Touch
  • Color
  • Ultrasonic

Defining Sensors

To define a new sensor, write the following in HardwareCreator:

new <SensorType>(String name, int port);

Examples:

new GyroSensor("myGyro", 1);
new TouchSensor("myTouchSensor", 3);

Accessing Sensors

To access a sensor, call RobotMap.getSensor() with either the name or port:

RobotMap.getSensor("myGyro")
RobotMap.getMotor(3)

This will allow you to use the sensor as follows:

RobotMap.getSensor(3).read();

General Information

Sensors have one primary function: read() read() returns a double containing the current sensor value.

Sensors can have their current value defined as 0 with resetToCurrentValue(), and return their original definition of 0 with resetToAbsoluteValue()

Gyro sensors can also calibrate with the calibrate() function

Clone this wiki locally