Search…
⌃K

Application Examples

Application Information

The REV Touch Sensor features an off-center button. Because this sensor requires a contact interface; the sensor must be mounted with regards to the location of the button and the object, or mechanism, intended to trigger the sensor.
Common applications for the Touch Sensor, such as limit switches, require consideration for unconstrained, or twisting motion. Limit switches limit the range of motion for a mechanism. If the mechanism is not properly constrained, there is a risk that the contact interface will not trigger the Touch Sensor.

FTC Applications

Configuring in the Control System

Configure the Touch Sensor as "REV Touch Sensor" as shown in the image below.
In this example, the Touch Sensor is configured on port one. It is touched on briefly in the Pinout Section that the Touch Sensor only sends a signal to the Control Hub through the n+1 communication channel. Because of this limitation, the Touch Sensor will only work when configured on the odd-numbered digital ports.

Programming Applications

The code blocks below give a basic example of how to use the Touch Sensor to limit the motion range of a motor using if/else logic. If the button is pressed then the motor stops. Otherwise, the motor is allowed to move.
Blocks
OnBot Java
The code assumes the sensor has been named "Touch" and the motor has been named "Motor" in configuration.
import com.qualcomm.robotcore.hardware.TouchSensor;
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
import com.qualcomm.robotcore.hardware.DcMotor;
@TeleOp
public class TouchTest extends LinearOpMode {
// Define variables for our touch sensor and motor
TouchSensor touch;
DcMotor motor;
@Override
public void runOpMode() {
// Get the touch sensor and motor from hardwareMap
touch = hardwareMap.get(TouchSensor.class, "Touch");
motor = hardwareMap.get(DcMotor.class, "Motor");
// Wait for the play button to be pressed
waitForStart();
// Loop while the Op Mode is running
while (opModeIsActive()) {
// If the touch sensor is pressed, stop the motor
if (touch.isPressed()) {
motor.setPower(0);
} else { // Otherwise, run the motor
motor.setPower(0.3);
}
}
}
Last modified 2yr ago