Input - Gongoliers/Library-of-Gongolierium GitHub Wiki

Switches

Switch

One of the core devices in the I/O framework is a Switch. A switch is an input device which can be triggered. All switches contain the method:

boolean isTriggered()

This method specifies when the given switch is active.

ResettableSwitch

The ResettableSwitch interface extends Switch to add the following method:

void reset()

This method causes the switch to become inactive (isTriggered() will return false). ResettableSwitches are good for cases when a non-physical switch can hold the state (such as an intake mechanism determining whether it picked up an object).

LimitSwitch

A limit switch is a piece of hardware which determines is a lever is open or closed. It is commonly used to determine if a device is at a certain limit (top, bottom, etc.). The LimitSwitch class implements Switch, so it contains the isTriggered method. A LimitSwitch can be created through the following line of code:

Switch topLimit = new LimitSwitch(0);
  • Note it is better in most cases to use polymorphism; that is make the variable type the most general type needed (in this case Switch, because LimitSwitch implements Switch) so it will be easier to change the specific type of object in the future.

Boolean Switch operations

The Switch interface also contains a default method called invert with the following signature:

Switch invert()

This method will invert the switch; this means the new switch will return false then the old would have returned true, and vice-versa.

The Switch interface also has two static methods (or, and) which create new switches in which either switch needs to be true for the new switch to be true (or) or both switches need to be true for the new switch to be true (and).

static Switch and(Switch s1, Switch s2)
static Switch or(Switch s1, Switch s2)

Switch example

Switch topLimit = new LimitSwitch(0);
Switch objectDetection = new LimitSwitch(1);

// Create a switch in which both the topLimit and the objectDetection switches need to be false
Switch armMovementUpAllowed = Switch.and(topLimit.invert(), objectDetection.invert());

while(armMovementUpAllowed.isTriggered()){
    // Move arm up
}

// Stop arm, switch was triggered

Voltage and Current Sensors

CurrentSensor and VoltageSensor

The Library of Gongolierium defines two interfaces for getting the current or voltage of a sensor. The methods for each interface are as follows:

double getCurrent()

double getVoltage()

The getCurrent is for the CurrentSensor and the getVoltage is for the VoltageSensor. By themselves, these classes aren't all too useful (you could use the VoltageSensor to adjust speeds based on battery voltage). This is why the following two component types were created.

Trip sensors

Trip sensors are Switches which are triggered when the current or voltage exceeds or dips below a threshold. They are useful for implementing safety stops which can stop a motor if the current gets too high or similar applications. There are four different trip sensors and two trip sensor interfaces. There are two different trip sensor types for each the CurrentSensor and VoltageSensor: High and Low. The following is the list of classes:

  • CurrentTripSensor
    • HighCurrentSensor
    • LowCurrentSensor
  • VoltageTripSensor
    • HighVoltageSensor
    • LowVoltageSensor
// More on specific current sensors will be presented further in this wiki.
CurrentSensor sensor = new PDPCurrentSensor(0);
CurrentTripSensor safetyStop = new HighCurrentSensor(sensor, 50);

while(!safetyStop.isTriggered()){
    // do something
}

Spike sensors

Spike sensors detect a spike upward or downward in a CurrentSensor or VoltageSensor. Spike sensors can be used to detect unusual activity in voltage or when a load passes through an intake system current sensor (upward spike). Each spike sensor takes its corresponding trip sensor where a high trip sensor is for upward spikes and a low trip sensor is for downward spikes. The spike sensors implement ResettableSwitch and will need to be reset after each spike is detected.

CurrentSensor sensor = new PDPCurrentSensor(0);
CurrentTripSensor intakeSensor = new HighCurrentSensor(sensor, 7);
CurrentSpikeSensor boulderDetection = new CurrentSpikeSensor(intakeSensor);

while(!boulderDetection.isTriggered()){
    // intake
}

// stop, boulder passed through current sensor

Built in voltage and current sensors

By default there is one type of current sensor and one type of voltage sensor implemented in the Library of Gongolierium. The built in current sensor is the PDPCurrentSensor. The PDPCurrentSensor takes a PowerDistributionPanel instance and the port of a motor or device to monitor. If no PowerDistributionPanel is provided, the default will be used though issues may occur when creating multiple PDPCurrentSensors that way. The PDPCurrentSensor implements CurrentSensor.

