Skip to content

Commit 83a722a

Browse files
Merge pull request #205 from Spikes-2212-Programming-Guild/drive-square-input
added squareInput to DriveTank
2 parents 663288e + 9237bb4 commit 83a722a

File tree

2 files changed

+225
-23
lines changed

2 files changed

+225
-23
lines changed

src/main/java/com/spikes2212/command/drivetrains/commands/DriveArcade.java

Lines changed: 113 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
package com.spikes2212.command.drivetrains.commands;
22

3-
import java.util.function.Supplier;
4-
53
import com.spikes2212.command.drivetrains.TankDrivetrain;
64
import edu.wpi.first.wpilibj2.command.CommandBase;
75

6+
import java.util.function.Supplier;
87

98
/**
109
* This command moves a {@link TankDrivetrain} by linear and rotational speeds, using
@@ -21,35 +20,138 @@ public class DriveArcade extends CommandBase {
2120
protected final Supplier<Double> rotateValueSupplier;
2221
protected final Supplier<Boolean> isFinished;
2322

23+
/**
24+
* Whether to square the velocity suppliers.
25+
*/
26+
protected final boolean squareInputs;
27+
2428
/**
2529
* This constructs a new {@link DriveArcade} command that moves the given
2630
* {@link TankDrivetrain} according to speed values from Double {@link Supplier}s
2731
* for linear and rotational movements.
2832
*
29-
* @param drivetrain the tank drivetrain this command operates on.
30-
* @param moveValueSupplier the double {@link Supplier} supplying the linear velocity. Positive values go forwards.
31-
* @param rotateValueSupplier the double {@link Supplier} supplying the rotational velocity. Positive values go left.
33+
* @param drivetrain the tank drivetrain this command operates on
34+
* @param moveValueSupplier the double {@link Supplier} supplying the linear speed (-1 to 1).
35+
* Positive values go forwards
36+
* @param rotateValueSupplier the double {@link Supplier} supplying the rotational speed (-1 to 1).
37+
* Positive values go clockwise
38+
* @param isFinished when to finish the command
39+
* @param squareInputs whether to square the speed suppliers' values
3240
*/
3341
public DriveArcade(TankDrivetrain drivetrain, Supplier<Double> moveValueSupplier,
34-
Supplier<Double> rotateValueSupplier, Supplier<Boolean> isFinished) {
42+
Supplier<Double> rotateValueSupplier, Supplier<Boolean> isFinished, boolean squareInputs) {
3543
addRequirements(drivetrain);
3644
this.tankDrivetrain = drivetrain;
3745
this.moveValueSupplier = moveValueSupplier;
3846
this.rotateValueSupplier = rotateValueSupplier;
3947
this.isFinished = isFinished;
48+
this.squareInputs = squareInputs;
49+
}
50+
51+
/**
52+
* This constructs a new {@link DriveArcade} command that moves the given
53+
* {@link TankDrivetrain} according to speed values from Double {@link Supplier}s
54+
* for linear and rotational movements. Does not square the inputs.
55+
*
56+
* @param drivetrain the tank drivetrain this command operates on
57+
* @param moveValueSupplier the double {@link Supplier} supplying the linear speed (-1 to 1).
58+
* Positive values go forwards
59+
* @param rotateValueSupplier the double {@link Supplier} supplying the rotational speed (-1 to 1).
60+
* Positive values go clockwise
61+
* @param isFinished when to finish the command
62+
*/
63+
public DriveArcade(TankDrivetrain drivetrain, Supplier<Double> moveValueSupplier,
64+
Supplier<Double> rotateValueSupplier, Supplier<Boolean> isFinished) {
65+
this(drivetrain, moveValueSupplier, rotateValueSupplier, isFinished, false);
66+
}
67+
68+
/**
69+
* This constructs a new {@link DriveArcade} command that moves the given
70+
* {@link TankDrivetrain} according to speed values from Double {@link Supplier}s
71+
* for linear and rotational movements.
72+
*
73+
* @param drivetrain the tank drivetrain this command operates on
74+
* @param moveValueSupplier the double {@link Supplier} supplying the linear speed (-1 to 1).
75+
* Positive values go forwards
76+
* @param rotateValueSupplier the double {@link Supplier} supplying the rotational speed (-1 to 1).
77+
* Positive values go clockwise
78+
* @param squareInputs whether to square the speed suppliers' values
79+
*/
80+
public DriveArcade(TankDrivetrain drivetrain, Supplier<Double> moveValueSupplier,
81+
Supplier<Double> rotateValueSupplier, boolean squareInputs) {
82+
this(drivetrain, moveValueSupplier, rotateValueSupplier, () -> false, squareInputs);
4083
}
4184

