-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDrivetrainSubsystem.java
More file actions
88 lines (70 loc) · 3.44 KB
/
Copy pathDrivetrainSubsystem.java
File metadata and controls
88 lines (70 loc) · 3.44 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
package frc.robot.subsystems;
import static frc.robot.Constants.DrivetrainConstants.DEVICE_ID_LEFT_LEADER;
import static frc.robot.Constants.DrivetrainConstants.DEVICE_ID_LEFT_FOLLOWER;
import static frc.robot.Constants.DrivetrainConstants.DEVICE_ID_RIGHT_LEADER;
import static frc.robot.Constants.DrivetrainConstants.SPEED_LIMIT;
import static frc.robot.Constants.DrivetrainConstants.DEVICE_ID_RIGHT_FOLLOWER;
import com.revrobotics.CANSparkMax;
import com.revrobotics.CANSparkBase.IdleMode;
import com.revrobotics.CANSparkLowLevel.MotorType;
import edu.wpi.first.wpilibj.drive.DifferentialDrive;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj2.command.SubsystemBase;
import edu.wpi.first.wpilibj.shuffleboard.Shuffleboard;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
public class DrivetrainSubsystem extends SubsystemBase {
private final DifferentialDrive differentialDrive;
private double newSpeed;
private double limit = 0.4;
private boolean outreachMode = true;
public DrivetrainSubsystem() {
CANSparkMax leftLeader = new CANSparkMax(DEVICE_ID_LEFT_LEADER, MotorType.kBrushless);
CANSparkMax leftFollower = new CANSparkMax(DEVICE_ID_LEFT_FOLLOWER, MotorType.kBrushless);
CANSparkMax rightLeader = new CANSparkMax(DEVICE_ID_RIGHT_LEADER, MotorType.kBrushless);
CANSparkMax rightFollower = new CANSparkMax(DEVICE_ID_RIGHT_FOLLOWER, MotorType.kBrushless);
//caution: in future year migrate to elastic or a different software to Smartdashboard because of code crashes in this test version
SmartDashboard.putBoolean("outreachMode", outreachMode);
SmartDashboard.putNumber("Speed_Limit", limit);
leftLeader.restoreFactoryDefaults();
leftFollower.restoreFactoryDefaults();
rightLeader.restoreFactoryDefaults();
rightFollower.restoreFactoryDefaults();
leftLeader.setIdleMode(IdleMode.kBrake);
leftFollower.setIdleMode(IdleMode.kBrake);
rightLeader.setIdleMode(IdleMode.kBrake);
rightFollower.setIdleMode(IdleMode.kBrake);
leftLeader.setInverted(true);
leftFollower.setInverted(true);
rightLeader.setInverted(false);
rightFollower.setInverted(false);
leftFollower.follow(leftLeader);
rightFollower.follow(rightLeader);
this.differentialDrive = new DifferentialDrive(leftLeader, rightLeader);
}
public void arcadeDrive(double speed, double rotation) {
outreachMode = SmartDashboard.getBoolean("outreachMode", outreachMode);
limit = SmartDashboard.getNumber("Speed_Limit", limit);
if(outreachMode == true){
newSpeed = speed*limit;
rotation = 0;
} else {
newSpeed = speed*limit;
}
this.arcadeDrive(newSpeed, rotation, false);
}
public void arcadeDrive(double speed, double rotation, boolean squareInputs) {
if(outreachMode == true){
newSpeed = speed*limit;
rotation = 0;
} else {
newSpeed = speed*limit;
}
this.differentialDrive.arcadeDrive(newSpeed, rotation, squareInputs);
}
public void tankDrive(double leftSpeed, double rightSpeed) {
this.tankDrive(leftSpeed, rightSpeed, false);
}
public void tankDrive(double leftSpeed, double rightSpeed, boolean squareInputs) {
this.differentialDrive.tankDrive(leftSpeed, rightSpeed, squareInputs);
}
}