1
1
package com .spikes2212 .command .drivetrains .commands ;
2
2
3
- import java .util .function .Supplier ;
4
-
5
3
import com .spikes2212 .command .drivetrains .TankDrivetrain ;
6
4
import edu .wpi .first .wpilibj2 .command .CommandBase ;
7
5
6
+ import java .util .function .Supplier ;
8
7
9
8
/**
10
- * This command moves a {@link TankDrivetrain} by linear and rotational speeds, using
11
- * the arcade control method written by WPILIB.
9
+ * A command that moves a {@link TankDrivetrain} using linear and rotational speeds.
12
10
*
13
11
* @author Yuval Levy
14
12
* @see TankDrivetrain
@@ -22,39 +20,142 @@ public class DriveArcade extends CommandBase {
22
20
protected final Supplier <Boolean > isFinished ;
23
21
24
22
/**
25
- * This constructs a new {@link DriveArcade} command that moves the given
23
+ * Whether to square the velocity suppliers.
24
+ */
25
+ protected final boolean squareInputs ;
26
+
27
+ /**
28
+ * Constructs a new {@link DriveArcade} command that moves the given
26
29
* {@link TankDrivetrain} according to speed values from Double {@link Supplier}s
27
30
* for linear and rotational movements.
28
31
*
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.
32
+ * @param drivetrain the tank drivetrain this command operates on
33
+ * @param moveValueSupplier the Double {@link Supplier} supplying the linear speed (-1 to 1).
34
+ * Positive values go forwards
35
+ * @param rotateValueSupplier the Double {@link Supplier} supplying the rotational speed (-1 to 1).
36
+ * Positive values go clockwise
37
+ * @param isFinished when to finish the command
38
+ * @param squareInputs whether to square the speed suppliers' values
32
39
*/
33
40
public DriveArcade (TankDrivetrain drivetrain , Supplier <Double > moveValueSupplier ,
34
- Supplier <Double > rotateValueSupplier , Supplier <Boolean > isFinished ) {
41
+ Supplier <Double > rotateValueSupplier , Supplier <Boolean > isFinished , boolean squareInputs ) {
35
42
addRequirements (drivetrain );
36
43
this .tankDrivetrain = drivetrain ;
37
44
this .moveValueSupplier = moveValueSupplier ;
38
45
this .rotateValueSupplier = rotateValueSupplier ;
39
46
this .isFinished = isFinished ;
47
+ this .squareInputs = squareInputs ;
48
+ }
49
+
50
+ /**
51
+ * Constructs a new {@link DriveArcade} command that moves the given
52
+ * {@link TankDrivetrain} according to speed values from Double {@link Supplier}s
53
+ * for linear and rotational movements. Does not square the inputs.
54
+ *
55
+ * @param drivetrain the tank drivetrain this command operates on
56
+ * @param moveValueSupplier the Double {@link Supplier} supplying the linear speed (-1 to 1).
57
+ * Positive values go forwards
58
+ * @param rotateValueSupplier the Double {@link Supplier} supplying the rotational speed (-1 to 1).
59
+ * Positive values go clockwise
60
+ * @param isFinished when to finish the command
61
+ */
62
+ public DriveArcade (TankDrivetrain drivetrain , Supplier <Double > moveValueSupplier ,
63
+ Supplier <Double > rotateValueSupplier , Supplier <Boolean > isFinished ) {
64
+ this (drivetrain , moveValueSupplier , rotateValueSupplier , isFinished , false );
40
65
}
41
66
67
+ /**
68
+ * Constructs a new {@link DriveArcade} command that moves the given
69
+ * {@link TankDrivetrain} according to speed values from Double {@link Supplier}s
70
+ * for linear and rotational movements.
71
+ *
72
+ * @param drivetrain the tank drivetrain this command operates on
73
+ * @param moveValueSupplier the Double {@link Supplier} supplying the linear speed (-1 to 1).
74
+ * Positive values go forwards
75
+ * @param rotateValueSupplier the Double {@link Supplier} supplying the rotational speed (-1 to 1).
76
+ * Positive values go clockwise
77
+ * @param squareInputs whether to square the speed suppliers' values
78
+ */
79
+ public DriveArcade (TankDrivetrain drivetrain , Supplier <Double > moveValueSupplier ,
80
+ Supplier <Double > rotateValueSupplier , boolean squareInputs ) {
81
+ this (drivetrain , moveValueSupplier , rotateValueSupplier , () -> false , squareInputs );
82
+ }
83
+
84
+ /**
85
+ * Constructs a new {@link DriveArcade} command that moves the given
86
+ * {@link TankDrivetrain} according to speed values from Double {@link Supplier}s
87
+ * for linear and rotational movements. Does not square the inputs.
88
+ *
89
+ * @param drivetrain the tank drivetrain this command operates on
90
+ * @param moveValueSupplier the Double {@link Supplier} supplying the linear speed (-1 to 1).
91
+ * Positive values go forwards
92
+ * @param rotateValueSupplier the Double {@link Supplier} supplying the rotational speed (-1 to 1).
93
+ * Positive values go clockwise
94
+ */
42
95
public DriveArcade (TankDrivetrain drivetrain , Supplier <Double > moveValueSupplier ,
43
96
Supplier <Double > rotateValueSupplier ) {
44
- this (drivetrain , moveValueSupplier , rotateValueSupplier , () -> false );
97
+ this (drivetrain , moveValueSupplier , rotateValueSupplier , () -> false , false );
45
98
}
46
99
47
- public DriveArcade (TankDrivetrain drivetrain , double moveValue , double rotateValue ) {
48
- this (drivetrain , () -> moveValue , () -> rotateValue , () -> false );
100
+ /**
101
+ * Constructs a new {@link DriveArcade} command that moves the given
102
+ * {@link TankDrivetrain} according to speed values for linear and rotational movements.
103
+ *
104
+ * @param drivetrain the tank drivetrain this command operates on
105
+ * @param moveValue the linear speed (-1 to 1). Positive values go forwards
106
+ * @param rotateValue the rotational speed (-1 to 1). Positive values go clockwise
107
+ * @param isFinished when to finish the command
108
+ * @param squareInputs whether to square the speed values
109
+ */
110
+ public DriveArcade (TankDrivetrain drivetrain , double moveValue ,
111
+ double rotateValue , Supplier <Boolean > isFinished , boolean squareInputs ) {
112
+ this (drivetrain , () -> moveValue , () -> rotateValue , isFinished , squareInputs );
49
113
}
50
114
51
- public DriveArcade (TankDrivetrain drivetrain , double moveValue , double rotateValue , boolean isFinished ) {
52
- this (drivetrain , () -> moveValue , () -> rotateValue , () -> isFinished );
115
+ /**
116
+ * Constructs a new {@link DriveArcade} command that moves the given
117
+ * {@link TankDrivetrain} according to speed values for linear and rotational movements. Does not square the inputs.
118
+ *
119
+ * @param drivetrain the tank drivetrain this command operates on
120
+ * @param moveValue the linear speed (-1 to 1). Positive values go forwards
121
+ * @param rotateValue the rotational speed (-1 to 1). Positive values go clockwise
122
+ * @param isFinished when to finish the command
123
+ */
124
+ public DriveArcade (TankDrivetrain drivetrain , double moveValue ,
125
+ double rotateValue , Supplier <Boolean > isFinished ) {
126
+ this (drivetrain , moveValue , rotateValue , isFinished , false );
127
+ }
128
+
129
+ /**
130
+ * Constructs a new {@link DriveArcade} command that moves the given
131
+ * {@link TankDrivetrain} according to speed values for linear and rotational movements.
132
+ *
133
+ * @param drivetrain the tank drivetrain this command operates on
134
+ * @param moveValue the linear speed (-1 to 1). Positive values go forwards
135
+ * @param rotateValue the rotational speed (-1 to 1). Positive values go clockwise
136
+ * @param squareInputs whether to square the speed values
137
+ */
138
+ public DriveArcade (TankDrivetrain drivetrain , double moveValue ,
139
+ double rotateValue , boolean squareInputs ) {
140
+ this (drivetrain , moveValue , rotateValue , () -> false , squareInputs );
141
+ }
142
+
143
+ /**
144
+ * Constructs a new {@link DriveArcade} command that moves the given
145
+ * {@link TankDrivetrain} according to speed values for linear and rotational movements. Does not square the inputs.
146
+ *
147
+ * @param drivetrain the tank drivetrain this command operates on
148
+ * @param moveValue the linear speed (-1 to 1). Positive values go forwards
149
+ * @param rotateValue the rotational speed (-1 to 1). Positive values go clockwise
150
+ */
151
+ public DriveArcade (TankDrivetrain drivetrain , double moveValue ,
152
+ double rotateValue ) {
153
+ this (drivetrain , moveValue , rotateValue , () -> false , false );
53
154
}
54
155
55
156
@ Override
56
157
public void execute () {
57
- tankDrivetrain .arcadeDrive (moveValueSupplier .get (), rotateValueSupplier .get ());
158
+ tankDrivetrain .arcadeDrive (moveValueSupplier .get (), rotateValueSupplier .get (), squareInputs );
58
159
}
59
160
60
161
@ Override
0 commit comments