-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDiffTalonSubsystem.java
More file actions
137 lines (115 loc) · 4.72 KB
/
Copy pathDiffTalonSubsystem.java
File metadata and controls
137 lines (115 loc) · 4.72 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
package frc.robot.subsystems;
import com.ctre.phoenix.motorcontrol.InvertType;
import com.ctre.phoenix.motorcontrol.NeutralMode;
import com.ctre.phoenix.motorcontrol.can.BaseMotorController;
import com.ctre.phoenix.motorcontrol.can.WPI_TalonSRX;
import com.ctre.phoenix.motorcontrol.can.WPI_VictorSPX;
import com.ctre.phoenix.sensors.PigeonIMU;
import edu.wpi.first.wpilibj.DriverStation;
import edu.wpi.first.wpilibj.drive.DifferentialDrive;
import edu.wpi.first.wpilibj2.command.SubsystemBase;
import frc.lib.lib2706.SubsystemChecker;
import frc.lib.lib2706.SubsystemChecker.SubsystemType;
import frc.robot.Config;
public class DiffTalonSubsystem extends SubsystemBase {
/**
* Instance Variables
*/
private WPI_TalonSRX leftLeader, rightLeader;
private BaseMotorController leftFollower, rightFollower;
private DifferentialDrive diffDrive;
private PigeonIMU pigeon;
private static DiffTalonSubsystem instance;
public static DiffTalonSubsystem getInstance() {
if (instance == null) {
if (Config.DIFF.ISNEOS) {
DriverStation.reportError(
String.format("DiffTalonSubsystem.getInstance() was called even though Config.DIFF_ISNEOS is true. RobotID: %d", Config.getRobotId()),
true);
} else {
SubsystemChecker.subsystemConstructed(SubsystemType.DiffTalonSubsystem);
instance = new DiffTalonSubsystem();
}
}
return instance;
}
/** Creates a new ExampleSubsystem. */
public DiffTalonSubsystem() {
leftLeader = new WPI_TalonSRX(Config.DIFF.DIFF_LEADER_LEFT);
rightLeader = new WPI_TalonSRX(Config.DIFF.DIFF_LEADER_RIGHT);
// Check whether to construct a victor or a talon or nothing
if(Config.DIFF.HAS_FOLLOWERS == true){
if (Config.DIFF.LEFT_FOLLOWER_ISVICTOR) {
leftFollower = new WPI_VictorSPX(Config.DIFF.DIFF_FOLLOWER_LEFT);
} else {
leftFollower = new WPI_TalonSRX(Config.DIFF.DIFF_FOLLOWER_LEFT);
}
if (Config.DIFF.RIGHT_FOLLOWER_ISVICTOR) {
rightFollower = new WPI_VictorSPX(Config.DIFF.DIFF_FOLLOWER_RIGHT);
} else {
rightFollower = new WPI_TalonSRX(Config.DIFF.DIFF_FOLLOWER_RIGHT);
}
}
else{
leftFollower = null;
rightFollower = null;
}
leftLeader.configFactoryDefault(Config.CAN_TIMEOUT_LONG);
rightLeader.configFactoryDefault(Config.CAN_TIMEOUT_LONG);
leftLeader.setInverted(Config.DIFF.LEADER_LEFT_INVERTED);
rightLeader.setInverted(Config.DIFF.LEADER_RIGHT_INVERTED);
if (leftFollower != null && rightFollower != null) {
leftFollower.configFactoryDefault();
rightFollower.configFactoryDefault();
leftFollower.setInverted(
Config.DIFF.FOLLOWER_LEFT_INVERTED ? InvertType.OpposeMaster : InvertType.FollowMaster);
rightFollower.setInverted(
Config.DIFF.FOLLOWER_RIGHT_INVERTED ? InvertType.OpposeMaster : InvertType.FollowMaster);
}
if (Config.CANID.PIGEON.val() != -1) {
if (Config.CANID.PIGEON.val() == Config.DIFF.DIFF_FOLLOWER_LEFT && leftFollower != null)
pigeon = new PigeonIMU((WPI_TalonSRX) leftFollower);
else {
pigeon = new PigeonIMU(Config.CANID.PIGEON.val());
}
}
diffDrive = new DifferentialDrive(leftLeader, rightLeader);
}
public void stopMotors() {
leftLeader.stopMotor();
rightLeader.stopMotor();
if(leftFollower != null) {
leftFollower.neutralOutput();
}
if(rightFollower != null){
rightFollower.neutralOutput();
}
}
/**
* Set the {@link NeutralMode} of the motors.
*
* @param mode Desired NeutralMode.
*/
public void setNeutralMode(NeutralMode mode) {
leftLeader.setNeutralMode(mode);
rightLeader.setNeutralMode(mode);
if(leftFollower != null){
leftFollower.setNeutralMode(mode);
}
if(rightFollower != null){
rightFollower.setNeutralMode(mode);
}
}
/**
* Motor control method for arcade drive.
*
* @param forwardVal The forward value
* @param rotateVal The rotate value
*/
public void arcadeDrive(double forwardVal, double rotateVal) {
diffDrive.arcadeDrive(forwardVal, rotateVal, false);
}
}