Commit | Line | Data |
---|---|---|
38a404b3 KZ |
1 | package org.usfirst.frc.team3501.robot.subsystems; |
2 | ||
3 | import org.usfirst.frc.team3501.robot.Constants; | |
111dc444 | 4 | |
38a404b3 | 5 | import edu.wpi.first.wpilibj.CANTalon; |
111dc444 YN |
6 | import edu.wpi.first.wpilibj.CounterBase.EncodingType; |
7 | import edu.wpi.first.wpilibj.Encoder; | |
38a404b3 KZ |
8 | import edu.wpi.first.wpilibj.command.Subsystem; |
9 | ||
10 | public class DriveTrain extends Subsystem { | |
1884c3cf KZ |
11 | // Drivetrain related objects |
12 | private Encoder leftEncoder, rightEncoder; | |
d7bf2340 | 13 | private CANTalon frontLeft, frontRight, rearLeft, rearRight; |
d7bf2340 KZ |
14 | |
15 | public DriveTrain() { | |
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); | |
1884c3cf | 20 | |
d7bf2340 KZ |
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); | |
45bdf5b9 KZ |
25 | leftEncoder.setDistancePerPulse(Constants.DriveTrain.INCHES_PER_PULSE); |
26 | rightEncoder.setDistancePerPulse(Constants.DriveTrain.INCHES_PER_PULSE); | |
d7bf2340 KZ |
27 | } |
28 | ||
29 | @Override | |
30 | protected void initDefaultCommand() { | |
31 | } | |
32 | ||
33 | public void resetEncoders() { | |
34 | leftEncoder.reset(); | |
35 | rightEncoder.reset(); | |
36 | } | |
37 | ||
d7bf2340 | 38 | public double getRightSpeed() { |
6833a887 | 39 | return rightEncoder.getRate(); // in inches per second |
d7bf2340 KZ |
40 | } |
41 | ||
42 | public double getLeftSpeed() { | |
6833a887 | 43 | return leftEncoder.getRate(); // in inches per second |
d7bf2340 KZ |
44 | } |
45 | ||
46 | public double getSpeed() { | |
6833a887 | 47 | return (getLeftSpeed() + getRightSpeed()) / 2.0; // in inches per second |
d7bf2340 KZ |
48 | } |
49 | ||
d7bf2340 | 50 | public double getRightDistance() { |
6833a887 | 51 | return rightEncoder.getDistance(); // in inches |
d7bf2340 KZ |
52 | } |
53 | ||
d7bf2340 | 54 | public double getLeftDistance() { |
6833a887 | 55 | return leftEncoder.getDistance(); // in inches |
d7bf2340 KZ |
56 | } |
57 | ||
58 | public double getDistance() { | |
6833a887 | 59 | return (getRightDistance() + getLeftDistance()) / 2.0; // in inches |
d7bf2340 KZ |
60 | } |
61 | ||
62 | public void stop() { | |
63 | setMotorSpeeds(0, 0); | |
64 | } | |
65 | ||
66 | public void setMotorSpeeds(double leftSpeed, double rightSpeed) { | |
1884c3cf KZ |
67 | // speed passed to right motor is negative because right motor rotates in |
68 | // opposite direction | |
d7bf2340 KZ |
69 | this.frontLeft.set(leftSpeed); |
70 | this.frontRight.set(-rightSpeed); | |
71 | this.rearLeft.set(leftSpeed); | |
72 | this.rearRight.set(-rightSpeed); | |
d7bf2340 | 73 | } |
38a404b3 | 74 | } |