4f686879a8194cb59db058f01f124846077f5883
1 package org
.usfirst
.frc
.team3501
.robot
.subsystems
;
3 import org
.usfirst
.frc
.team3501
.robot
.Constants
;
4 import org
.usfirst
.frc
.team3501
.robot
.Lidar
;
6 import edu
.wpi
.first
.wpilibj
.CANTalon
;
7 import edu
.wpi
.first
.wpilibj
.CounterBase
.EncodingType
;
8 import edu
.wpi
.first
.wpilibj
.Encoder
;
9 import edu
.wpi
.first
.wpilibj
.I2C
;
10 import edu
.wpi
.first
.wpilibj
.command
.Subsystem
;
12 public class DriveTrain
extends Subsystem
{
13 // Drivetrain related objects
14 private Encoder leftEncoder
, rightEncoder
;
15 public static Lidar leftLidar
;
16 public static Lidar rightLidar
;
17 private CANTalon frontLeft
, frontRight
, rearLeft
, rearRight
;
20 frontLeft
= new CANTalon(Constants
.DriveTrain
.FRONT_LEFT
);
21 frontRight
= new CANTalon(Constants
.DriveTrain
.FRONT_RIGHT
);
22 rearLeft
= new CANTalon(Constants
.DriveTrain
.REAR_LEFT
);
23 rearRight
= new CANTalon(Constants
.DriveTrain
.REAR_RIGHT
);
25 leftLidar
= new Lidar(I2C
.Port
.kOnboard
);
26 rightLidar
= new Lidar(I2C
.Port
.kOnboard
); // TODO: find port for second
28 leftEncoder
= new Encoder(Constants
.DriveTrain
.ENCODER_LEFT_A
,
29 Constants
.DriveTrain
.ENCODER_LEFT_B
, false, EncodingType
.k4X
);
30 rightEncoder
= new Encoder(Constants
.DriveTrain
.ENCODER_RIGHT_A
,
31 Constants
.DriveTrain
.ENCODER_RIGHT_B
, false, EncodingType
.k4X
);
32 leftEncoder
.setDistancePerPulse(Constants
.DriveTrain
.INCHES_PER_PULSE
);
33 rightEncoder
.setDistancePerPulse(Constants
.DriveTrain
.INCHES_PER_PULSE
);
37 protected void initDefaultCommand() {
40 public void resetEncoders() {
45 public double getLeftLidarDistance() {
46 return leftLidar
.pidGet();
49 public double getsRightLidarDistance() {
50 return rightLidar
.pidGet();
53 public double getRightSpeed() {
54 return rightEncoder
.getRate(); // in inches per second
57 public double getLeftSpeed() {
58 return leftEncoder
.getRate(); // in inches per second
61 public double getSpeed() {
62 return (getLeftSpeed() + getRightSpeed()) / 2.0; // in inches per second
65 public double getRightDistance() {
66 return rightEncoder
.getDistance(); // in inches
69 public double getLeftDistance() {
70 return leftEncoder
.getDistance(); // in inches
73 public double getDistance() {
74 return (getRightDistance() + getLeftDistance()) / 2.0; // in inches
81 public void setMotorSpeeds(double leftSpeed
, double rightSpeed
) {
82 // speed passed to right motor is negative because right motor rotates in
84 this.frontLeft
.set(leftSpeed
);
85 this.frontRight
.set(-rightSpeed
);
86 this.rearLeft
.set(leftSpeed
);
87 this.rearRight
.set(-rightSpeed
);