CurrentSensor sensor = new PDPCurrentSensor(new PowerDistributionPanel(), 0);
sensor.getCurrent();

The built in voltage sensor is the BatteryVoltageSensor. The BatteryVoltageSensor monitors the voltage of the main battery on the robot. The BatteryVoltageSensor implements VoltageSensor.

VoltageSensor battery = new BatteryVoltageSensor();
battery.getVoltage();

Accelerometer based sensors

Accelerometer data in itself is not the most useful in FRC because of the large amount of noise in its readings. However, it does have several applications explained below.

Collision sensor

The collision sensor can be used to determine if the robot has collided with another object on the field. This sensor can be used to prevent further damage upon colliding with something. This sensor takes an Accelerometer and a magnitude threshold in g-forces. This is also a Switch, so it contains the isTriggered method to determine if a collision has occurred.

Switch collision = new CollisionSensor(new BuiltInAccelerometer(), 10);

while(!collision.isTriggered()){
    // do something
}

// brace for impact!

Linear and gravitational acceleration sensors

Sometimes it may be useful to detect just the acceleration that the robot is producing rather than having gravity in the picture or vice-versa. This is where the LinearAccelerationSensor and GravitySensor come into play. Both implement Accelerometer, so they return their respective kind of acceleration in the x, y, and z axes in g-forces. Both also take an Accelerometer.

Accelerometer builtIn = new BuiltInAccelerometer();
Accelerometer gravity = new GravitySensor(builtIn);
Accelerometer linear = new LinearAccelerationSensor(builtIn);

gravity.getY();
linear.getX();

Orientation

Orientation sensors allow you to know the robot's orientation in 3D space and typically use sensor fusion.

Tilt sensor

Accelerometers can detect the tilt of the robot with respect to the ground. This can be used to balance the robot, bracing for impact on a fall, or determine if the robot is on a ramp. The TiltSensor class takes an Accelerometer and it contains two methods, getPitch which returns the pitch in degrees and getRoll which returns the roll in degrees. To get a more accurate reading, use a GravitySensor instead of an Accelerometer.

TiltSensor tilt = new TiltSensor(new BuiltInAccelerometer());
tilt.getPitch();
tilt.getRoll();

OrientationSensor

The OrientationSensor can detect the roll, pitch, and yaw of the robot (roll and pitch are with respect to the ground, yaw is with respect to the robot's starting position). This can be used to balance the robot, brace for impact of a fall, determine if the robot is on a ramp, or know which direction the robot is facing.

OrientationSensor orientation = new OrientationSensor(accelerometer, gyro);
orientation.getOrientation(); // Contains roll, pitch, and yaw

User input

JoystickTransformer

The JoystickTransformer class contains several static methods which can be used to transform the joystick values to get smoother control over the robot.

Sensitivity

The sensitivity of the joystick determines how sudden slight movements of the joystick are. Sensitivity is defined on the range [0, Inf) where 0 is no sensitivity (no movement) and greater values mean the robot will get to full speed quicker. Sensitivities less than 1 will set the limit the max speed of the robot to the sensitivity passed in.

Sensitivity of 0.5

Power

Adjusting the power of the joystick will give different sensitivities at different speeds. For example, powers less than 1 will have higher sensitivity with low speeds, and lower sensitivities with high speeds. Powers greater than 1 will provide lower sensitivities at low speeds and higher sensitivities for high speeds. Powers greater than 1 are good for applications in which the robot must have fine control in low speeds but higher sensitivity in normal operations.

Power of 2

Deadzones

There are 3 types of deadzones provided in the JoystickTransfomer class: deadzone (axial), radial deadzone, and scaled radial deadzone. The axial deadzone is the most common deadzone, and it just silences (sets to 0) a value that is between +/- threshold. The radial deadzone accepts an x and y value from the joystick and will silences values in which the magnitude of the input is less than the threshold. The scaled radial deadzone does the same as the radial deadzone, except it will scale the resulting good zone from 0 to +/- 1 instead of +/- threshold to +/- 1. Deadzones are useful to prevent movement from noise or slight movements of a joystick.

Deadzone of 0.1

Radial deadzone of 0.1