-
Notifications
You must be signed in to change notification settings - Fork 0
Description
What needs to be done?
A callback is a sort of way to handle events in a Java program. With very memory and cpu intensive programs, it is often more beneficial to do things only when they have to be done. A callback ensures that certain procedures will only occur when they are called upon (hence the name callback).
The FTC SDK provides a neat Gamepad callback which alerts the program when there is a state change in one of the gamepad variables. In other words, when someone presses a button or moves a joystick, this method is called. Unfortunately, implementing this callback is tedious and I found some example code which demonstrates how to do this. Whether it works or not is yet to be determined.
Using the example for the code found here, I need someone to test whether implementing the Gamepad callback works with the current SDK version.
package org.firstinspires.ftc.teamcode;
import com.qualcomm.robotcore.eventloop.opmode.OpMode;
import com.qualcomm.robotcore.exception.RobotCoreException;
import com.qualcomm.robotcore.hardware.Gamepad;
import com.qualcomm.robotcore.util.RobotLog;
public class OpModeTest extends OpMode implements Gamepad.GamepadCallback {
@Override
public void init() {
try {
gamepad1.copy(new Gamepad()) ;
gamepad2.copy(new Gamepad()) ;
}
catch (RobotCoreException e) {
RobotLog.e("Gamepads could not be re-created");
throw new IllegalStateException("Gamepads could not be re-created");
}
}
@Override
public void loop() {
}
@Override
public void gamepadChanged(Gamepad gamepad) {
}
}
Notes:
- Do the changes in the prototype branch
- Notice that the package name will need to be changed in order for the code to work properly.
- Inside of the gamepadChanged callback function, implement a way for us to know that it is working. Possible solutions include a simple telemetry reading back to the driver station (Phone connected to controller), actuation of a servo, running a motor, etc.