|
| 1 | +package com.stuypulse.robot.subsystems.double_jointed_arm; |
| 2 | + |
| 3 | +import com.stuypulse.robot.Robot; |
| 4 | +import com.stuypulse.robot.constants.Constants; |
| 5 | +import com.stuypulse.stuylib.math.SLMath; |
| 6 | + |
| 7 | +import edu.wpi.first.math.Matrix; |
| 8 | +import edu.wpi.first.math.geometry.Rotation2d; |
| 9 | +import edu.wpi.first.math.geometry.Translation2d; |
| 10 | +import edu.wpi.first.math.numbers.N1; |
| 11 | +import edu.wpi.first.math.numbers.N2; |
| 12 | +import edu.wpi.first.wpilibj2.command.SubsystemBase; |
| 13 | + |
| 14 | +public class DoubleJointedArm extends SubsystemBase { |
| 15 | + |
| 16 | + private static DoubleJointedArm instance; |
| 17 | + |
| 18 | + private DoubleJointedArmIO io; |
| 19 | + private DoubleJointedArmIOInputsAutoLogged inputs = new DoubleJointedArmIOInputsAutoLogged(); |
| 20 | + |
| 21 | + public enum DoubleJointedArmState { |
| 22 | + STOW(Rotation2d.fromDegrees(10), Rotation2d.fromDegrees(10)); |
| 23 | + |
| 24 | + private Rotation2d shoulderTargetAngle; |
| 25 | + private Rotation2d elbowTargetAngle; |
| 26 | + |
| 27 | + private DoubleJointedArmState(Rotation2d shoulderTargetAngle, Rotation2d elbowTargetAngle){ |
| 28 | + this.shoulderTargetAngle = Rotation2d.fromDegrees( |
| 29 | + SLMath.clamp(shoulderTargetAngle.getDegrees(), |
| 30 | + Constants.DoubleJointedArm.Shoulder.MIN_ANGLE.getDegrees(), |
| 31 | + Constants.DoubleJointedArm.Shoulder.MAX_ANGLE.getDegrees())); |
| 32 | + this.elbowTargetAngle = Rotation2d.fromDegrees( |
| 33 | + SLMath.clamp(elbowTargetAngle.getDegrees(), |
| 34 | + Constants.DoubleJointedArm.Elbow.MIN_ANGLE.getDegrees(), |
| 35 | + Constants.DoubleJointedArm.Elbow.MAX_ANGLE.getDegrees())); |
| 36 | + } |
| 37 | + |
| 38 | + public Rotation2d getShoulderTargetAngle(){ |
| 39 | + return this.shoulderTargetAngle; |
| 40 | + } |
| 41 | + |
| 42 | + public Rotation2d getElbowTargetAngle(){ |
| 43 | + return this.elbowTargetAngle; |
| 44 | + } |
| 45 | + |
| 46 | + private DoubleJointedArmState state; |
| 47 | + |
| 48 | + public DoubleJointedArmState getState(){ |
| 49 | + return this.state; |
| 50 | + } |
| 51 | + } |
| 52 | + |
| 53 | + @Override |
| 54 | + public void periodic() { |
| 55 | + // PUT ALL CALLS TO CONTROL METHODS HERE |
| 56 | + } |
| 57 | + |
| 58 | + /* LOGIC for controlling the double jointed arm: */ |
| 59 | + |
| 60 | + // 0. Measure system: angle, angular velocity, angular acceleration |
| 61 | + |
| 62 | + // 1. Find M, C, G (mass inertia matrix, centrifugal + coriolis matrix, gravity torque matrix) |
| 63 | + |
| 64 | + // 2. Given a current position (x, y) for the end effector on the double jointed arm, pathfind to a target position (x, y) and calculate the required angular position, velocity, and acceleration |
| 65 | + |
| 66 | + // 3. Feed the current angular states and target angular states into the PID controllers for each joint |
| 67 | + |
| 68 | + // 4. Calculate the three matrices using the angular states, which outputs a toruqe input |
| 69 | + |
| 70 | + // 5. Using torque current control on the motor, feed the torque input into the motor |
| 71 | +} |
0 commit comments