Skip to content

Commit 5d23284

Browse files
committed
Updated to make all the '::' (methodRef) stuff isolated to a single place
1 parent ae636c1 commit 5d23284

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+956
-735
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package org.firstinspires.ftc.forteaching.TechnoBot.Commands;
2+
3+
import com.technototes.library.command.SimpleCommand;
4+
import com.technototes.library.command.SimpleRequiredCommand;
5+
6+
import org.firstinspires.ftc.forteaching.TechnoBot.Subsystems.ClawSubsystem;
7+
import org.firstinspires.ftc.forteaching.TechnoBot.Subsystems.LiftSubsystem;
8+
import org.firstinspires.ftc.forteaching.TechnoBot.Subsystems.MotorAsServoSubsystem;
9+
import org.firstinspires.ftc.forteaching.TechnoBot.Subsystems.MovementTestingSubsystem;
10+
11+
public class Commands {
12+
public static class Claw {
13+
public static SimpleRequiredCommand<ClawSubsystem> open(ClawSubsystem clawSubsystem) {
14+
return new SimpleRequiredCommand<>(clawSubsystem, ClawSubsystem::open);
15+
}
16+
public static SimpleRequiredCommand<ClawSubsystem> close(ClawSubsystem clawSubsystem) {
17+
return new SimpleRequiredCommand<>(clawSubsystem, ClawSubsystem::close);
18+
}
19+
}
20+
21+
public static class Lift {
22+
public static SimpleRequiredCommand<LiftSubsystem> moveUp(LiftSubsystem lift) {
23+
return new SimpleRequiredCommand<>(lift, LiftSubsystem::moveUp);
24+
}
25+
public static SimpleRequiredCommand<LiftSubsystem> moveDown(LiftSubsystem lift) {
26+
return new SimpleRequiredCommand<>(lift, LiftSubsystem::moveUp);
27+
}
28+
}
29+
30+
public static class MotorAsServo {
31+
public static SimpleRequiredCommand<MotorAsServoSubsystem> increaseEncMotor(MotorAsServoSubsystem m) {
32+
return new SimpleRequiredCommand<>(m, MotorAsServoSubsystem::increaseEncMotor);
33+
}
34+
public static SimpleRequiredCommand<MotorAsServoSubsystem> decreaseEncMotor(MotorAsServoSubsystem m) {
35+
return new SimpleRequiredCommand<>(m, MotorAsServoSubsystem::decreaseEncMotor);
36+
}
37+
public static SimpleRequiredCommand<MotorAsServoSubsystem> stop(MotorAsServoSubsystem m) {
38+
return new SimpleRequiredCommand<>(m, MotorAsServoSubsystem::stop);
39+
}
40+
public static SimpleRequiredCommand<MotorAsServoSubsystem> halt(MotorAsServoSubsystem m) {
41+
return new SimpleRequiredCommand<>(m, MotorAsServoSubsystem::halt);
42+
}
43+
}
44+
45+
public static class MovementTesting {
46+
public static SimpleRequiredCommand<MovementTestingSubsystem> incMotorSpeed(MovementTestingSubsystem m) {
47+
return new SimpleRequiredCommand<>(m, MovementTestingSubsystem::increaseMotorSpeed);
48+
}
49+
public static SimpleRequiredCommand<MovementTestingSubsystem> decMotorSpeed(MovementTestingSubsystem m) {
50+
return new SimpleRequiredCommand<>(m, MovementTestingSubsystem::decreaseMotorSpeed);
51+
}
52+
public static SimpleRequiredCommand<MovementTestingSubsystem> incServoSpeed(MovementTestingSubsystem m) {
53+
return new SimpleRequiredCommand<>(m, MovementTestingSubsystem::increaseServoMotor);
54+
}
55+
public static SimpleRequiredCommand<MovementTestingSubsystem> decServoSpeed(MovementTestingSubsystem m) {
56+
return new SimpleRequiredCommand<>(m, MovementTestingSubsystem::decreaseServoMotor);
57+
}
58+
public static SimpleCommand neutralMotorSpeed(MovementTestingSubsystem m) {
59+
return new SimpleCommand(m::neutralMotorSpeed);
60+
}
61+
public static SimpleCommand neutralServoSpeed(MovementTestingSubsystem m) {
62+
return new SimpleCommand(m::neutralServoMotor);
63+
}
64+
public static SimpleCommand brakeMotor(MovementTestingSubsystem m) {
65+
return new SimpleCommand(m::brakeMotor);
66+
}
67+
}
68+
}

ForTeaching/src/main/java/org/firstinspires/ftc/forteaching/TechnoBot/Controls.java

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,14 @@
22

