This should feel somewhat familiar, as we already had a system for interchangeable control schemes. This is a new version, however. Some things work similarly to the previous version, and some things work differently.
Please refer to the JavaDoc links below for more detailed information.
JavaDoc for axes and buttonsSelect one of the related packages: "axes" or "buttons". You will then see all the available axis or button implementations, respectively.
JavaDoc for TeleOpState
package org.firstinspires.ftc.teamcode.fy23;
// some imports here
public class NewControlScheme implements controlScheme {
TeleOpState state = new TeleOpState;
Gamepad driver;
Gamepad manipulator;
// When not inverted, pressed = true and released = false.
Button exampleMomentaryButton = new MomentaryButton( () -> driver.a );
// Only active the first time isActive() is called on it after each new press.
// A button press, no matter how long, will only appear as active once.
Button exampleTriggerButton = new TriggerButton( () -> driver.b );
// Handles toggle for you. Each press toggles what isActive() returns.
Button exampleToggleButton = new ToggleButton( () -> driver.x );
// Pretend that an axis is a button.
// Appears as active when the absolute value is greater than the threshold (the second argument).
Button exampleAxisAsButton = new AxisAsButton( () -> driver.left_trigger, 0.3);
// Runs from 0 to 1
Axis exampleLinearAxis = new LinearAxis( () -> driver.right_stick_x );
// Arguments: physical axis, invert, scalingFactor
// Y axes on analog sticks need to be inverted
// Scaling factor greater than 1: change in value is less in center, greater towards edge of stick
Axis exampleExponentialAxis = new ExponentialAxis( () -> driver.left_stick_y, true, 2);
// Pretend that a button is an axis. When not inverted, pressed = 1 and released = 0.
Axis exampleButtonAsAxis = new buttonAsAxis( () -> driver.right_trigger );
// Now, some more realistic cases:
Axis driveAxis = new LinearAxis( () -> (driver.right_trigger - driver.left_trigger) );
Axis turnAxis = new ExponentialAxis( () -> driver.left_stick_x, 2);
Axis strafeAxis = new LinearAxis( () -> driver.right_stick_x );
Button launchPlane = new TriggerButton( () -> driver.right_bumper );
Axis pivotAxis = new ExponentialAxis( () -> manipulator.left_stick_y, true, 2);
Axis elevatorAxis = new LinearAxis( () -> (manipulator.right_trigger - manipulator.left_trigger) );
Button clawToggle = new ToggleButton( () -> manipulator.a );
// You can make private methods, only used internally, to help you.
// For example, I like to make ones like this to de-clutter my getState() method.
private void setStateDTS() {
state.setDts(new DTS(
driveAxis.value(),
turnAxis.value(),
strafeAxis.value()
));
}
private Claw.State determineClawState() {
if (clawToggle.active()) {
return Claw.State.CLOSED;
} else {
return Claw.State.OPEN;
}
}
// This is the one public method that you are required to provide.
// TeleOpState method names (what to set / get):
// https://axolotl10107.github.io/javadoc/fy23/org/firstinspires/ftc/teamcode/fy23/gamepad2/teleop/TeleOpState.html
@Override
public void getState() {
setStateDTS();
state.setArmMovement(pivotAxis.value());
state.setElevatorMovement(elevatorAxis.value());
state.setClawState(determineClawState());
state.setLaunchPlane(launchPlane.isActive());
}
}