This repository was archived by the owner on Sep 7, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDriveSubsystem.java
More file actions
114 lines (85 loc) · 3.62 KB
/
DriveSubsystem.java
File metadata and controls
114 lines (85 loc) · 3.62 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
// 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.phoenix6.configs.MotorOutputConfigs;
import com.ctre.phoenix6.configs.TalonFXConfiguration;
import com.ctre.phoenix6.configs.TalonFXConfigurator;
import com.ctre.phoenix6.controls.DutyCycleOut;
import com.ctre.phoenix6.hardware.TalonFX;
import edu.wpi.first.wpilibj.XboxController;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.SubsystemBase;
import com.ctre.phoenix6.signals.InvertedValue;
import com.ctre.phoenix6.signals.NeutralModeValue;
import com.ctre.phoenix6.controls.Follower;
public class DriveSubsystem extends SubsystemBase {
private static DriveSubsystem instance;
public static DriveSubsystem getInstance() {
if(instance == null) instance = new DriveSubsystem();
return instance;
}
private static final String rio = "rio";
public final TalonFX FrontLeftDriving = new TalonFX(2, rio);
public final TalonFX FrontRightDriving = new TalonFX(1, rio);
public final TalonFX BackLeftDriving = new TalonFX(4, rio);
public final TalonFX BackRightDriving = new TalonFX(3, rio);
public final DutyCycleOut leftOut = new DutyCycleOut(0.0);
public final DutyCycleOut rightOut = new DutyCycleOut(0.0);
public DriveSubsystem() {
var leftConfiguration = new TalonFXConfiguration();
var RightConfiguration = new TalonFXConfiguration();
RightConfiguration.MotorOutput.Inverted = InvertedValue.CounterClockwise_Positive;
leftConfiguration.MotorOutput.Inverted = InvertedValue.Clockwise_Positive;
BackLeftDriving.setControl(new Follower(FrontLeftDriving.getDeviceID(), false));
BackRightDriving.setControl(new Follower(FrontRightDriving.getDeviceID(), false));
FrontLeftDriving.setSafetyEnabled(true);
FrontRightDriving.setSafetyEnabled(true);
BackLeftDriving.getConfigurator().apply(leftConfiguration);
FrontLeftDriving.getConfigurator().apply(leftConfiguration);
BackRightDriving.getConfigurator().apply(RightConfiguration);
FrontRightDriving.getConfigurator().apply(RightConfiguration);
FrontLeftDriving.setNeutralMode(NeutralModeValue.Brake);
FrontRightDriving.setNeutralMode(NeutralModeValue.Brake);
BackLeftDriving.setNeutralMode(NeutralModeValue.Brake);
BackRightDriving.setNeutralMode(NeutralModeValue.Brake);
}
/**
* Example command factory method.
*
* @return a command
*/
public Command exampleMethodCommand() {
// Inline construction of command goes here.
// Subsystem::RunOnce implicitly requires `this` subsystem.
return runOnce(
() -> {
/* one-time action goes here */
});
}
/**
* An example method querying a boolean state of the subsystem (for example, a digital sensor).
*
* @return value of some boolean subsystem state, such as a digital sensor.
*/
public boolean exampleCondition() {
// Query some boolean state, such as a digital sensor.
return false;
}
@Override
public void periodic() {
// This method will be called once per scheduler run
}
@Override
public void simulationPeriodic() {
// This method will be called once per scheduler run during simulation
}
public void arcadeDrive(double d, double e, boolean b, boolean c) {
double leftArcade = d+e;
double rightArcade = d-e;
leftOut.Output = leftArcade;
rightOut.Output = rightArcade;
FrontLeftDriving.setControl(leftOut);
FrontRightDriving.setControl(rightOut);
}
}