2023-01-24 17:41:00 -07:00
|
|
|
package frc4388.robot.subsystems;
|
|
|
|
|
|
|
|
|
|
import com.ctre.phoenix.motorcontrol.ControlMode;
|
|
|
|
|
import com.ctre.phoenix.motorcontrol.can.WPI_TalonFX;
|
|
|
|
|
import frc4388.robot.Constants.ArmConstants;
|
|
|
|
|
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
|
|
|
|
|
import edu.wpi.first.wpilibj2.command.SubsystemBase;
|
|
|
|
|
|
|
|
|
|
public class Arm extends SubsystemBase {
|
|
|
|
|
private WPI_TalonFX m_armmotor;
|
|
|
|
|
private boolean m_debug;
|
2023-01-23 19:53:30 -07:00
|
|
|
// Moves arm to distence [dist] then returns new ang
|
2023-01-24 17:41:00 -07:00
|
|
|
public Arm(WPI_TalonFX armmotor, boolean debug) {
|
|
|
|
|
armmotor.configFactoryDefault();
|
|
|
|
|
m_armmotor = armmotor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Arm(WPI_TalonFX armmoter) {
|
|
|
|
|
this(armmoter, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void armSetLength(double len) {
|
|
|
|
|
if (len > 1 || len < 0) return;
|
2023-01-23 19:53:30 -07:00
|
|
|
// Move arm code
|
2023-01-24 17:41:00 -07:00
|
|
|
m_armmotor.set(ControlMode.Position, len * (ArmConstants.maxArmLen - ArmConstants.minArmLen) +
|
|
|
|
|
ArmConstants.minArmLen);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public double getArmLength() {
|
|
|
|
|
return (m_armmotor.getSelectedSensorPosition() - ArmConstants.minArmLen) /
|
|
|
|
|
(ArmConstants.maxArmLen - ArmConstants.minArmLen);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void periodic() {
|
|
|
|
|
if (m_debug)
|
|
|
|
|
SmartDashboard.putNumber("Arm Motor", m_armmotor.getSelectedSensorPosition());
|
2023-01-23 19:53:30 -07:00
|
|
|
}
|
|
|
|
|
}
|