@@ -191,6 +191,11 @@ The following example shows how to stabilize heading using a simple P loop close
191
191
192
192
DifferentialDrive drive = new DifferentialDrive(leftMotors, rightMotors);
193
193
194
+ @Override
195
+ public void robotInit() {
196
+ rightMotors.setInverted(true);
197
+ }
198
+
194
199
@Override
195
200
public void autonomousPeriodic() {
196
201
// Setpoint is implicitly 0, since we don't want the heading to change
@@ -218,6 +223,10 @@ The following example shows how to stabilize heading using a simple P loop close
218
223
219
224
frc::DifferentialDrive drive{leftMotors, rightMotors};
220
225
226
+ void Robot::RobotInit() {
227
+ rightMotors.SetInverted(true);
228
+ }
229
+
221
230
void Robot::AutonomousPeriodic() {
222
231
// Setpoint is implicitly 0, since we don't want the heading to change
223
232
double error = -gyro.GetRate();
@@ -257,6 +266,11 @@ The following example shows how to stabilize heading using a simple P loop close
257
266
258
267
DifferentialDrive drive = new DifferentialDrive(leftMotors, rightMotors);
259
268
269
+ @Override
270
+ public void robotInit() {
271
+ rightMotors.setInverted(true);
272
+ }
273
+
260
274
@Override
261
275
public void autonomousInit() {
262
276
// Set setpoint to current heading at start of auto
@@ -292,6 +306,10 @@ The following example shows how to stabilize heading using a simple P loop close
292
306
293
307
frc::DifferentialDrive drive{leftMotors, rightMotors};
294
308
309
+ void Robot::RobotInit() {
310
+ rightMotors.SetInverted(true);
311
+ }
312
+
295
313
void Robot::AutonomousInit() {
296
314
// Set setpoint to current heading at start of auto
297
315
heading = gyro.GetAngle();
@@ -320,7 +338,7 @@ Much like with heading stabilization, this is often accomplished with a PID loop
320
338
// Use gyro declaration from above here
321
339
322
340
// The gain for a simple P loop
323
- double kP = 1 ;
341
+ double kP = 0.05 ;
324
342
325
343
// Initialize motor controllers and drive
326
344
Spark left1 = new Spark(0);
@@ -334,21 +352,26 @@ Much like with heading stabilization, this is often accomplished with a PID loop
334
352
335
353
DifferentialDrive drive = new DifferentialDrive(leftMotors, rightMotors);
336
354
355
+ @Override
356
+ public void robotInit() {
357
+ rightMotors.setInverted(true);
358
+ }
359
+
337
360
@Override
338
361
public void autonomousPeriodic() {
339
362
// Find the heading error; setpoint is 90
340
363
double error = 90 - gyro.getAngle();
341
364
342
365
// Turns the robot to face the desired direction
343
- drive.tankDrive(kP * error, kP * error);
366
+ drive.tankDrive(kP * error, - kP * error);
344
367
}
345
368
346
369
.. code-tab :: c++
347
370
348
371
// Use gyro declaration from above here
349
372
350
373
// The gain for a simple P loop
351
- double kP = 1 ;
374
+ double kP = 0.05 ;
352
375
353
376
// Initialize motor controllers and drive
354
377
frc::Spark left1{0};
@@ -361,12 +384,16 @@ Much like with heading stabilization, this is often accomplished with a PID loop
361
384
362
385
frc::DifferentialDrive drive{leftMotors, rightMotors};
363
386
387
+ void Robot::RobotInit() {
388
+ rightMotors.SetInverted(true);
389
+ }
390
+
364
391
void Robot::AutonomousPeriodic() {
365
392
// Find the heading error; setpoint is 90
366
393
double error = 90 - gyro.GetAngle();
367
394
368
395
// Turns the robot to face the desired direction
369
- drive.TankDrive(kP * error, kP * error);
396
+ drive.TankDrive(kP * error, - kP * error);
370
397
}
371
398
372
399
As before, more-advanced implementations can use more-complicated control loops.
0 commit comments