85+
/**
86+
* This constructs a new {@link DriveArcade} command that moves the given
87+
* {@link TankDrivetrain} according to speed values from Double {@link Supplier}s
88+
* for linear and rotational movements. Does not square the inputs.
89+
*
90+
* @param drivetrain the tank drivetrain this command operates on
91+
* @param moveValueSupplier the double {@link Supplier} supplying the linear speed (-1 to 1).
92+
* Positive values go forwards
93+
* @param rotateValueSupplier the double {@link Supplier} supplying the rotational speed (-1 to 1).
94+
* Positive values go clockwise
95+
*/
4296
public DriveArcade(TankDrivetrain drivetrain, Supplier<Double> moveValueSupplier,
4397
Supplier<Double> rotateValueSupplier) {
44-
this(drivetrain, moveValueSupplier, rotateValueSupplier, () -> false);
98+
this(drivetrain, moveValueSupplier, rotateValueSupplier, () -> false, false);
4599
}
46100

47-
public DriveArcade(TankDrivetrain drivetrain, double moveValue, double rotateValue) {
48-
this(drivetrain, () -> moveValue, () -> rotateValue, () -> false);
101+
/**
102+
* This constructs a new {@link DriveArcade} command that moves the given
103+
* {@link TankDrivetrain} according to speed values for linear and rotational movements.
104+
*
105+
* @param drivetrain the tank drivetrain this command operates on
106+
* @param moveValue the linear speed (-1 to 1). Positive values go forwards
107+
* @param rotateValue the rotational speed (-1 to 1). Positive values go clockwise
108+
* @param isFinished when to finish the command
109+
* @param squareInputs whether to square the speed values
110+
*/
111+
public DriveArcade(TankDrivetrain drivetrain, double moveValue,
112+
double rotateValue, Supplier<Boolean> isFinished, boolean squareInputs) {
113+
this(drivetrain, () -> moveValue, () -> rotateValue, isFinished, squareInputs);
49114
}
50115

51-
public DriveArcade(TankDrivetrain drivetrain, double moveValue, double rotateValue, Supplier<Boolean> isFinished) {
52-
this(drivetrain, () -> moveValue, () -> rotateValue, isFinished);
116+
/**
117+
* This constructs a new {@link DriveArcade} command that moves the given
118+
* {@link TankDrivetrain} according to speed values for linear and rotational movements. Does not square the inputs.
119+
*
120+
* @param drivetrain the tank drivetrain this command operates on
121+
* @param moveValue the linear speed (-1 to 1). Positive values go forwards
122+
* @param rotateValue the rotational speed (-1 to 1). Positive values go clockwise
123+
* @param isFinished when to finish the command
124+
*/
125+
public DriveArcade(TankDrivetrain drivetrain, double moveValue,
126+
double rotateValue, Supplier<Boolean> isFinished) {
127+
this(drivetrain, moveValue, rotateValue, isFinished, false);
128+
}
129+
130+
/**
131+
* This constructs a new {@link DriveArcade} command that moves the given
132+
* {@link TankDrivetrain} according to speed values for linear and rotational movements.
133+
*
134+
* @param drivetrain the tank drivetrain this command operates on
135+
* @param moveValue the linear speed (-1 to 1). Positive values go forwards
136+
* @param rotateValue the rotational speed (-1 to 1). Positive values go clockwise
137+
* @param squareInputs whether to square the speed values
138+
*/
139+
public DriveArcade(TankDrivetrain drivetrain, double moveValue,
140+
double rotateValue, boolean squareInputs) {
141+
this(drivetrain, moveValue, rotateValue, () -> false, squareInputs);
142+
}
143+
144+
/**
145+
* This constructs a new {@link DriveArcade} command that moves the given
146+
* {@link TankDrivetrain} according to speed values for linear and rotational movements. Does not square the inputs.
147+
*
148+
* @param drivetrain the tank drivetrain this command operates on
149+
* @param moveValue the linear speed (-1 to 1). Positive values go forwards
150+
* @param rotateValue the rotational speed (-1 to 1). Positive values go clockwise
151+
*/
152+
public DriveArcade(TankDrivetrain drivetrain, double moveValue,
153+
double rotateValue) {
154+
this(drivetrain, moveValue, rotateValue, () -> false, false);
53155
}
54156

55157
@Override

src/main/java/com/spikes2212/command/drivetrains/commands/DriveTank.java

Lines changed: 112 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,46 +17,146 @@ public class DriveTank extends CommandBase {
1717
protected final Supplier<Double> leftSpeedSupplier;
1818
protected final Supplier<Double> rightSpeedSupplier;
1919
protected final Supplier<Boolean> isFinished;
20+
protected final boolean squareInputs;
2021

2122
/**
2223
* This constructs a new {@link DriveTank} command that moves the given
23-
* {@link TankDrivetrain} according to speed values from Double {@link Supplier}s for left and right sides.<br>
24-
* Positive values move forwards.
24+
* {@link TankDrivetrain} according to speed values from Double {@link Supplier}s for left and right sides. <br>
25+
* Positive values move the drivetrain forward.
2526
*
26-
* @param drivetrain the drivetrain this command requires and moves.
27-
* @param leftSpeedSupplier the double {@link Supplier} supplying the speed to move on the left side with.
28-
* @param rightSpeedSupplier the double {@link Supplier} supplying the speed to move on the right side with.
27+
* @param drivetrain the tank drivetrain this command operates on
28+
* @param leftSpeedSupplier the double {@link Supplier} supplying the left side's speed (-1 to 1).
29+
* Positive values go forwards
30+
* @param rightSpeedSupplier the double {@link Supplier} supplying the right side's speed (-1 to 1).
31+
* Positive values go forwards
32+
* @param isFinished when to finish the command
33+
* @param squareInputs whether to square the speed suppliers' values
2934
*/
3035
public DriveTank(TankDrivetrain drivetrain, Supplier<Double> leftSpeedSupplier,
31-
Supplier<Double> rightSpeedSupplier, Supplier<Boolean> isFinished) {
36+
Supplier<Double> rightSpeedSupplier, Supplier<Boolean> isFinished, boolean squareInputs) {
3237
addRequirements(drivetrain);
3338
this.tankDrivetrain = drivetrain;
3439
this.leftSpeedSupplier = leftSpeedSupplier;
3540
this.rightSpeedSupplier = rightSpeedSupplier;
3641
this.isFinished = isFinished;
42+
this.squareInputs = squareInputs;
43+
}
44+
45+
/**
46+
* This constructs a new {@link DriveTank} command that moves the given
47+
* {@link TankDrivetrain} according to speed values from Double {@link Supplier}s for left and right sides. <br>
48+
* Positive values move the drivetrain forward. Does not square the inputs.
49+
*
50+
* @param drivetrain the tank drivetrain this command operates on
51+
* @param leftSpeedSupplier the double {@link Supplier} supplying the left side's speed (-1 to 1).
52+
* Positive values go forwards
53+
* @param rightSpeedSupplier the double {@link Supplier} supplying the right side's speed (-1 to 1).
54+
* Positive values go forwards
55+
* @param isFinished when to finish the command
56+
*/
57+
public DriveTank(TankDrivetrain drivetrain, Supplier<Double> leftSpeedSupplier,
58+
Supplier<Double> rightSpeedSupplier, Supplier<Boolean> isFinished) {
59+
this(drivetrain, leftSpeedSupplier, rightSpeedSupplier, isFinished, false);
60+
}
61+
62+
/**
63+
* This constructs a new {@link DriveTank} command that moves the given
64+
* {@link TankDrivetrain} according to speed values from Double {@link Supplier}s for left and right sides. <br>
65+
* Positive values move the drivetrain forward.
66+
*
67+
* @param drivetrain the tank drivetrain this command operates on
68+
* @param leftSpeedSupplier the double {@link Supplier} supplying the left side's speed (-1 to 1).
69+
* Positive values go forwards
70+
* @param rightSpeedSupplier the double {@link Supplier} supplying the right side's speed (-1 to 1).
71+
* Positive values go forwards
72+
* @param squareInputs whether to square the speed suppliers' values
73+
*/
74+
public DriveTank(TankDrivetrain drivetrain, Supplier<Double> leftSpeedSupplier,
75+
Supplier<Double> rightSpeedSupplier, boolean squareInputs) {
76+
this(drivetrain, leftSpeedSupplier, rightSpeedSupplier, () -> false, squareInputs);
3777
}
3878

79+
/**
80+
* This constructs a new {@link DriveTank} command that moves the given
81+
* {@link TankDrivetrain} according to speed values from Double {@link Supplier}s for left and right sides. <br>
82+
* Positive values move the drivetrain forward. Does not square the inputs.
83+
*
84+
* @param drivetrain the tank drivetrain this command operates on
85+
* @param leftSpeedSupplier the double {@link Supplier} supplying the left side's speed (-1 to 1).
86+
* Positive values go forwards
87+
* @param rightSpeedSupplier the double {@link Supplier} supplying the right side's speed (-1 to 1).
88+
* Positive values go forwards
89+
*/
3990
public DriveTank(TankDrivetrain drivetrain, Supplier<Double> leftSpeedSupplier,
4091
Supplier<Double> rightSpeedSupplier) {
41-
this(drivetrain, leftSpeedSupplier, rightSpeedSupplier, () -> false);
92+
this(drivetrain, leftSpeedSupplier, rightSpeedSupplier, () -> false, false);
4293
}
4394

44-
public DriveTank(TankDrivetrain drivetrain, double leftSpeed, double rightSpeed, boolean isFinished) {
45-
this(drivetrain, () -> leftSpeed, () -> rightSpeed, () -> isFinished);
95+
/**
96+
* This constructs a new {@link DriveTank} command that moves the given
97+
* {@link TankDrivetrain} according to speed values for left and right sides. <br>
98+
* Positive values move the drivetrain forward.
99+
*
100+
* @param drivetrain the tank drivetrain this command operates on
101+
* @param leftSpeed the left side's speed (-1 to 1). Positive values go forwards
102+
* @param rightSpeed the right side's speed (-1 to 1). Positive values go forwards
103+
* @param isFinished when to finish the command
104+
* @param squareInputs whether to square the speed values
105+
*/
106+
public DriveTank(TankDrivetrain drivetrain, double leftSpeed,
107+
double rightSpeed, Supplier<Boolean> isFinished, boolean squareInputs) {
108+
this(drivetrain, () -> leftSpeed, () -> rightSpeed, isFinished, squareInputs);
109+
}
110+
111+
/**
112+
* This constructs a new {@link DriveTank} command that moves the given
113+
* {@link TankDrivetrain} according to speed values for left and right sides. <br>
114+
* Positive values move the drivetrain forward. Does not square the inputs.
115+
*
116+
* @param drivetrain the tank drivetrain this command operates on
117+
* @param leftSpeed the left side's speed (-1 to 1). Positive values go forwards
118+
* @param rightSpeed the right side's speed (-1 to 1). Positive values go forwards
119+
* @param isFinished when to finish the command
120+
*/
121+
public DriveTank(TankDrivetrain drivetrain, double leftSpeed, double rightSpeed, Supplier<Boolean> isFinished) {
122+
this(drivetrain, leftSpeed, rightSpeed, isFinished, false);
46123
}
47124

125+
/**
126+
* This constructs a new {@link DriveTank} command that moves the given
127+
* {@link TankDrivetrain} according to speed values for left and right sides. <br>
128+
* Positive values move the drivetrain forward.
129+
*
130+
* @param drivetrain the tank drivetrain this command operates on
131+
* @param leftSpeed the left side's speed (-1 to 1). Positive values go forwards
132+
* @param rightSpeed the right side's speed (-1 to 1). Positive values go forwards
133+
* @param squareInputs whether to square the speed values
134+
*/
135+
public DriveTank(TankDrivetrain drivetrain, double leftSpeed, double rightSpeed, boolean squareInputs) {
136+
this(drivetrain, leftSpeed, rightSpeed, () -> false, squareInputs);
137+
}
138+
139+
/**
140+
* This constructs a new {@link DriveTank} command that moves the given
141+
* {@link TankDrivetrain} according to speed values for left and right sides. <br>
142+
* Positive values move the drivetrain forward. Does not square the inputs.
143+
*
144+
* @param drivetrain the tank drivetrain this command operates on
145+
* @param leftSpeed the left side's speed (-1 to 1). Positive values go forwards
146+
* @param rightSpeed the right side's speed (-1 to 1). Positive values go forwards
147+
*/
48148
public DriveTank(TankDrivetrain drivetrain, double leftSpeed, double rightSpeed) {
49-
this(drivetrain, () -> leftSpeed, () -> rightSpeed, () -> false);
149+
this(drivetrain, leftSpeed, rightSpeed, () -> false, false);
50150
}
51151

52152
@Override
53153
public void execute() {
54-
tankDrivetrain.tankDrive(leftSpeedSupplier.get(), rightSpeedSupplier.get());
154+
tankDrivetrain.tankDrive(leftSpeedSupplier.get(), rightSpeedSupplier.get(), squareInputs);
55155
}
56156

57157
@Override
58158
public boolean isFinished() {
59-
return this.isFinished.get();
159+
return isFinished.get();
60160
}
61161

62162
@Override

0 commit comments

Comments
 (0)