33
import com.technototes.library.command.CommandScheduler;
44
import com.technototes.library.command.ParallelCommandGroup;
5-
import com.technototes.library.command.SimpleCommand;
6-
import com.technototes.library.command.SimpleRequiredCommand;
75
import com.technototes.library.control.CommandAxis;
86
import com.technototes.library.control.CommandButton;
97
import com.technototes.library.control.CommandGamepad;
108
import com.technototes.library.control.Stick;
119
import com.technototes.library.util.Alliance;
1210

11+
import org.firstinspires.ftc.forteaching.TechnoBot.Commands.Commands;
1312
import org.firstinspires.ftc.forteaching.TechnoBot.Commands.MecDriveCommand;
14-
import org.firstinspires.ftc.forteaching.TechnoBot.Subsystems.ClawSubsystem;
15-
import org.firstinspires.ftc.forteaching.TechnoBot.Subsystems.LiftSubsystem;
16-
import org.firstinspires.ftc.forteaching.TechnoBot.Subsystems.MotorAsServoSubsystem;
17-
import org.firstinspires.ftc.forteaching.TechnoBot.Subsystems.MovementTestingSubsystem;
1813

1914
public class Controls {
2015

@@ -93,52 +88,52 @@ public Controls(CommandGamepad gpad, TheBot bot, Alliance ally) {
9388
}
9489

9590
public void bindClawControls() {
96-
openClaw.whenPressed(robot.clawSubsystem, ClawSubsystem::open);
97-
closeClaw.whenPressed(robot.clawSubsystem, ClawSubsystem::close);
91+
openClaw.whenPressed(Commands.Claw.open(robot.clawSubsystem));
92+
closeClaw.whenPressed(Commands.Claw.close(robot.clawSubsystem));
9893
}
9994

10095
public void bindLiftControls() {
101-
liftUp.whenPressed(robot.liftSubsystem, LiftSubsystem::moveUp);
102-
liftDown.whenPressed(robot.liftSubsystem, LiftSubsystem::moveDown);
96+
liftUp.whenPressed(Commands.Lift.moveUp(robot.liftSubsystem));
97+
liftDown.whenPressed(Commands.Lift.moveDown(robot.liftSubsystem));
10398
}
10499

105100
// Joysticks require a "scheduleJoystick" thing, so the commands are invoked all the time
106101
private void bindDrivebaseControls() {
107102
CommandScheduler
108103

109-
.scheduleJoystick(
110-
// new TankDriveCommand(robot.tankDriveBase, leftTankStick, rightTankStick, snapToAngle)
111-
new MecDriveCommand(robot.mecanumDrivebase, leftMecDriveStick, rightMecDriveStick)
112-
);
104+
.scheduleJoystick(
105+
// new TankDriveCommand(robot.tankDriveBase, leftTankStick, rightTankStick, snapToAngle)
106+
new MecDriveCommand(robot.mecanumDrivebase, leftMecDriveStick, rightMecDriveStick)
107+
);
113108
}
114109

115110
private void bindTesterControls() {
116-
encMotorTestUp.whenPressed(robot.encodedMotorSubsystem, MotorAsServoSubsystem::increaseEncMotor);
117-
encMotorTestDown.whenPressed(robot.encodedMotorSubsystem, MotorAsServoSubsystem::decreaseEncMotor);
111+
encMotorTestUp.whenPressed(Commands.MotorAsServo.increaseEncMotor(robot.encodedMotorSubsystem));
112+
encMotorTestDown.whenPressed(Commands.MotorAsServo.decreaseEncMotor(robot.encodedMotorSubsystem));
118113

119-
motorTestUp.whenPressed(robot.movementTestingSubsystem, MovementTestingSubsystem::increaseMotorSpeed);
120-
motorTestDown.whenPressed(robot.movementTestingSubsystem, MovementTestingSubsystem::decreaseMotorSpeed);
114+
motorTestUp.whenPressed(Commands.MovementTesting.incMotorSpeed(robot.movementTestingSubsystem));
115+
motorTestDown.whenPressed(Commands.MovementTesting.decMotorSpeed(robot.movementTestingSubsystem));
121116

122-
servoTestUp.whenPressed(robot.movementTestingSubsystem, MovementTestingSubsystem::increaseServoMotor);
123-
servoTestDown.whenPressed(robot.movementTestingSubsystem, MovementTestingSubsystem::decreaseServoMotor);
117+
servoTestUp.whenPressed(Commands.MovementTesting.incServoSpeed(robot.movementTestingSubsystem));
118+
servoTestDown.whenPressed(Commands.MovementTesting.decServoSpeed(robot.movementTestingSubsystem));
124119

125120
// For this stuff, ParallelCommandGroups or SequentialCommandGroups both work the same
126121
// For command that take "time" you parallel command groups (as they will run at the same
127122
// time as the other commands) but if you want "do A, then do B, then do C" you should
128123
// use a sequential command group
129124
stop.whenPressed(
130-
new ParallelCommandGroup(
131-
new SimpleCommand(robot.movementTestingSubsystem::neutralMotorSpeed),
132-
new SimpleCommand(robot.movementTestingSubsystem::neutralServoMotor),
133-
new SimpleRequiredCommand<>(robot.encodedMotorSubsystem, MotorAsServoSubsystem::stop)
134-
)
125+
new ParallelCommandGroup(
126+
Commands.MovementTesting.neutralMotorSpeed(robot.movementTestingSubsystem),
127+
Commands.MovementTesting.neutralServoSpeed(robot.movementTestingSubsystem),
128+
Commands.MotorAsServo.stop(robot.encodedMotorSubsystem)
129+
)
135130
);
136131
halt.whenPressed(
137-
new ParallelCommandGroup(
138-
new SimpleCommand(robot.movementTestingSubsystem::brakeMotor),
139-
new SimpleCommand(robot.movementTestingSubsystem::neutralServoMotor),
140-
new SimpleRequiredCommand<>(robot.encodedMotorSubsystem, MotorAsServoSubsystem::halt)
141-
)
132+
new ParallelCommandGroup(
133+
Commands.MovementTesting.brakeMotor(robot.movementTestingSubsystem),
134+
Commands.MovementTesting.neutralServoSpeed(robot.movementTestingSubsystem),
135+
Commands.MotorAsServo.halt(robot.encodedMotorSubsystem)
136+
)
142137
);
143138
}
144139
}

