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.
refactor(arm): Move motion profiling to outside of joints.
- Loading branch information
1 parent
6f28c11
commit 9fc300f
Showing
7 changed files
with
77 additions
and
44 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -99,6 +99,7 @@ | |
"robotJoysticks": [ | ||
{}, | ||
{ | ||
"guid": "78696e70757401000000000000000000", | ||
"useGamepad": true | ||
} | ||
] | ||
|
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 |
---|---|---|
|
@@ -30,6 +30,9 @@ | |
"transitory": { | ||
"Shuffleboard": { | ||
"Arm": { | ||
"Goal": { | ||
"open": true | ||
}, | ||
"Position": { | ||
"open": true | ||
}, | ||
|
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 |
---|---|---|
@@ -1,51 +1,66 @@ | ||
package frc.robot.arm; | ||
|
||
import edu.wpi.first.math.geometry.Rotation2d; | ||
import edu.wpi.first.math.trajectory.TrapezoidProfile.State; | ||
import frc.robot.RobotConstants; | ||
import frc.robot.arm.ArmConstants.ShoulderMotorConstants; | ||
import java.util.Objects; | ||
|
||
/** State of the arm. */ | ||
public record ArmState(Rotation2d shoulder, Rotation2d elbow, Rotation2d wrist) { | ||
public record ArmState(State shoulder, State elbow, State wrist) { | ||
|
||
/** | ||
* Creates an arm state. | ||
* | ||
* @param shoulder the shoulder's rotation. | ||
* @param elbow the elbow's rotation. | ||
* @param wrist the wrist's rotation. | ||
* @param shoulder the shoulder's state. | ||
* @param elbow the elbow's state. | ||
* @param wrist the wrist's state. | ||
*/ | ||
public ArmState { | ||
Objects.requireNonNull(shoulder); | ||
Objects.requireNonNull(elbow); | ||
Objects.requireNonNull(wrist); | ||
} | ||
|
||
/** | ||
* Creates an arm state. | ||
* | ||
* @param shoulder the shoulder's rotation. | ||
* @param elbow the elbow's rotation. | ||
* @param wrist the wrist's rotation. | ||
*/ | ||
public ArmState(Rotation2d shoulder, Rotation2d elbow, Rotation2d wrist) { | ||
this( | ||
new State(shoulder.getRotations(), 0), | ||
new State(elbow.getRotations(), 0), | ||
new State(wrist.getRotations(), 0)); | ||
} | ||
|
||
/** | ||
* Copies this arm state with a new shoulder rotation. | ||
* | ||
* @param newShoulder the new shoulder rotation. | ||
* @return a copy of this arm state with a new shoulder rotation. | ||
*/ | ||
public ArmState withShoulder(Rotation2d newShoulder) { | ||
return new ArmState(newShoulder, elbow, wrist); | ||
return withShoulder(new State(newShoulder.getRotations(), 0)); | ||
} | ||
|
||
/** | ||
* Copies this arm state with a new elbow rotation. | ||
* Copies this arm state with a new shoulder state. | ||
* | ||
* @param newElbow the new elbow rotation. | ||
* @return a copy of this arm state with a new elbow rotation. | ||
* @param newShoulder the new shoulder state. | ||
* @return a copy of this arm state with a new shoulder rotation. | ||
*/ | ||
public ArmState withElbow(Rotation2d newElbow) { | ||
return new ArmState(shoulder, newElbow, wrist); | ||
public ArmState withShoulder(State newShoulder) { | ||
return new ArmState(newShoulder, elbow, wrist); | ||
} | ||
|
||
/** | ||
* Copies this arm state with a new wrist rotation. | ||
* | ||
* @param newWrist the new wrist rotation. | ||
* @return a copy of this arm state with a new wrist rotation. | ||
*/ | ||
public ArmState withWrist(Rotation2d newWrist) { | ||
return new ArmState(shoulder, elbow, newWrist); | ||
public ArmState nextSetpoint(ArmState goal) { | ||
State nextShoulderState = | ||
ShoulderMotorConstants.MOTION_PROFILE.calculate( | ||
RobotConstants.PERIODIC_DURATION, this.shoulder, goal.shoulder); | ||
|
||
return withShoulder(nextShoulderState); | ||
} | ||
} |
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