5
5
#include < frc/smartdashboard/SendableBuilder.h>
6
6
7
7
#include < cmath>
8
+ #include < iostream>
9
+ #include < iomanip>
8
10
9
11
DriveTrain::DriveTrain (wpi::json &jsonConfig) : frc::Subsystem(" DriveTrain" ) {
10
12
# ifndef PROTOBOT
11
- // Set up TalonSRXs.
12
- m_MotorRightFront.ConfigFactoryDefault ();
13
- m_MotorRightBack.ConfigFactoryDefault ();
14
- m_MotorLeftFront.ConfigFactoryDefault ();
15
- m_MotorLeftBack.ConfigFactoryDefault ();
16
-
17
- int contLimit = 40 ;
18
- int peakLimit = 50 ;
19
- int peakTime = 1800 ;
20
-
21
- m_MotorRightFront.EnableCurrentLimit (true );
22
- m_MotorRightFront.ConfigContinuousCurrentLimit (contLimit, 10 );
23
- m_MotorRightFront.ConfigPeakCurrentLimit (peakLimit, 10 );
24
- m_MotorRightFront.ConfigPeakCurrentDuration (peakTime, 10 );
25
-
26
- m_MotorRightBack.EnableCurrentLimit (true );
27
- m_MotorRightBack.ConfigContinuousCurrentLimit (contLimit, 10 );
28
- m_MotorRightBack.ConfigPeakCurrentLimit (peakLimit, 10 );
29
- m_MotorRightBack.ConfigPeakCurrentDuration (peakTime, 10 );
30
-
31
- m_MotorLeftFront.EnableCurrentLimit (true );
32
- m_MotorLeftFront.ConfigContinuousCurrentLimit (contLimit, 10 );
33
- m_MotorLeftFront.ConfigPeakCurrentLimit (peakLimit, 10 );
34
- m_MotorLeftFront.ConfigPeakCurrentDuration (peakTime, 10 );
35
-
36
- m_MotorLeftBack.EnableCurrentLimit (true );
37
- m_MotorLeftBack.ConfigContinuousCurrentLimit (contLimit, 10 );
38
- m_MotorLeftBack.ConfigPeakCurrentLimit (peakLimit, 10 );
39
- m_MotorLeftBack.ConfigPeakCurrentDuration (peakTime, 10 );
40
-
41
- // The documentation says to do this, so that both sides get the proper values.
42
- // See https://phoenix-documentation.readthedocs.io/en/latest/ch15_WPIDrive.html?highlight=wpi_talon
43
- m_MotorRightFront.SetInverted (false );
44
- m_MotorRightBack.SetInverted (false );
45
- m_MotorLeftFront.SetInverted (true );
46
- m_MotorLeftBack.SetInverted (true );
13
+ // m_MotorRightFront.SetSmartCurrentLimit(45);
14
+ // m_MotorRightFront.SetSecondaryCurrentLimit(60);
47
15
16
+ // m_MotorRightBack.SetSmartCurrentLimit(45);
17
+ // m_MotorRightBack.SetSecondaryCurrentLimit(60);
18
+
19
+ // m_MotorLeftFront.SetSmartCurrentLimit(45);
20
+ // m_MotorLeftFront.SetSecondaryCurrentLimit(60);
21
+
22
+ // m_MotorLeftBack.SetSmartCurrentLimit(45);
23
+ // m_MotorLeftBack.SetSecondaryCurrentLimit(60);
24
+
25
+ m_MotorRight1.SetInverted (false );
26
+ m_MotorRight2.SetInverted (false );
27
+ m_MotorRight3.SetInverted (false );
28
+ m_MotorLeft1.SetInverted (true );
29
+ m_MotorLeft2.SetInverted (true );
30
+ m_MotorLeft3.SetInverted (true );
31
+
32
+ SetIdleMode (m_IdleMode);
48
33
# endif
49
34
50
35
m_EncoderLeft.SetDistancePerPulse (kEncoderDistPerPulse );
@@ -54,7 +39,7 @@ DriveTrain::DriveTrain(wpi::json &jsonConfig) : frc::Subsystem("DriveTrain") {
54
39
Subsystem::AddChild (" Left Drive PID" , &m_LeftPID);
55
40
Subsystem::AddChild (" Right Drive PID" , &m_RightPID);
56
41
#else
57
- m_MaxAcceleration = jsonConfig[" drive" ][" max -acceleration" ];
42
+ m_MinAcceleration = jsonConfig[" drive" ][" min -acceleration" ];
58
43
59
44
m_MaxNormalSpeed = jsonConfig[" drive" ][" max-normal-speed" ];
60
45
m_SandstormStepSpeed = jsonConfig[" drive" ][" sandstorm-step-speed" ];
@@ -88,11 +73,11 @@ void DriveTrain::Drive(frc::XboxController& driver) {
88
73
// Get left stick axes values.
89
74
double hidX = -driver.GetX (frc::XboxController::kRightHand );
90
75
double hidY = driver.GetY (frc::XboxController::kLeftHand );
91
- double sprintFactor = 0.75 ;
76
+ double sprintFactor = 0.65 ;
92
77
sprintFactor += driver.GetTriggerAxis (frc::XboxController::kRightHand ) * 0.25 ;
93
- sprintFactor -= driver.GetTriggerAxis (frc::XboxController::kLeftHand ) * 0.25 ;
78
+ sprintFactor -= driver.GetTriggerAxis (frc::XboxController::kLeftHand ) * 0.20 ;
94
79
95
- double turnFactor = 1 - (driver.GetTriggerAxis (frc::XboxController::kLeftHand ) * 0.3 ); // THIS
80
+ double turnFactor = 0.6 - (driver.GetTriggerAxis (frc::XboxController::kLeftHand ) * 0.15 ); // THIS
96
81
97
82
if (ENABLE_DRIVETRAIN_CONTROL) {
98
83
ArcadeDrive (hidY * sprintFactor, hidX * turnFactor, true );
@@ -162,27 +147,7 @@ void DriveTrain::ArcadeDrive(double xSpeed, double zRotation, bool squareInputs)
162
147
double currentLeft = m_LeftMotors.Get () / m_maxOutput;
163
148
double currentRight = m_RightMotors.Get () / m_maxOutput;
164
149
165
- double maxLeftAccel = m_MaxAcceleration, maxRightAccel = m_MaxAcceleration;
166
-
167
- /* *
168
- // Descrease the max velocity step size for the slower drive side so
169
- // turning takes effect sooner.
170
- //
171
- // WARNING: Doesn't really work from initial testing. Robot drives more straight.
172
- if (0.01 < std::abs(desiredLeft) - std::abs(desiredRight)) {
173
- // Left speed is faster than right.
174
- maxLeftAccel = m_MaxAcceleration;
175
- maxRightAccel = m_MaxAcceleration * desiredRight / desiredLeft;
176
- } else if (0.01 < std::abs(desiredRight) - std::abs(desiredLeft)) {
177
- // Right speed is faster than left.
178
- maxLeftAccel = m_MaxAcceleration * desiredLeft / desiredRight;
179
- maxRightAccel = m_MaxAcceleration;
180
- } else {
181
- // Both speeds are effectively same.
182
- maxLeftAccel = m_MaxAcceleration;
183
- maxRightAccel = m_MaxAcceleration;
184
- }
185
- /* */
150
+ double minLeftAccel = m_MinAcceleration, minRightAccel = m_MinAcceleration;
186
151
187
152
double timeDelta = m_TimeDelta.Split ();
188
153
@@ -194,17 +159,17 @@ void DriveTrain::ArcadeDrive(double xSpeed, double zRotation, bool squareInputs)
194
159
// v_{i+1} is the next velocity to send to the motors,
195
160
// a is the max acceleration, and
196
161
// dt is the time delta in seconds since the velocity step.
197
- double allowedLeft = ComputeNextOutputDelta (
162
+ double allowedLeft = ComputeNextOutput (
198
163
currentLeft,
199
164
desiredLeft,
200
- maxLeftAccel ,
165
+ minLeftAccel ,
201
166
timeDelta
202
167
);
203
168
204
- double allowedRight = ComputeNextOutputDelta (
169
+ double allowedRight = ComputeNextOutput (
205
170
currentRight,
206
171
desiredRight,
207
- maxRightAccel ,
172
+ minRightAccel ,
208
173
timeDelta
209
174
);
210
175
@@ -225,6 +190,38 @@ void DriveTrain::ArcadeDrive(double xSpeed, double zRotation, bool squareInputs)
225
190
Feed ();
226
191
}
227
192
193
+ void DriveTrain::SetIdleMode (rev::CANSparkMax::IdleMode mode) {
194
+ m_IdleMode = mode;
195
+
196
+ m_MotorRight1.SetIdleMode (mode);
197
+ m_MotorRight2.SetIdleMode (mode);
198
+ m_MotorRight3.SetIdleMode (mode);
199
+
200
+ m_MotorLeft1.SetIdleMode (mode);
201
+ m_MotorLeft2.SetIdleMode (mode);
202
+ m_MotorLeft3.SetIdleMode (mode);
203
+ }
204
+
205
+ void DriveTrain::ToggleIdleMode () {
206
+ if (IdleMode::kCoast == m_IdleMode) {
207
+ SetIdleMode (IdleMode::kBrake );
208
+ } else {
209
+ SetIdleMode (IdleMode::kCoast );
210
+ }
211
+ }
212
+
213
+ IdleMode DriveTrain::GetIdleMode () {
214
+ return m_IdleMode;
215
+ }
216
+
217
+ wpi::StringRef DriveTrain::GetIdleModeText () {
218
+ if (IdleMode::kCoast == m_IdleMode) {
219
+ return " Coast" ;
220
+ } else {
221
+ return " Brake" ;
222
+ }
223
+ }
224
+
228
225
void DriveTrain::StopMotor () {
229
226
#ifdef USE_DRIVETRAIN_PID
230
227
m_LeftPID.Disable ();
@@ -301,7 +298,7 @@ void DriveTrain::UseDukesSpeedLimit() {
301
298
#endif
302
299
}
303
300
304
- double DriveTrain::ComputeNextOutputDelta (double iVel, double fVel , double maxAccel , double timeDelta) {
305
- double deltaVel = fVel - iVel;
306
- return iVel + std::copysign (std::min (std::abs (deltaVel), maxAccel * timeDelta ), deltaVel);
301
+ double DriveTrain::ComputeNextOutput (double iVel, double fVel , double minAccel , double timeDelta) {
302
+ double deltaVel = ( fVel - iVel) * 0.4 ;
303
+ return iVel + std::copysign (std::min (std::fabs (deltaVel), minAccel ), deltaVel);
307
304
}
0 commit comments