Twenty403/src/main/java/org/firstinspires/ftc/twenty403/Robot.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
import org.firstinspires.ftc.twenty403.subsystem.ClawSubsystem;
88
import org.firstinspires.ftc.twenty403.subsystem.DrivebaseSubsystem;
99
import org.firstinspires.ftc.twenty403.subsystem.LiftSubsystem;
10-
import org.firstinspires.ftc.twenty403.subsystem.VisionSubsystem;
1110
import org.firstinspires.ftc.twenty403.subsystem.OdoSubsystem;
11+
import org.firstinspires.ftc.twenty403.subsystem.VisionSubsystem;
1212

1313
public class Robot implements Loggable {
1414

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
package org.firstinspires.ftc.twenty403.command;
2+
3+
import android.util.Pair;
4+
import com.technototes.library.command.ChoiceCommand;
5+
import com.technototes.library.command.Command;
6+
import com.technototes.library.command.SequentialCommandGroup;
7+
import com.technototes.library.command.SimpleCommand;
8+
import com.technototes.library.command.SimpleRequiredCommand;
9+
import com.technototes.path.command.TrajectorySequenceCommand;
10+
import org.firstinspires.ftc.twenty403.Robot;
11+
import org.firstinspires.ftc.twenty403.command.autonomous.AutoConstants;
12+
// This one has been converted to a local command as an example
13+
// import org.firstinspires.ftc.twenty403.command.autonomous.right.AutoRightCycleLeft;
14+
import org.firstinspires.ftc.twenty403.command.autonomous.right.AutoRightCycleMiddle;
15+
import org.firstinspires.ftc.twenty403.command.autonomous.right.AutoRightCycleRight;
16+
import org.firstinspires.ftc.twenty403.subsystem.ClawSubsystem;
17+
import org.firstinspires.ftc.twenty403.subsystem.DrivebaseSubsystem;
18+
import org.firstinspires.ftc.twenty403.subsystem.LiftSubsystem;
19+
20+
public class Commands {
21+
22+
// If you prefer, we could name commands ClawOpen, instead of Claw.open (or Claw.Open)
23+
// In addition, every autonomous command that just extends a command type, and only
24+
// has a constructor could be moved into this format of command.
25+
// The onlyk problem I see is that this file would become problematic for merge conflicts
26+
// For an example:
27+
public static class Auto {
28+
29+
public static class Right {
30+
31+
public static Command ParkingSelectionCycle(Robot r) {
32+
return new ChoiceCommand(
33+
// Note that by putting these things in their respective static classes,
34+
// much of the auto code may be identical, as this "CycleLeft" function
35+
// is calling the Auto.Right.CycleLeft function. We could call it that
36+
// way if we wanted. I could also moving the Auto.Right into a completely
37+
// separate file, so they're invoked as "AutoCmds.Right.ParkingSelectionCycle"
38+
new Pair<>(r.visionSystem::left, CycleLeft(r)),
39+
new Pair<>(r.visionSystem::middle, new AutoRightCycleMiddle(r)),
40+
new Pair<>(r.visionSystem::right, new AutoRightCycleRight(r))
41+
);
42+
}
43+
44+
public static Command CycleLeft(Robot r) {
45+
// This is instead of the AutoRightCycleLeft command
46+
// (it's literally a copy of the constructor of that thing)
47+
return new SequentialCommandGroup(
48+
new TrajectorySequenceCommand(
49+
r.drivebaseSubsystem,
50+
AutoConstants.Right.START_TO_W_JUNCTION
51+
)
52+
.alongWith(Commands.Lift.highJunction(r.liftSubsystem)),
53+
Commands.Claw.open(r.clawSubsystem),
54+
new TrajectorySequenceCommand(
55+
r.drivebaseSubsystem,
56+
AutoConstants.Right.W_JUNCTION_TO_STACK_ONE
57+
)
58+
.alongWith(Commands.Lift.collect(r.liftSubsystem)),
59+
Commands.Claw.close(r.clawSubsystem),
60+
new TrajectorySequenceCommand(
61+
r.drivebaseSubsystem,
62+
AutoConstants.Right.STACK_TO_W_JUNCTION_ONE
63+
)
64+
.alongWith(Commands.Lift.highJunction(r.liftSubsystem)),
65+
Commands.Claw.open(r.clawSubsystem),
66+
new TrajectorySequenceCommand(
67+
r.drivebaseSubsystem,
68+
AutoConstants.Right.W_JUNCTION_TO_LEFT_PARK
69+
)
70+
.alongWith(Commands.Lift.collect(r.liftSubsystem))
71+
);
72+
}
73+
}
74+
}
75+
76+
public static class Claw {
77+
78+
public static Command open(ClawSubsystem clawSubsystem) {
79+
return new SimpleRequiredCommand<>(clawSubsystem, ClawSubsystem::open);
80+
}
81+
82+
public static Command close(ClawSubsystem clawSubsystem) {
83+
return new SimpleRequiredCommand<>(clawSubsystem, ClawSubsystem::close);
84+
}
85+
86+
public static Command toggleAutoClose(ClawSubsystem claw) {
87+
return new SimpleRequiredCommand<>(claw, ClawSubsystem::toggleAutoClose);
88+
}
89+
}
90+
91+
public static class Drive {
92+
93+
public static Command fast(DrivebaseSubsystem drive) {
94+
return new SimpleCommand(drive::fast);
95+
}
96+
97+
public static Command slow(DrivebaseSubsystem drive) {
98+
return new SimpleCommand(drive::slow);
99+
}
100+
101+
public static Command zeroHeading(DrivebaseSubsystem drive) {
102+
return new SimpleCommand(drive::setExternalHeading, 0.0);
103+
}
104+
105+
public static Command cancelTileRequest(DrivebaseSubsystem drive) {
106+
return new SimpleCommand(drive::requestCancelled);
107+
}
108+
}
109+
110+
public static class Lift {
111+
112+
public static Command moveUp(LiftSubsystem lift) {
113+
return new SimpleRequiredCommand<>(lift, LiftSubsystem::moveUp);
114+
}
115+
116+
public static Command moveDown(LiftSubsystem lift) {
117+
return new SimpleRequiredCommand<>(lift, LiftSubsystem::moveDown);
118+
}
119+
120+
public static Command moveUp_OVERRIDE(LiftSubsystem lift) {
121+
return new SimpleRequiredCommand<>(lift, LiftSubsystem::moveUp_OVERRIDE);
122+
}
123+
124+
public static Command moveDown_OVERRIDE(LiftSubsystem lift) {
125+
return new SimpleRequiredCommand<>(lift, LiftSubsystem::moveDown_OVERRIDE);
126+
}
127+
128+
public static Command collect(LiftSubsystem lift) {
129+
return new SimpleRequiredCommand<>(lift, LiftSubsystem::collect);
130+
}
131+
132+
public static Command highJunction(LiftSubsystem lift) {
133+
return new SimpleRequiredCommand<>(lift, LiftSubsystem::highPole);
134+
}
135+
136+
public static Command midJunction(LiftSubsystem lift) {
137+
return new SimpleRequiredCommand<>(lift, LiftSubsystem::midPole);
138+
}
139+
140+
public static Command lowJunction(LiftSubsystem lift) {
141+
return new SimpleRequiredCommand<>(lift, LiftSubsystem::lowPole);
142+
}
143+
144+
public static Command groundJunction(LiftSubsystem lift) {
145+
return new SimpleRequiredCommand<>(lift, LiftSubsystem::groundJunction);
146+
}
147+
148+
public static Command intake(LiftSubsystem lift) {
149+
return new SimpleRequiredCommand<>(lift, LiftSubsystem::intakePos);
150+
}
151+
152+
public static Command setNewZero(LiftSubsystem lift) {
153+
return new SimpleRequiredCommand<>(lift, LiftSubsystem::setNewZero);
154+
}
155+
}
156+
}

0 commit comments

Comments
 (0)