Skip to content

Commit

Permalink
mechanism2d wrist visualizer
Browse files Browse the repository at this point in the history
  • Loading branch information
GearBoxFox committed Feb 28, 2024
1 parent a13adef commit 96558a2
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/main/java/frc/robot/subsystems/arm/ArmVisualizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,30 @@
public class ArmVisualizer {
private final Mechanism2d mechanism;
private final MechanismLigament2d arm;
private final MechanismLigament2d wrist;
private final String key;

public ArmVisualizer(String key, Color color) {
this.key = key;
mechanism = new Mechanism2d(3.0, 3.0, new Color8Bit(Color.kWhite));
MechanismRoot2d root = mechanism.getRoot("pivot", 1.0, 0.4);
arm = new MechanismLigament2d("arm", ArmConstants.ARM_LENGTH_METERS, 20.0, 6, new Color8Bit(color));
arm = new MechanismLigament2d("arm", ArmConstants.ARM_LENGTH_METERS, 0.0, 6, new Color8Bit(color));
wrist = new MechanismLigament2d("wrist", ArmConstants.WRIST_LENGTH_METERS, 45.0, 5, new Color8Bit(color));
root.append(arm);
arm.append(wrist);
}

/** Update arm visualizer with current arm angle */
public void update(double angleDegs) {
public void update(double armAngleDegs, double wristAngleDegs) {
// Log Mechanism2d
arm.setAngle(Rotation2d.fromDegrees(angleDegs));
arm.setAngle(Rotation2d.fromDegrees(armAngleDegs));
wrist.setAngle(Rotation2d.fromDegrees(wristAngleDegs));
Logger.recordOutput("Arm/Mechanism2d/" + key, mechanism);

// Log 3D poses
Pose3d pivotArm =
new Pose3d(ArmConstants.PIVOT_JOINT_TRANSLATION.getX(), 0.0,
ArmConstants.PIVOT_JOINT_TRANSLATION.getY(), new Rotation3d(0.0, -angleDegs, 0.0));
ArmConstants.PIVOT_JOINT_TRANSLATION.getY(), new Rotation3d(0.0, -armAngleDegs, 0.0));
Logger.recordOutput("Arm/Mechanism3d/" + key, pivotArm);
}
}

0 comments on commit 96558a2

Please sign in to comment.