6969ed1d961de1130ef7f9658578a770b4a09662
1 package org
.usfirst
.frc
.team3501
.robot
.subsystems
;
3 import org
.usfirst
.frc
.team3501
.robot
.Constants
;
5 import edu
.wpi
.first
.wpilibj
.CANTalon
;
6 import edu
.wpi
.first
.wpilibj
.CounterBase
.EncodingType
;
7 import edu
.wpi
.first
.wpilibj
.Encoder
;
8 import edu
.wpi
.first
.wpilibj
.command
.Subsystem
;
10 public class DriveTrain
extends Subsystem
{
11 // Drivetrain related objects
12 private Encoder leftEncoder
, rightEncoder
;
13 private CANTalon frontLeft
, frontRight
, rearLeft
, rearRight
;
16 frontLeft
= new CANTalon(Constants
.DriveTrain
.FRONT_LEFT
);
17 frontRight
= new CANTalon(Constants
.DriveTrain
.FRONT_RIGHT
);
18 rearLeft
= new CANTalon(Constants
.DriveTrain
.REAR_LEFT
);
19 rearRight
= new CANTalon(Constants
.DriveTrain
.REAR_RIGHT
);
21 leftEncoder
= new Encoder(Constants
.DriveTrain
.ENCODER_LEFT_A
,
22 Constants
.DriveTrain
.ENCODER_LEFT_B
, false, EncodingType
.k4X
);
23 rightEncoder
= new Encoder(Constants
.DriveTrain
.ENCODER_RIGHT_A
,
24 Constants
.DriveTrain
.ENCODER_RIGHT_B
, false, EncodingType
.k4X
);
25 leftEncoder
.setDistancePerPulse(Constants
.DriveTrain
.INCHES_PER_PULSE
);
26 rightEncoder
.setDistancePerPulse(Constants
.DriveTrain
.INCHES_PER_PULSE
);
30 protected void initDefaultCommand() {
33 public void resetEncoders() {
38 public double getRightSpeed() {
39 return rightEncoder
.getRate(); // in inches per second
42 public double getLeftSpeed() {
43 return leftEncoder
.getRate(); // in inches per second
46 public double getSpeed() {
47 return (getLeftSpeed() + getRightSpeed()) / 2.0; // in inches per second
50 public double getRightDistance() {
51 return rightEncoder
.getDistance(); // in inches
54 public double getLeftDistance() {
55 return leftEncoder
.getDistance(); // in inches
58 public double getDistance() {
59 return (getRightDistance() + getLeftDistance()) / 2.0; // in inches
66 public void setMotorSpeeds(double leftSpeed
, double rightSpeed
) {
67 // speed passed to right motor is negative because right motor rotates in
69 this.frontLeft
.set(leftSpeed
);
70 this.frontRight
.set(-rightSpeed
);
71 this.rearLeft
.set(leftSpeed
);
72 this.rearRight
.set(-rightSpeed
);