wiki:Sensors

Sensors Implementation

Here's how to get sensor values (except for encoder values and limit switches):

First, you need to register your Subsystem with the sensors system. To do this, you first need to go into Robot.java and after you create your subsystem and run initDefaultCommand() and registerButtons() (if applicable), put the line sensorSys.registerListener(Subsystem Name, e.g. armSys).

Once that's complete, you'll need to go into your Subsystem and make it implement the SensorListener? interface via implements SensorListener. For the arm subsystem, this looks like public class ArmSubsystem extends Subsystem implements SensorListener.

Once you've done this eclipse should yell at you that you have unimplemented methods. Allow it to implement these and you'll have a new method named receivedValue. receivedValue is called in the handleEvents class and will pass you a hashmap of all the sensors with a tag and a value. Go into the class Sensor.java (singular) in order to see a list of all the sensor values and their tags. If your sensor value isn't there, create it. Don't worry about what the tag is - that's the sensors team's job. In order to get your sensor data, simply set a variable equal to e.get(Sensor.VALUE_NAME).

And that's all! An example can be found in the manipulatorArm branch and the Arm Subsystem. Any questions feel free to ask Alex or Tim.

Last modified 5 years ago Last modified on Jan 29, 2016, 11:14:20 AM