-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from Ri3D-PSU/arm-&-claw
Climber, Arm, & Intake
- Loading branch information
Showing
10 changed files
with
560 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package frc.robot.subsystems.arm; | ||
|
||
import edu.wpi.first.math.controller.ArmFeedforward; | ||
import edu.wpi.first.wpilibj2.command.SubsystemBase; | ||
import org.littletonrobotics.junction.Logger; | ||
|
||
public class Arm extends SubsystemBase { | ||
|
||
ArmIO io; | ||
ArmInputsAutoLogged inputs = new ArmInputsAutoLogged(); | ||
|
||
public Arm(ArmIO io) { | ||
this.io = io; | ||
} | ||
|
||
private double targetPosition = 0.0; | ||
private final ArmFeedforward feedforward = new ArmFeedforward(0.0, 0.0, 0.0); | ||
|
||
/** | ||
* @param position The position to set the arm to in degrees | ||
*/ | ||
public void setArmPosition(double position) { | ||
targetPosition = position; | ||
} | ||
|
||
@Override | ||
public void periodic() { | ||
io.updateInputs(inputs); | ||
Logger.getInstance().processInputs("Arm", inputs); | ||
|
||
double armffvoltage = feedforward.calculate(inputs.armPositionRad, inputs.armVelocityRadPerSec); | ||
Logger.getInstance().recordOutput("ArmFFVoltage", armffvoltage); | ||
|
||
io.setArmPosition(targetPosition, armffvoltage); | ||
} | ||
|
||
public double getArmPosition() { | ||
return inputs.armPositionRad; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package frc.robot.subsystems.arm; | ||
|
||
import org.littletonrobotics.junction.AutoLog; | ||
|
||
public interface ArmIO { | ||
@AutoLog | ||
public static class ArmInputs { | ||
public double armPositionRad = 0.0; | ||
public double armVelocityRadPerSec = 0.0; | ||
public double armCurrent = 0.0; | ||
public double armTemperature = 0.0; | ||
public double armVoltage = 0.0; | ||
} | ||
|
||
/** | ||
* Updates the set of loggable inputs. | ||
*/ | ||
public default void updateInputs(ArmInputs inputs) { | ||
|
||
} | ||
|
||
public default void setArmPosition(double position, double ffvoltage) { | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package frc.robot.subsystems.arm; | ||
|
||
import com.revrobotics.CANSparkMax; | ||
import com.revrobotics.CANSparkMaxLowLevel.MotorType; | ||
import com.revrobotics.SparkMaxPIDController.ArbFFUnits; | ||
|
||
public class ArmIOSparkMax implements ArmIO { | ||
|
||
CANSparkMax arm; | ||
CANSparkMax armFollower; | ||
|
||
public ArmIOSparkMax() { | ||
arm = new CANSparkMax(30, MotorType.kBrushless); | ||
arm.getEncoder().setPositionConversionFactor((1.0 / 100.0) * (16.0 / 62.0)); | ||
arm.getEncoder().setVelocityConversionFactor((1.0 / 100.0) * (16.0 / 62.0) * (1.0 / 60.0) * 2.0 * Math.PI); | ||
arm.enableVoltageCompensation(11.0); | ||
arm.setSmartCurrentLimit(40); | ||
|
||
arm.getPIDController().setP(0.01); | ||
arm.getPIDController().setI(0.0); | ||
arm.getPIDController().setD(0.0); | ||
arm.getPIDController().setFF(0.0); | ||
|
||
arm.setSmartCurrentLimit(40); | ||
|
||
armFollower = new CANSparkMax(31, MotorType.kBrushless); | ||
armFollower.follow(arm, true); | ||
|
||
} | ||
|
||
public void updateInputs(ArmInputs inputs) { | ||
inputs.armPositionRad = arm.getEncoder().getPosition(); | ||
inputs.armVelocityRadPerSec = arm.getEncoder().getVelocity(); | ||
inputs.armCurrent = arm.getOutputCurrent(); | ||
inputs.armTemperature = arm.getMotorTemperature(); | ||
inputs.armVoltage = arm.getBusVoltage(); | ||
} | ||
|
||
public void setArmPosition(double position, double ffvoltage) { | ||
arm.getPIDController().setReference(position, CANSparkMax.ControlType.kPosition, 0, | ||
ffvoltage, ArbFFUnits.kVoltage); | ||
} | ||
} |
Oops, something went wrong.