This repository has been archived by the owner on May 19, 2024. It is now read-only.
-
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.
- Loading branch information
1 parent
e62821b
commit f44dc27
Showing
15 changed files
with
153 additions
and
34 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
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
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
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,48 @@ | ||
package frc.robot.arm; | ||
|
||
import edu.wpi.first.math.util.Units; | ||
import edu.wpi.first.wpilibj.smartdashboard.Mechanism2d; | ||
import edu.wpi.first.wpilibj.smartdashboard.MechanismLigament2d; | ||
import edu.wpi.first.wpilibj.smartdashboard.MechanismRoot2d; | ||
import edu.wpi.first.wpilibj.util.Color; | ||
import edu.wpi.first.wpilibj.util.Color8Bit; | ||
import frc.robot.arm.ArmConstants.ElbowMotorConstants; | ||
import frc.robot.arm.ArmConstants.ShoulderMotorConstants; | ||
|
||
/** Helper class for rendering the arm using WPILib mechanisms. */ | ||
public class ArmMechanism { | ||
|
||
private static ArmMechanism instance = null; | ||
|
||
private final Mechanism2d mechanism; | ||
|
||
private final MechanismRoot2d root; | ||
|
||
private final MechanismLigament2d shoulder, elbow; | ||
|
||
private final double THICKNESS = Units.inchesToMeters(2) * 100; | ||
|
||
private ArmMechanism() { | ||
mechanism = new Mechanism2d(1, 1); | ||
root = mechanism.getRoot("arm", 0.15, 0); | ||
shoulder = root.append(new MechanismLigament2d("shoulder", ShoulderMotorConstants.SHOULDER_TO_ELBOW_DISTANCE, 90, THICKNESS, new Color8Bit(Color.kOrange))); | ||
elbow = shoulder.append(new MechanismLigament2d("elbow", ElbowMotorConstants.ELBOW_TO_WRIST_DISTANCE, 90, THICKNESS, new Color8Bit(Color.kGreen))); | ||
} | ||
|
||
public static ArmMechanism getInstance() { | ||
if (instance == null) { | ||
instance = new ArmMechanism(); | ||
} | ||
|
||
return instance; | ||
} | ||
|
||
public Mechanism2d getMechanism() { | ||
return mechanism; | ||
} | ||
|
||
public void setState(ArmState state) { | ||
shoulder.setAngle(state.shoulder()); | ||
elbow.setAngle(state.elbow().minus(state.shoulder())); | ||
} | ||
} |
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,60 @@ | ||
package frc.robot.arm; | ||
|
||
import edu.wpi.first.math.system.plant.DCMotor; | ||
import edu.wpi.first.math.util.Units; | ||
import edu.wpi.first.wpilibj.simulation.SingleJointedArmSim; | ||
import frc.robot.RobotConstants; | ||
import frc.robot.arm.ArmConstants.ShoulderMotorConstants; | ||
|
||
/** Simulated shoulder motor. */ | ||
public class ShoulderMotorIOSim implements ShoulderMotorIO { | ||
|
||
private final SingleJointedArmSim singleJointedArmSim; | ||
|
||
/** Creates a new simulated shoulder motor. */ | ||
public ShoulderMotorIOSim() { | ||
singleJointedArmSim = | ||
new SingleJointedArmSim( | ||
DCMotor.getNEO(1), | ||
ShoulderMotorConstants.GEARING, | ||
0.1, | ||
ShoulderMotorConstants.SHOULDER_TO_ELBOW_DISTANCE, | ||
Units.degreesToRadians(10), | ||
Units.degreesToRadians(90), | ||
false, | ||
Units.degreesToRadians(90)); | ||
} | ||
|
||
@Override | ||
public void configure() { | ||
} | ||
|
||
@Override | ||
public void update(ShoulderMotorIOValues values) { | ||
singleJointedArmSim.update(RobotConstants.PERIODIC_DURATION); | ||
|
||
values.positionRotations = Units.radiansToRotations(singleJointedArmSim.getAngleRads()); | ||
values.currentAmps = singleJointedArmSim.getCurrentDrawAmps(); | ||
} | ||
|
||
@Override | ||
public void setPosition(double positionRotations) { | ||
singleJointedArmSim.setState(Units.rotationsToRadians(positionRotations), 0.0); | ||
} | ||
|
||
@Override | ||
public void runSetpoint(double positionRotations) { | ||
//setPosition(positionRotations); | ||
} | ||
|
||
// TODO Remove, only for characterization | ||
@Override | ||
public void setVoltage(double volts) { | ||
singleJointedArmSim.setInputVoltage(volts); | ||
} | ||
|
||
@Override | ||
public void stop() { | ||
setVoltage(0); | ||
} | ||
} |
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
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
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