Skip to content
This repository was archived by the owner on May 19, 2024. It is now read-only.

Commit 856ffc6

Browse files
committed
fix(superstructure): Add some intermediate rules.
1 parent 4d2d167 commit 856ffc6

File tree

5 files changed

+74
-10
lines changed

5 files changed

+74
-10
lines changed

simgui-ds.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,7 @@
101101
"useGamepad": true
102102
},
103103
{
104-
"guid": "78696e70757401000000000000000000",
105-
"useGamepad": true
104+
"guid": "Keyboard0"
106105
}
107106
]
108107
}

src/main/java/frc/robot/RobotContainer.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ private void configureBindings() {
8181
operatorController.rightTrigger().onTrue(superstructure.shoot());
8282

8383
operatorController.a().onTrue(superstructure.amp());
84+
operatorController.b().onTrue(superstructure.intake());
8485
operatorController.x().onTrue(superstructure.stow());
86+
operatorController.y().onTrue(superstructure.shoot());
8587
}
8688

8789
/**

src/main/java/frc/robot/superstructure/Superstructure.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,10 @@ public Command to(SuperstructureState goal) {
223223
return new ToGoal(goal);
224224
}
225225

226+
public Command initial() {
227+
return to(SuperstructureState.INITIAL);
228+
}
229+
226230
public Command stow() {
227231
return to(SuperstructureState.STOW);
228232
}

src/main/java/frc/robot/superstructure/SuperstructureGoals.java

Lines changed: 54 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package frc.robot.superstructure;
22

3+
import frc.robot.superstructure.SuperstructureConstants.PivotAngleConstants;
4+
import frc.robot.superstructure.SuperstructureConstants.ShoulderAngleConstants;
35
import frc.robot.superstructure.SuperstructureConstants.WristAngleConstants;
46
import java.util.LinkedList;
57
import java.util.Queue;
@@ -8,19 +10,63 @@ public class SuperstructureGoals {
810

911
private final Queue<SuperstructureState> goals;
1012

11-
public SuperstructureGoals(SuperstructureState start, SuperstructureState end) {
12-
goals = new LinkedList<SuperstructureState>();
13+
public static Queue<SuperstructureState> merge(
14+
Queue<SuperstructureState> first, Queue<SuperstructureState> second) {
15+
Queue<SuperstructureState> mergedGoals = new LinkedList<SuperstructureState>();
16+
17+
while (!first.isEmpty()) {
18+
mergedGoals.add(first.poll());
19+
}
20+
21+
while (!second.isEmpty()) {
22+
mergedGoals.add(second.poll());
23+
}
24+
25+
return mergedGoals;
26+
}
27+
28+
public static Queue<SuperstructureState> generate(
29+
SuperstructureState start, SuperstructureState end) {
30+
Queue<SuperstructureState> goals = new LinkedList<SuperstructureState>();
31+
32+
boolean shoulderMove = !start.atShoulderAngleGoal(end);
1333

14-
if (!start.atShoulderAngleGoal(end)) {
34+
// Shoulder move: HOME -> STOW; ANY -> AMP
35+
// Move wrist to STOW first, then move shoulder
36+
if (shoulderMove) {
1537
goals.add(start.withWristAngle(WristAngleConstants.STOW));
16-
goals.add(
17-
start
18-
.withShoulderAngleOf(end)
19-
.withWristAngle(WristAngleConstants.STOW)
20-
.withPivotAngleOf(end));
38+
goals.add(end.withWristAngle(WristAngleConstants.STOW));
39+
goals.add(end);
40+
return goals;
41+
}
42+
43+
boolean shoulderStowed = start.atShoulderAngle(ShoulderAngleConstants.STOW);
44+
boolean wristMove = !start.atWristAngleGoal(end);
45+
boolean pivotMove = !start.atPivotAngleGoal(end);
46+
boolean pivotUp = start.pivotAngleRotations().position > PivotAngleConstants.DOWN.getRotations();
47+
48+
// Stow position movement & wrist-intake collision avoidance
49+
if (shoulderStowed && wristMove && pivotMove) {
50+
if (pivotUp) {
51+
// Pivot is up and needs to go down; move it first
52+
goals.add(start.withPivotAngleOf(end));
53+
} else {
54+
// Pivot is down and needs to go up; move wrist out of way first
55+
goals.add(start.withWristAngleOf(end));
56+
}
2157
}
2258

2359
goals.add(end);
60+
61+
return goals;
62+
}
63+
64+
public SuperstructureGoals(Queue<SuperstructureState> goals) {
65+
this.goals = goals;
66+
}
67+
68+
public SuperstructureGoals(SuperstructureState start, SuperstructureState end) {
69+
this(generate(start, end));
2470
}
2571

2672
public SuperstructureState get() {

src/main/java/frc/robot/superstructure/SuperstructureState.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,19 @@ public boolean atShoulderAngleGoal(SuperstructureState goal) {
229229
SuperstructureConstants.ShoulderAngleConstants.TOLERANCE.getRotations());
230230
}
231231

232+
/**
233+
* Returns true if at the shoulder angle.
234+
*
235+
* @param other
236+
* @return true if at the shoulder angle.
237+
*/
238+
public boolean atShoulderAngle(Rotation2d other) {
239+
return MathUtil.isNear(
240+
this.shoulderAngleRotations().position,
241+
other.getRotations(),
242+
SuperstructureConstants.ShoulderAngleConstants.TOLERANCE.getRotations());
243+
}
244+
232245
/**
233246
* Returns true if at the wrist angle goal.
234247
*

0 commit comments

Comments
 (0)