extra stuff

This commit is contained in:
66945
2023-02-28 17:47:35 -07:00
parent 197e21d6b0
commit bf57b2d40c
4 changed files with 44 additions and 9 deletions
@@ -116,6 +116,12 @@ public final class Constants {
public static final double TELE_FORWARD_SOFT_LIMIT = 0; public static final double TELE_FORWARD_SOFT_LIMIT = 0;
public static final double TELE_REVERSE_SOFT_LIMIT = 0; public static final double TELE_REVERSE_SOFT_LIMIT = 0;
public static final double kP = 0;
public static final double kI = 0;
public static final double kD = 0;
public static final double OFFSET = 0;
} }
public static final class LEDConstants { public static final class LEDConstants {
@@ -34,7 +34,7 @@ public class RobotContainer {
/* Subsystems */ /* Subsystems */
private final SwerveDrive m_robotSwerveDrive = new SwerveDrive(m_robotMap.leftFront, m_robotMap.rightFront, m_robotMap.leftBack, m_robotMap.rightBack, m_robotMap.gyro); private final SwerveDrive m_robotSwerveDrive = new SwerveDrive(m_robotMap.leftFront, m_robotMap.rightFront, m_robotMap.leftBack, m_robotMap.rightBack, m_robotMap.gyro);
private final Arm m_robotArm = new Arm(m_robotMap.pivot, m_robotMap.tele); private final Arm m_robotArm = new Arm(m_robotMap.pivot, m_robotMap.tele, m_robotMap.pivotEncoder);
private final LED m_robotLED = new LED(m_robotMap.LEDController); private final LED m_robotLED = new LED(m_robotMap.LEDController);
+3 -2
View File
@@ -131,8 +131,9 @@ public class RobotMap {
} }
// arm stuff // arm stuff
public WPI_TalonFX pivot = new WPI_TalonFX(-1); // TODO: Add real id public WPI_TalonFX pivot = new WPI_TalonFX(-1); // TODO: Add real id
public WPI_TalonFX tele = new WPI_TalonFX(-1); // TODO: Add real id public WPI_TalonFX tele = new WPI_TalonFX(-1); // TODO: Add real id
public CANCoder pivotEncoder = new CANCoder(-1);
public void configArmMotors() { public void configArmMotors() {
// config factory default // config factory default
@@ -1,7 +1,13 @@
package frc4388.robot.subsystems; package frc4388.robot.subsystems;
import com.ctre.phoenix.motorcontrol.ControlMode; import com.ctre.phoenix.motorcontrol.ControlMode;
import com.ctre.phoenix.motorcontrol.FeedbackDevice;
import com.ctre.phoenix.motorcontrol.RemoteSensorSource;
import com.ctre.phoenix.motorcontrol.can.TalonFXConfiguration;
import com.ctre.phoenix.motorcontrol.can.WPI_TalonFX; import com.ctre.phoenix.motorcontrol.can.WPI_TalonFX;
import com.ctre.phoenix.sensors.CANCoder;
import com.ctre.phoenix.sensors.CANCoderConfiguration;
import frc4388.robot.Constants.ArmConstants; import frc4388.robot.Constants.ArmConstants;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj2.command.SubsystemBase; import edu.wpi.first.wpilibj2.command.SubsystemBase;
@@ -9,19 +15,35 @@ import edu.wpi.first.wpilibj2.command.SubsystemBase;
public class Arm extends SubsystemBase { public class Arm extends SubsystemBase {
private WPI_TalonFX m_tele; private WPI_TalonFX m_tele;
private WPI_TalonFX m_pivot; private WPI_TalonFX m_pivot;
private boolean m_debug; private CANCoder m_pivotEncoder;
private boolean m_debug;
// Moves arm to distance [dist] then returns new ang // Moves arm to distance [dist] then returns new ang
public Arm(WPI_TalonFX pivot, WPI_TalonFX tele, boolean debug) { public Arm(WPI_TalonFX pivot, WPI_TalonFX tele, CANCoder encoder, boolean debug) {
m_tele = tele; m_tele = tele;
m_pivot = pivot; m_pivot = pivot;
m_pivotEncoder = encoder;
TalonFXConfiguration pivotConfig = new TalonFXConfiguration();
pivotConfig.slot0.kP = ArmConstants.kP;
pivotConfig.slot0.kI = ArmConstants.kI;
pivotConfig.slot0.kD = ArmConstants.kD;
pivotConfig.remoteFilter0.remoteSensorDeviceID = encoder.getDeviceID();
pivotConfig.remoteFilter0.remoteSensorSource = RemoteSensorSource.CANCoder;
pivotConfig.primaryPID.selectedFeedbackSensor = FeedbackDevice.RemoteSensor0;
pivot.configAllSettings(pivotConfig);
CANCoderConfiguration config = new CANCoderConfiguration();
config.magnetOffsetDegrees = ArmConstants.OFFSET;
m_pivotEncoder.configAllSettings(config);
tele.configFactoryDefault(); tele.configFactoryDefault();
pivot.configFactoryDefault(); pivot.configFactoryDefault();
} }
public Arm(WPI_TalonFX pivot, WPI_TalonFX tele) { public Arm(WPI_TalonFX pivot, WPI_TalonFX tele, CANCoder encoder) {
this(pivot, tele, false); this(pivot, tele, encoder, false);
} }
public void armSetRotation(double rot) { public void armSetRotation(double rot) {
@@ -36,6 +58,12 @@ public class Arm extends SubsystemBase {
// Move arm code // Move arm code
m_tele.set(ControlMode.Position, len * Math.abs(ArmConstants.TELE_REVERSE_SOFT_LIMIT - ArmConstants.TELE_FORWARD_SOFT_LIMIT) + m_tele.set(ControlMode.Position, len * Math.abs(ArmConstants.TELE_REVERSE_SOFT_LIMIT - ArmConstants.TELE_FORWARD_SOFT_LIMIT) +
ArmConstants.TELE_FORWARD_SOFT_LIMIT); ArmConstants.TELE_FORWARD_SOFT_LIMIT);
if (m_tele.isRevLimitSwitchClosed() == 1) {
m_tele.setSelectedSensorPosition(ArmConstants.TELE_REVERSE_SOFT_LIMIT);
} else if (m_tele.isFwdLimitSwitchClosed() == 1) {
m_tele.setSelectedSensorPosition(ArmConstants.TELE_FORWARD_SOFT_LIMIT);
}
} }
public double getArmLength() { public double getArmLength() {