This repository has been archived by the owner on Jan 13, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
362 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,73 @@ | ||
package com.team766.robot.burro_arm; | ||
|
||
import static com.team766.framework.RulePersistence.ONCE; | ||
import static com.team766.framework.RulePersistence.ONCE_AND_HOLD; | ||
import static com.team766.framework.RulePersistence.REPEATEDLY; | ||
import static com.team766.robot.burro_arm.constants.InputConstants.*; | ||
|
||
import com.team766.framework.Context; | ||
import com.team766.framework.Procedure; | ||
import com.team766.framework.Rule; | ||
import com.team766.framework.RuleEngine; | ||
import com.team766.hal.JoystickReader; | ||
import com.team766.hal.RobotProvider; | ||
import com.team766.logging.Category; | ||
import com.team766.robot.burro_arm.mechanisms.*; | ||
import com.team766.robot.burro_arm.procedures.*; | ||
import com.team766.robot.common.mechanisms.BurroDrive; | ||
import java.util.Set; | ||
|
||
/** | ||
* This class is the glue that binds the controls on the physical operator | ||
* interface to the code that allow control of the robot. | ||
*/ | ||
public class OI extends Procedure { | ||
public class OI extends RuleEngine { | ||
private JoystickReader joystick0; | ||
private JoystickReader joystick1; | ||
private JoystickReader joystick2; | ||
|
||
public OI() { | ||
loggerCategory = Category.OPERATOR_INTERFACE; | ||
@Override | ||
public Category getLoggerCategory() { | ||
return Category.OPERATOR_INTERFACE; | ||
} | ||
|
||
public OI(BurroDrive drive, Arm arm, Gripper gripper) { | ||
joystick0 = RobotProvider.instance.getJoystick(0); | ||
joystick1 = RobotProvider.instance.getJoystick(1); | ||
joystick2 = RobotProvider.instance.getJoystick(2); | ||
} | ||
|
||
public void run(final Context context) { | ||
context.takeOwnership(Robot.drive); | ||
context.takeOwnership(Robot.arm); | ||
context.takeOwnership(Robot.gripper); | ||
|
||
while (true) { | ||
// wait for driver station data (and refresh it using the WPILib APIs) | ||
context.waitFor(() -> RobotProvider.instance.hasNewDriverStationData()); | ||
RobotProvider.instance.refreshDriverStationData(); | ||
|
||
// Add driver controls here - make sure to take/release ownership | ||
// of mechanisms when appropriate. | ||
|
||
Robot.drive.drive(-joystick0.getAxis(1) * 0.5, -joystick0.getAxis(2) * 0.3); | ||
|
||
if (joystick0.getButton(BUTTON_ARM_UP)) { | ||
Robot.arm.setAngle(Robot.arm.getAngle() + NUDGE_UP_INCREMENT); | ||
} else if (joystick0.getButton(BUTTON_ARM_DOWN)) { | ||
Robot.arm.setAngle(Robot.arm.getAngle() - NUDGE_DOWN_INCREMENT); | ||
} | ||
|
||
if (joystick0.getButton(BUTTON_INTAKE)) { | ||
Robot.gripper.intake(); | ||
} else if (joystick0.getButton(BUTTON_OUTTAKE)) { | ||
Robot.gripper.outtake(); | ||
; | ||
} else { | ||
Robot.gripper.idle(); | ||
} | ||
} | ||
// Add driver controls here. | ||
|
||
addRule( | ||
Rule.create("Drive Robot", () -> true) | ||
.withOnTriggeringProcedure( | ||
REPEATEDLY, | ||
Set.of(drive), | ||
() -> { | ||
drive.setRequest( | ||
new BurroDrive.ArcadeDrive( | ||
-joystick0.getAxis(AXIS_FORWARD_BACKWARD) * 0.5, | ||
-joystick0.getAxis(AXIS_TURN) * 0.3)); | ||
})); | ||
|
||
addRule( | ||
Rule.create("Arm Up", () -> joystick0.getButton(BUTTON_ARM_UP)) | ||
.withOnTriggeringProcedure( | ||
ONCE, Set.of(arm), () -> arm.setRequest(Arm.makeNudgeUp()))); | ||
addRule( | ||
Rule.create("Arm Down", () -> joystick0.getButton(BUTTON_ARM_DOWN)) | ||
.withOnTriggeringProcedure( | ||
ONCE, Set.of(arm), () -> arm.setRequest(Arm.makeNudgeDown()))); | ||
|
||
addRule( | ||
Rule.create("Intake", () -> joystick0.getButton(BUTTON_INTAKE)) | ||
.withOnTriggeringProcedure( | ||
ONCE_AND_HOLD, | ||
Set.of(gripper), | ||
() -> gripper.setRequest(new Gripper.Intake()))); | ||
addRule( | ||
Rule.create("Outtake", () -> joystick0.getButton(BUTTON_OUTTAKE)) | ||
.withOnTriggeringProcedure( | ||
ONCE_AND_HOLD, | ||
Set.of(gripper), | ||
() -> gripper.setRequest(new Gripper.Outtake()))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.