-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDriveTrain.java
More file actions
93 lines (73 loc) · 3.06 KB
/
DriveTrain.java
File metadata and controls
93 lines (73 loc) · 3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package frc.robot.subsystems;
import com.revrobotics.CANSparkMax;
import com.revrobotics.CANSparkMax.IdleMode;
import com.revrobotics.CANSparkMaxLowLevel.MotorType;
import com.revrobotics.RelativeEncoder;
import edu.wpi.first.wpilibj2.command.SubsystemBase;
import frc.robot.Constants;
import frc.robot.Robot;
import frc.robot.utils.SmartShuffleboard;
import frc.robot.utils.diag.DiagSparkMaxEncoder;
public class DriveTrain extends SubsystemBase {
public CANSparkMax left1;
public CANSparkMax left2;
private CANSparkMax right1;
private CANSparkMax right2;
private RelativeEncoder leftEncoder;
private RelativeEncoder rightEncoder;
private IMUSubsystem IMUSubsystem;
public DriveTrain(){
left1 = new CANSparkMax(Constants.DRIVE_LEFT1_ID, MotorType.kBrushless);
left2 = new CANSparkMax(Constants.DRIVE_LEFT2_ID, MotorType.kBrushless);
right1 = new CANSparkMax(Constants.DRIVE_RIGHT1_ID, MotorType.kBrushless);
right2 = new CANSparkMax(Constants.DRIVE_RIGHT2_ID, MotorType.kBrushless);
left1.restoreFactoryDefaults();
left2.restoreFactoryDefaults();
right1.restoreFactoryDefaults();
right2.restoreFactoryDefaults();
leftEncoder = left1.getEncoder();
rightEncoder = right1.getEncoder();
leftEncoder.setPositionConversionFactor(2);
rightEncoder.setPositionConversionFactor(2);
left2.follow(left1);
right2.follow(right1);
right1.setInverted(true);
right2.setInverted(true);
left1.setIdleMode(IdleMode.kBrake);
left2.setIdleMode(IdleMode.kBrake);
right1.setIdleMode(IdleMode.kBrake);
right2.setIdleMode(IdleMode.kBrake);
IMUSubsystem.resetGyro();
Robot.getDiagnostics().addDiagnosable(new DiagSparkMaxEncoder("Left Drive Encoder", 10, left1));
Robot.getDiagnostics().addDiagnosable(new DiagSparkMaxEncoder("Right Drive Encoder", 10, right1));
// TODO: Are there diags for the IMU?
}
public void drive(double speedLeft, double speedRight, boolean isSquared) {
if(isSquared) {
speedLeft = Math.signum(speedLeft) * Math.pow(speedLeft, 2);
speedRight = Math.signum(speedRight) * Math.pow(speedRight, 2);
}
// driveTrain.tankDrive(speedLeft, speedRight);
//The joysticks are inverted so inverting this makes it drive correctly.
left1.set(speedLeft);
right1.set(speedRight);
}
@Override
public void periodic() {
// This method will be called once per scheduler run
if (Constants.ENABLE_DEBUG) {
SmartShuffleboard.put("Drive", "Encoders", "L", getLeftEncoder());
SmartShuffleboard.put("Drive", "Encoders", "R", getRightEncoder());
}
}
public double getLeftEncoder(){
return leftEncoder.getPosition();
}
public double getRightEncoder(){
return rightEncoder.getPosition();
}
@Override
public void simulationPeriodic() {
// This method will be called once per scheduler run during simulation
}
}