-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
yoinked armvisualizer from mech advantage
- Loading branch information
1 parent
a9fc13e
commit f15de83
Showing
5 changed files
with
105 additions
and
43 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,39 @@ | ||
package frc.robot.subsystems.arm; | ||
|
||
import edu.wpi.first.math.geometry.Pose3d; | ||
import edu.wpi.first.math.geometry.Rotation2d; | ||
import edu.wpi.first.math.geometry.Rotation3d; | ||
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.Constants.ArmConstants; | ||
import org.littletonrobotics.junction.Logger; | ||
|
||
public class ArmVisualizer { | ||
private final Mechanism2d mechanism; | ||
private final MechanismLigament2d arm; | ||
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)); | ||
root.append(arm); | ||
} | ||
|
||
/** Update arm visualizer with current arm angle */ | ||
public void update(double angleDegs) { | ||
// Log Mechanism2d | ||
arm.setAngle(Rotation2d.fromDegrees(angleDegs)); | ||
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)); | ||
Logger.recordOutput("Arm/Mechanism3d/" + key, pivotArm); | ||
} | ||
} |
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,45 @@ | ||
package lib.utils; | ||
|
||
import edu.wpi.first.math.geometry.*; | ||
import edu.wpi.first.math.util.Units; | ||
import frc.robot.Constants.ArmConstants; | ||
import frc.robot.Constants.ArmSetpoints; | ||
|
||
public class AimbotUtils { | ||
/** Gets the top point of the shooter for checking limits*/ | ||
public static Translation2d calculateArmPosition(double armAngle, double wristAngle) { | ||
return ArmConstants.PIVOT_JOINT_TRANSLATION | ||
// translate the length + direction of the arm | ||
.plus(new Translation2d(ArmConstants.ARM_LENGTH_METERS, | ||
Rotation2d.fromDegrees(armAngle))) | ||
// translate the length + direction of the wrist | ||
.plus(new Translation2d(ArmConstants.WRIST_LENGTH_METERS, | ||
Rotation2d.fromDegrees(360) | ||
.minus(Rotation2d.fromDegrees(wristAngle)))); | ||
} | ||
|
||
/** Gets the transformation of the shooter relative to the drive base */ | ||
public static Transform3d getShooterTransformation(double armAngle) { | ||
return ArmConstants.PIVOT_TRANSLATION_METERS.plus( | ||
// Add the movement of the arm | ||
GeomUtils.translationToTransform(new Translation3d( | ||
ArmConstants.ARM_LENGTH_METERS, | ||
new Rotation3d(0.0, Units.degreesToRadians(armAngle), 0.0) | ||
)) | ||
); | ||
} | ||
|
||
public static ArmSetpoints.ArmSetpoint aimbotCalculate(Pose3d robotPose, double armAngle) { | ||
Pose3d speakerPose = new Pose3d(AllianceFlipUtil.apply(FieldConstants.CENTER_SPEAKER), new Rotation3d()); | ||
Pose3d shooterPivotPose = robotPose.plus(getShooterTransformation(armAngle)); | ||
Transform3d robotToSpeaker = | ||
new Transform3d(shooterPivotPose.plus(getShooterTransformation(armAngle)), speakerPose); | ||
|
||
double groundDistance = | ||
Math.sqrt(Math.pow(robotToSpeaker.getX(), 2) + Math.pow(robotToSpeaker.getY(), 2)); | ||
|
||
double desiredWristAngle = Math.atan2(groundDistance, robotToSpeaker.getZ()); | ||
double safeArmAngle = desiredWristAngle - ArmConstants.WRIST_ARM_GAP.getValue(); | ||
return new ArmSetpoints.ArmSetpoint(safeArmAngle, desiredWristAngle); | ||
} | ||
} |
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