parseInputs method
- @override
- GamepadState state
override
Return a list of commands based on the current state of the gamepad.
Implementation
@override
List<Message> parseInputs(GamepadState state) => [
// Manual control
if (state.normalRightX.abs() > state.normalRightY.abs() && state.normalRightX != 0)
ArmCommand(swivel: MotorCommand(moveRadians: state.normalRightX * settings.swivel)),
if (state.normalRightY.abs() > state.normalRightX.abs() && state.normalRightY != 0)
ArmCommand(shoulder: MotorCommand(moveRadians: state.normalRightY * settings.shoulder)),
if (state.normalLeftY != 0) ArmCommand(elbow: MotorCommand(moveRadians: state.normalLeftY * settings.elbow)),
// The bumpers should be pseudo-IK: Move the shoulder and elbow in sync.
if (state.normalShoulder != 0) ArmCommand(
shoulder: MotorCommand(moveRadians: state.normalShoulder * settings.shoulder * -1),
elbow: MotorCommand(moveRadians: state.normalShoulder * settings.elbow),
),
// Gripper
if (state.normalDpadY != 0) GripperCommand(lift: MotorCommand(moveRadians: state.normalDpadY * settings.lift)),
if (state.normalDpadX != 0) GripperCommand(rotate: MotorCommand(moveRadians: state.normalDpadX * settings.rotate)),
if (state.normalTriggers != 0) GripperCommand(pinch: MotorCommand(moveRadians: state.normalTriggers * settings.pinch)),
// Custom actions
if (state.buttonA && !isAPressed) () { isAPressed = true; return GripperCommand(open: true); }(),
if (state.buttonB && !isBPressed) () { isBPressed = true; return GripperCommand(close: true); }(),
if (state.buttonX && !isXPressed) () { isXPressed = true; return ArmCommand(jab: true); }(),
if (state.buttonY && !isYPressed) () { isYPressed = true; return GripperCommand(spin: true); }(),
// General commands
if (state.buttonBack) ...[ArmCommand(stop: true), GripperCommand(stop: true)],
if (state.buttonStart) ...[ArmCommand(calibrate: true), GripperCommand(calibrate: true)],
];