-
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.
finished ArmIO Interface, worked on ArmIOSim
- Loading branch information
1 parent
05f6d39
commit 42098a6
Showing
4 changed files
with
131 additions
and
0 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
10 changes: 10 additions & 0 deletions
10
src/main/java/org/team1540/robot2025/subsystems/arm/Arm.java
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,10 @@ | ||
package org.team1540.robot2025.subsystems.arm; | ||
|
||
import edu.wpi.first.wpilibj2.command.SubsystemBase; | ||
|
||
public class Arm extends SubsystemBase { | ||
|
||
public void Arm(){ | ||
|
||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/org/team1540/robot2025/subsystems/arm/ArmIO.java
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,20 @@ | ||
package org.team1540.robot2025.subsystems.arm; | ||
import edu.wpi.first.math.geometry.Rotation2d; | ||
import org.littletonrobotics.junction.AutoLog; | ||
public interface ArmIO { | ||
@AutoLog | ||
class ArmIOInputs{ | ||
//TODO: are these inputs okay? do I want any other ones? | ||
public double velocityRPM = 0.0; | ||
public double appliedVolts = 0.0; | ||
public double currentAmps = 0.0; | ||
public Rotation2d rotation2d = new Rotation2d(); | ||
public double tempCelsius = 0.0; | ||
} | ||
|
||
default void setVoltage(double voltage){} | ||
default void updateInputs(ArmIOInputs inputs){} | ||
default void setSetPoint(Rotation2d setPoint){}; | ||
default void configPID(double kP, double kI, double kD){}; | ||
default void setBrakeMode(boolean setBrake){}; | ||
} |
68 changes: 68 additions & 0 deletions
68
src/main/java/org/team1540/robot2025/subsystems/arm/ArmIOSim.java
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,68 @@ | ||
package org.team1540.robot2025.subsystems.arm; | ||
|
||
import edu.wpi.first.math.controller.ArmFeedforward; | ||
import edu.wpi.first.math.controller.ProfiledPIDController; | ||
import edu.wpi.first.math.geometry.Rotation2d; | ||
import edu.wpi.first.math.system.plant.DCMotor; | ||
import edu.wpi.first.math.trajectory.TrapezoidProfile; | ||
import edu.wpi.first.wpilibj.simulation.SingleJointedArmSim; | ||
import static org.team1540.robot2025.Constants.Arm.*; | ||
import static org.team1540.robot2025.Constants.LOOP_PERIODIC_SECS; | ||
|
||
public class ArmIOSim implements ArmIO{ | ||
//fields | ||
private final SingleJointedArmSim armSim = | ||
new SingleJointedArmSim( | ||
DCMotor.getKrakenX60(1), | ||
GEAR_RATIO, | ||
ARM_MOMENT_OF_INERTIA, | ||
ARM_LENGTH_METERS, | ||
MIN_ANGLE.getRadians(), | ||
MAX_ANGLE.getRadians(), | ||
true, | ||
STARTING_ANGLE.getRadians()); | ||
|
||
private double armAppliedVolts = 0.0; | ||
private final ProfiledPIDController controller = new ProfiledPIDController( | ||
KP, KI, KD, new TrapezoidProfile.Constraints(MAX_VELOCITY, MAX_ACCELERATION)); | ||
private final ArmFeedforward feedforward = new ArmFeedforward(KS, KG, KV); | ||
private boolean isClosedLoop; | ||
|
||
//methods | ||
public void setVoltage(double voltage){ | ||
|
||
} | ||
public void updateInputs(ArmIOInputs inputs){ | ||
if(isClosedLoop){ | ||
armAppliedVolts = controller.calculate(armSim.getAngleRads(), inputs.rotation2d.getRadians()) | ||
+ feedforward.calculate(controller.getSetpoint().position, controller.getSetpoint().velocity); | ||
} | ||
|
||
armSim.setInputVoltage(armAppliedVolts); | ||
armSim.update(LOOP_PERIODIC_SECS); | ||
|
||
inputs.rotation2d = Rotation2d.fromRadians(armSim.getAngleRads()); | ||
inputs.appliedVolts = armAppliedVolts; | ||
inputs.currentAmps = armSim.getCurrentDrawAmps(); | ||
inputs.velocityRPM = armSim.getVelocityRadPerSec()*60/(2*Math.PI); //converting to rpm; | ||
} | ||
public void setSetPoint(Rotation2d setPoint){ | ||
|
||
} | ||
public void configPID(double kP, double kI, double kD){ | ||
|
||
} | ||
public void setBrakeMode(boolean setBrake){ | ||
|
||
} | ||
|
||
// @Override | ||
// public void updateInputs(ArmIOInputs inputs) { | ||
// //TODO: | ||
// } | ||
// | ||
// @Override | ||
// public void setSetPointRads(double setPointRads){ | ||
// //TODO: | ||
// } | ||
} |