Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
141 commits
Select commit Hold shift + click to select a range
cbdf73f
first pass at coral ground state
LewisSeiden Mar 27, 2025
ea03c97
adjust mech viz to use new ee
LewisSeiden Mar 28, 2025
2e66856
adjust hp intake pose
LewisSeiden Mar 28, 2025
83366b3
add clearance for hp extension
LewisSeiden Mar 28, 2025
a6d19b9
begin trying to use ik to not have to redo setpoints (it brokey rn)
LewisSeiden Mar 28, 2025
28a2db9
fix getManipulatorPose (?)
LewisSeiden Mar 28, 2025
7296893
tune reef setpoints
LewisSeiden Mar 28, 2025
28f21ba
first pass tuning reef algae intaking
LewisSeiden Mar 29, 2025
d4e16cb
fix bindings for coral ground
LewisSeiden Mar 29, 2025
d0a94c1
use proper indexing
LewisSeiden Mar 29, 2025
b4b7ec7
import zeroing offset from cad
LewisSeiden Mar 29, 2025
6b2c2b2
make shoulder wait for wrist to not be retracted to begin clearance e…
LewisSeiden Mar 29, 2025
10d83eb
make auto use ground intake for ✨testing✨ reasons
LewisSeiden Mar 29, 2025
19e1e22
turn down shoulder + wrist speed for bring up
LewisSeiden Mar 29, 2025
607ee08
start tuning positions irl
LewisSeiden Mar 29, 2025
e3bfc09
more tuning on robot
LewisSeiden Mar 29, 2025
03a3b60
adjust l1
LewisSeiden Mar 29, 2025
f3b2f95
Merge branch 'ground-intake' of github.com:HighlanderRobotics/Reefsca…
LewisSeiden Mar 29, 2025
7e02572
adjust algae on robot
LewisSeiden Mar 29, 2025
3d92a1e
use stops for floor intake
LewisSeiden Mar 30, 2025
67b4183
ground intake tuning
LewisSeiden Mar 30, 2025
1863c23
tune hp pose
LewisSeiden Mar 30, 2025
37b458f
more adjustments for new ee robustness
LewisSeiden Mar 30, 2025
4715007
adjust l2 and l3 setpoints
LewisSeiden Mar 30, 2025
8f83f7d
adjust setpoints, clearance extension
LewisSeiden Mar 30, 2025
b22061b
fix not retracting after l2/3 scoring
LewisSeiden Mar 30, 2025
1c14742
reenable current limits, adjust l4 pose
LewisSeiden Mar 30, 2025
ed037bc
tune barge shot
LewisSeiden Mar 30, 2025
a2a8f16
tune stack intake, fix ik at max extension (?)
LewisSeiden Mar 30, 2025
20fa562
update ratio
LewisSeiden Mar 30, 2025
3477e2f
run spotless
Lyssia-Seiden Mar 30, 2025
385f718
update more setpoints
LewisSeiden Mar 31, 2025
af86ef0
make wrist use hardstop for ground, reenable left bumper align controls
LewisSeiden Mar 31, 2025
7c2dd02
make ready coral use hp pose, wrist use pid before hardstop
LewisSeiden Mar 31, 2025
8baa4a7
adjust wrist zero offset with shims
LewisSeiden Mar 31, 2025
824790d
Merge branch 'ground-intake' of github.com:HighlanderRobotics/Reefsca…
LewisSeiden Mar 31, 2025
6738f79
redo zeroing offset
LewisSeiden Apr 2, 2025
2428fde
increase manipulator current limit
LewisSeiden Apr 2, 2025
9cf7b35
increase wrist accel and add soft limit to try to avoid catching it
LewisSeiden Apr 2, 2025
5e8533b
revert accel increase
LewisSeiden Apr 2, 2025
012b434
adjust tucked clearance shoulder pose, increase filtering for ik
LewisSeiden Apr 2, 2025
dae0be7
try to avoid jitters when starting extendWithClearance near target
LewisSeiden Apr 2, 2025
1e59a92
hardcode auto prescore to true because it wasnt working otherwise for…
LewisSeiden Apr 3, 2025
78695e2
move auto prescore condition to Robot instead of goofy ah binding
LewisSeiden Apr 3, 2025
9f4142c
abstract checking for tuck
LewisSeiden Apr 3, 2025
ea6ed26
adjust climb so it works 🔥🔥
LewisSeiden Apr 3, 2025
6f807d9
wait better for reextension
LewisSeiden Apr 3, 2025
06d5a8c
make sure that robot waits to retract after coral score
LewisSeiden Apr 3, 2025
e289799
tune processor a bit
LewisSeiden Apr 3, 2025
869c96a
try to improve funnel behavior
LewisSeiden Apr 3, 2025
0a59d47
reenable ground piece in auto
LewisSeiden Apr 3, 2025
6265e85
turn off ik by default and when in l1
LewisSeiden Apr 3, 2025
eaa7ec4
make ground intake traj wait for prev scoring
LewisSeiden Apr 3, 2025
5c97978
try to avoid slams when entering score_coral when alr extended
LewisSeiden Apr 3, 2025
3135881
fix hop when switching from clearance to ik hold
LewisSeiden Apr 4, 2025
368665b
allow cancelling out of l4
LewisSeiden Apr 4, 2025
e1ba93a
delay wrist movement in some cases
LewisSeiden Apr 4, 2025
911d373
try to avoid l4 fucking itself again
LewisSeiden Apr 4, 2025
72dbd07
reduce skipping steps elevator tolerance
LewisSeiden Apr 4, 2025
58a5411
try to avoid l1 killing itself
LewisSeiden Apr 4, 2025
cff7bbc
tune hp intake more again 😭
LewisSeiden Apr 4, 2025
7907345
add manual zeroing
LewisSeiden Apr 4, 2025
00befae
tune auto to be slower and smoother
LewisSeiden Apr 4, 2025
91bcb2d
speed up auto a smidge
LewisSeiden Apr 4, 2025
1e8fe68
mirror lhs auto changes to rhs
LewisSeiden Apr 4, 2025
d6678fe
adjust slow speed again
LewisSeiden Apr 4, 2025
1693fff
make shoulder manual zero ignore disasble
LewisSeiden Apr 4, 2025
a0af068
make shoulder manual zero ignore disasble
LewisSeiden Apr 4, 2025
650c6f8
make leds orange when not zeroed
LewisSeiden Apr 4, 2025
b092e4d
make anti jam hold position and spit coral
LewisSeiden Apr 4, 2025
d53cb0c
make wrist assume starting pose if not alr zeroed
LewisSeiden Apr 5, 2025
e12eae3
merge remote formatting commit
LewisSeiden Apr 5, 2025
fa2e20d
adjsut l4 pose
LewisSeiden Apr 5, 2025
0add364
adjust hp pose
LewisSeiden Apr 5, 2025
84b024a
Update at 'Sat Apr 05 08:23:17 PDT 2025'
LewisSeiden Apr 5, 2025
1e1c16c
Update at 'Sat Apr 05 08:26:26 PDT 2025'
LewisSeiden Apr 5, 2025
a73f7ae
Update at 'Sat Apr 05 08:35:03 PDT 2025'
LewisSeiden Apr 5, 2025
e2771af
Update at 'Sat Apr 05 08:38:02 PDT 2025'
LewisSeiden Apr 5, 2025
115d9cf
Update at 'Sat Apr 05 08:41:38 PDT 2025'
LewisSeiden Apr 5, 2025
1fde829
Update at 'Sat Apr 05 09:05:42 PDT 2025'
LewisSeiden Apr 5, 2025
4f43c35
Update at 'Sat Apr 05 09:12:29 PDT 2025'
LewisSeiden Apr 5, 2025
3dc3042
Update at 'Sat Apr 05 09:12:58 PDT 2025'
LewisSeiden Apr 5, 2025
4d51253
make ground intake position reset happen sooner
LewisSeiden Apr 5, 2025
de0def1
increase climb pos
LewisSeiden Apr 5, 2025
6b0d604
Update at 'Sat Apr 05 11:08:53 PDT 2025'
LewisSeiden Apr 5, 2025
af12c89
fmt
LewisSeiden Apr 5, 2025
aff0805
Update at 'Sat Apr 05 11:15:37 PDT 2025'
LewisSeiden Apr 5, 2025
f4f2795
Update at 'Sat Apr 05 11:35:25 PDT 2025'
LewisSeiden Apr 5, 2025
cdcc9b0
Update at 'Sat Apr 05 11:36:50 PDT 2025'
LewisSeiden Apr 5, 2025
2964013
Update at 'Sat Apr 05 11:38:49 PDT 2025'
LewisSeiden Apr 5, 2025
b4100e2
Update at 'Sat Apr 05 11:40:53 PDT 2025'
LewisSeiden Apr 5, 2025
3489b3d
Update at 'Sat Apr 05 11:42:24 PDT 2025'
LewisSeiden Apr 5, 2025
5ba975a
Update at 'Sat Apr 05 11:45:58 PDT 2025'
LewisSeiden Apr 5, 2025
edfe782
make manipulator hold reset if moved too far
LewisSeiden Apr 5, 2025
b44bc93
adjust l4
LewisSeiden Apr 5, 2025
8103438
Update at 'Sat Apr 05 12:45:41 PDT 2025'
LewisSeiden Apr 5, 2025
5d36229
Update at 'Sat Apr 05 12:49:50 PDT 2025'
LewisSeiden Apr 5, 2025
00b1450
Update at 'Sat Apr 05 12:50:13 PDT 2025'
LewisSeiden Apr 5, 2025
35f9ab2
Update at 'Sat Apr 05 12:53:47 PDT 2025'
LewisSeiden Apr 5, 2025
d8926d7
Update at 'Sat Apr 05 12:55:39 PDT 2025'
LewisSeiden Apr 5, 2025
76cff1d
Update at 'Sat Apr 05 12:57:23 PDT 2025'
LewisSeiden Apr 5, 2025
fa850bd
Update at 'Sat Apr 05 13:04:25 PDT 2025'
LewisSeiden Apr 5, 2025
7ef6581
Update at 'Sat Apr 05 13:06:34 PDT 2025'
LewisSeiden Apr 5, 2025
9dd2ba1
Update at 'Sat Apr 05 13:12:36 PDT 2025'
LewisSeiden Apr 5, 2025
d77f794
Update at 'Sat Apr 05 13:12:49 PDT 2025'
LewisSeiden Apr 5, 2025
21711ea
Update at 'Sat Apr 05 13:28:17 PDT 2025'
LewisSeiden Apr 5, 2025
94120b9
Update at 'Sat Apr 05 13:33:08 PDT 2025'
LewisSeiden Apr 5, 2025
4ed1c23
Revert "Update at 'Sat Apr 05 13:33:08 PDT 2025'"
LewisSeiden Apr 5, 2025
b927795
Revert "Update at 'Sat Apr 05 13:28:17 PDT 2025'"
LewisSeiden Apr 5, 2025
d36308f
Revert "Update at 'Sat Apr 05 13:12:49 PDT 2025'"
LewisSeiden Apr 5, 2025
81c6cb1
Revert "Update at 'Sat Apr 05 13:12:36 PDT 2025'"
LewisSeiden Apr 5, 2025
13b3421
Revert "Update at 'Sat Apr 05 13:06:34 PDT 2025'"
LewisSeiden Apr 5, 2025
c75a919
Revert "Update at 'Sat Apr 05 13:04:25 PDT 2025'"
LewisSeiden Apr 5, 2025
b515a23
adjust hp pose again
LewisSeiden Apr 5, 2025
f947359
decrease funnel vel
LewisSeiden Apr 5, 2025
3ebe8a4
slow funnel more
LewisSeiden Apr 5, 2025
dc69d5e
slow down reverse indexing
LewisSeiden Apr 5, 2025
517a6e4
make IDLE wait for zero to go to READY_CORAL
LewisSeiden Apr 5, 2025
9b16223
increase rev indexing speed again
LewisSeiden Apr 5, 2025
8f057e3
make manipulator never stop in SCORE_CORAL
LewisSeiden Apr 6, 2025
c6d3d57
adjust how we wait for hitting target to outtake for SCORE_CORAL
LewisSeiden Apr 6, 2025
8adc89f
timeout shoulder hold in final stage of clearance extend
LewisSeiden Apr 6, 2025
7453743
tune operator jog
LewisSeiden Apr 6, 2025
c14703c
adjust processor height to slam less
LewisSeiden Apr 6, 2025
b751f01
use proper slow barge shot
LewisSeiden Apr 6, 2025
57d9573
reduce net shoulder vel a bit
LewisSeiden Apr 6, 2025
c00c72e
initial impl of path finding
LewisSeiden Apr 8, 2025
32a0c39
add cache
LewisSeiden Apr 8, 2025
6265096
rewrite extendWithClearance to use pathing
LewisSeiden Apr 8, 2025
4b99e44
add untucked and coral ground nodes
LewisSeiden Apr 8, 2025
64cbee1
add extension checking method
LewisSeiden Apr 8, 2025
beca0a3
make ground intake clearancyier
LewisSeiden Apr 8, 2025
ae961d5
add node between tucked and untucked state
LewisSeiden Apr 8, 2025
7ac5b46
use second order sorts for path finding
LewisSeiden Apr 8, 2025
9832a23
add more tolerance to leaving states
LewisSeiden Apr 8, 2025
3632aea
increase tols more
LewisSeiden Apr 8, 2025
b0ffb18
add l1 to pathing
LewisSeiden Apr 8, 2025
5497a3e
add precoralground
LewisSeiden Apr 8, 2025
cc08356
add edges for cancelling between states
LewisSeiden Apr 8, 2025
96e0835
make ground intake wait for wrist
LewisSeiden Apr 8, 2025
0f58a97
Merge branch 'main' into extension-graph
LewisSeiden Apr 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 61 additions & 3 deletions src/main/java/frc/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import edu.wpi.first.wpilibj2.command.button.Trigger;
import frc.robot.subsystems.ExtensionKinematics;
import frc.robot.subsystems.ExtensionKinematics.ExtensionState;
import frc.robot.subsystems.ExtensionPathing;
import frc.robot.subsystems.FunnelSubsystem;
import frc.robot.subsystems.ManipulatorSubsystem;
import frc.robot.subsystems.Superstructure;
Expand Down Expand Up @@ -123,6 +124,9 @@ private RobotHardware(SwerveConstants swerveConstants) {
public static final RobotType ROBOT_TYPE = Robot.isReal() ? RobotType.REAL : RobotType.SIM;
// For replay to work properly this should match the hardware used in the log
public static final RobotHardware ROBOT_HARDWARE = RobotHardware.KELPIE;
// for testing class loading
public static final ExtensionState test =
ExtensionPathing.getNearest(new ExtensionState(0.0, Rotation2d.kZero, Rotation2d.kZero));

public static enum ReefTarget {
L1(
Expand Down Expand Up @@ -338,7 +342,7 @@ public static enum AlgaeScoreTarget {
.withMotionMagic(WristSubsystem.DEFAULT_MOTION_MAGIC)
.withCurrentLimits(
new CurrentLimitsConfigs()
.withStatorCurrentLimit(30.0)
.withStatorCurrentLimit(50.0)
.withStatorCurrentLimitEnable(true)
.withSupplyCurrentLimit(20.0)
.withSupplyCurrentLimitEnable(true))
Expand Down Expand Up @@ -618,6 +622,60 @@ public Robot() {
})
.ignoringDisable(true));

System.out.println("Node Count " + ExtensionPathing.graph.nodes().size());

SmartDashboard.putData(
"Traverse Extension Graph",
superstructure
.extendWithClearance(
() ->
new ExtensionState(
ElevatorSubsystem.HP_EXTENSION_METERS,
ShoulderSubsystem.SHOULDER_HP_POS,
WristSubsystem.WRIST_HP_POS))
.until(
() ->
elevator.isNearExtension(ElevatorSubsystem.HP_EXTENSION_METERS)
&& shoulder.isNearAngle(ShoulderSubsystem.SHOULDER_HP_POS)
&& wrist.isNearAngle(WristSubsystem.WRIST_HP_POS))
.andThen(
Commands.sequence(
ExtensionPathing.graph.nodes().stream()
.map(
(node) ->
superstructure
.extendWithClearance(() -> node)
.alongWith(
Commands.print("Traversing to " + node),
Commands.runOnce(
() -> Logger.recordOutput("Traversal Target", node)))
.until(
() ->
elevator.isNearExtension(node.elevatorHeightMeters())
&& shoulder.isNearAngle(node.shoulderAngle())
&& wrist.isNearAngle(node.wristAngle()))
.finallyDo(() -> System.out.println("done"))
.andThen(
Commands.waitSeconds(0.5),
superstructure
.extendWithClearance(
() ->
new ExtensionState(
ElevatorSubsystem.HP_EXTENSION_METERS,
ShoulderSubsystem.SHOULDER_HP_POS,
WristSubsystem.WRIST_HP_POS))
.alongWith(Commands.print("Retracting"))
.until(
() ->
elevator.isNearExtension(
ElevatorSubsystem.HP_EXTENSION_METERS)
&& shoulder.isNearAngle(
ShoulderSubsystem.SHOULDER_HP_POS)
&& wrist.isNearAngle(
WristSubsystem.WRIST_HP_POS)),
Commands.waitSeconds(0.5)))
.toArray(Command[]::new))));

// Run auto when auto starts. Matches Choreolib's defer impl
RobotModeTriggers.autonomous()
.whileTrue(Commands.defer(() -> autoChooser.get().asProxy(), Set.of()));
Expand Down Expand Up @@ -701,9 +759,9 @@ public Robot() {

manipulator.setDefaultCommand(manipulator.hold());

shoulder.setDefaultCommand(shoulder.setTargetAngle(ShoulderSubsystem.SHOULDER_RETRACTED_POS));
shoulder.setDefaultCommand(shoulder.hold());

wrist.setDefaultCommand(wrist.setTargetAngle(WristSubsystem.WRIST_RETRACTED_POS));
wrist.setDefaultCommand(wrist.hold());

funnel.setDefaultCommand(funnel.setVoltage(0.0));

Expand Down
199 changes: 199 additions & 0 deletions src/main/java/frc/robot/subsystems/ExtensionPathing.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.

package frc.robot.subsystems;

import com.google.common.collect.Sets;
import com.google.common.graph.GraphBuilder;
import com.google.common.graph.MutableGraph;
import edu.wpi.first.math.Pair;
import edu.wpi.first.math.geometry.Rotation2d;
import frc.robot.subsystems.ExtensionKinematics.ExtensionState;
import frc.robot.subsystems.elevator.ElevatorSubsystem;
import frc.robot.subsystems.shoulder.ShoulderSubsystem;
import frc.robot.subsystems.wrist.WristSubsystem;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class ExtensionPathing {
public static final MutableGraph<ExtensionState> graph =
GraphBuilder.undirected().allowsSelfLoops(true).build();
// TODO make this cache distances so we can do partial caches
private static final Map<Pair<ExtensionState, ExtensionState>, List<ExtensionState>> cache =
new HashMap<>();

static {
final var hp =
new ExtensionState(
ElevatorSubsystem.HP_EXTENSION_METERS,
ShoulderSubsystem.SHOULDER_HP_POS,
WristSubsystem.WRIST_HP_POS);
graph.addNode(hp);
final var tucked =
new ExtensionState(
0.0,
ShoulderSubsystem.SHOULDER_TUCKED_CLEARANCE_POS,
WristSubsystem.WRIST_TUCKED_CLEARANCE_POS);
graph.addNode(tucked);
graph.putEdge(hp, tucked);
final var l2Tucked =
new ExtensionState(
ExtensionKinematics.L2_EXTENSION.elevatorHeightMeters(),
ShoulderSubsystem.SHOULDER_TUCKED_CLEARANCE_POS,
WristSubsystem.WRIST_TUCKED_CLEARANCE_POS);
graph.addNode(l2Tucked);
graph.putEdge(tucked, l2Tucked);
final var l3Tucked =
new ExtensionState(
ExtensionKinematics.L3_EXTENSION.elevatorHeightMeters(),
ShoulderSubsystem.SHOULDER_TUCKED_CLEARANCE_POS,
WristSubsystem.WRIST_TUCKED_CLEARANCE_POS);
graph.addNode(l3Tucked);
graph.putEdge(tucked, l3Tucked);
graph.putEdge(l3Tucked, l2Tucked);
final var l4Tucked =
new ExtensionState(
ExtensionKinematics.L4_EXTENSION.elevatorHeightMeters(),
ShoulderSubsystem.SHOULDER_TUCKED_CLEARANCE_POS,
WristSubsystem.WRIST_TUCKED_CLEARANCE_POS);
graph.addNode(l4Tucked);
graph.putEdge(tucked, l4Tucked);
graph.putEdge(l4Tucked, l3Tucked);
graph.putEdge(l4Tucked, l2Tucked);
final var l4TuckedOut =
new ExtensionState(
ExtensionKinematics.L4_EXTENSION.elevatorHeightMeters(),
Rotation2d.fromDegrees(25.0),
Rotation2d.fromDegrees(120.0));
graph.addNode(l4TuckedOut);
graph.putEdge(l4Tucked, l4TuckedOut);

final var betweenTucked =
new ExtensionState(0.0, Rotation2d.fromDegrees(35.0), WristSubsystem.WRIST_CLEARANCE_POS);
graph.addNode(betweenTucked);
graph.putEdge(tucked, betweenTucked);

final var untucked =
new ExtensionState(
0.0, ShoulderSubsystem.SHOULDER_CLEARANCE_POS, WristSubsystem.WRIST_CLEARANCE_POS);
graph.addNode(untucked);
graph.putEdge(betweenTucked, untucked);

final var preCoralGround =
new ExtensionState(
ElevatorSubsystem.GROUND_EXTENSION_METERS,
ShoulderSubsystem.SHOULDER_CORAL_GROUND_POS,
Rotation2d.kCCW_90deg);
graph.addNode(preCoralGround);
graph.putEdge(tucked, preCoralGround);

final var coralGround =
new ExtensionState(
ElevatorSubsystem.GROUND_EXTENSION_METERS,
ShoulderSubsystem.SHOULDER_CORAL_GROUND_POS,
WristSubsystem.WRIST_CORAL_GROUND);
graph.addNode(coralGround);
graph.putEdge(preCoralGround, coralGround);

final var retracted =
new ExtensionState(
0.0, ShoulderSubsystem.SHOULDER_RETRACTED_POS, WristSubsystem.WRIST_RETRACTED_POS);
graph.addNode(retracted);
graph.putEdge(untucked, retracted);
graph.putEdge(betweenTucked, retracted);

final var l1 = ExtensionKinematics.L1_EXTENSION;
graph.addNode(l1);
graph.putEdge(l1, betweenTucked);
}

private ExtensionPathing() {}

public static ExtensionState getNearest(ExtensionState state) {
return graph.nodes().stream()
.min(
(a, b) -> {
var aFK = ExtensionKinematics.solveFK(a);
var bFK = ExtensionKinematics.solveFK(b);
var stateFK = ExtensionKinematics.solveFK(state);
return (int)
(1000
* (aFK.getTranslation().getDistance(stateFK.getTranslation())
+ Math.abs(
aFK.getRotation().getRotations()
- stateFK.getRotation().getRotations()))
- 1000
* (bFK.getTranslation().getDistance(stateFK.getTranslation())
+ Math.abs(
bFK.getRotation().getRotations()
- stateFK.getRotation().getRotations())));
})
.get();
}

private record TotalMotion(double elevator, double shoulderRotations, double wristRotations) {
public TotalMotion plus(double elevator, double shoulderRotations, double wristRotations) {
return new TotalMotion(
this.elevator + elevator,
this.shoulderRotations + shoulderRotations,
this.wristRotations + wristRotations);
}
}

private static Pair<List<ExtensionState>, TotalMotion> search(
ExtensionState current, ExtensionState target, Set<ExtensionState> visited) {
if (current == target) {
List<ExtensionState> result = new ArrayList<>();
result.add(target);
return Pair.of(result, new TotalMotion(0, 0, 0));
}

final var edges = Sets.difference(graph.successors(current), visited);
final List<Pair<List<ExtensionState>, TotalMotion>> result = new ArrayList<>();
for (var edge : edges) {
final var path = search(edge, target, Sets.union(visited, Set.of(current)));
if (path != null) result.add(path);
}
if (result.size() == 0) return null;
final var best =
result.stream()
.min(
Comparator.comparing(
(Pair<List<ExtensionState>, TotalMotion> s) -> s.getSecond().elevator)
.thenComparing((s) -> s.getSecond().wristRotations)
.thenComparing((s) -> s.getSecond().shoulderRotations))
.get();
final List<ExtensionState> newList = new ArrayList<>();
newList.add(current);
newList.addAll(best.getFirst());
return Pair.of(
newList,
best.getSecond()
.plus(
Math.abs(
current.elevatorHeightMeters() - best.getFirst().get(0).elevatorHeightMeters()),
Math.abs(
current.shoulderAngle().getRotations()
- best.getFirst().get(0).shoulderAngle().getRotations()),
Math.abs(
current.wristAngle().getRotations()
- best.getFirst().get(0).wristAngle().getRotations())));
}

public static List<ExtensionState> getPath(ExtensionState current, ExtensionState target) {
final var nearestCurrent = getNearest(current);
final var nearestTarget = getNearest(target);
final var path =
cache.containsKey(Pair.of(nearestCurrent, nearestTarget))
? cache.get(Pair.of(nearestCurrent, nearestTarget))
: search(nearestCurrent, nearestTarget, Set.of()).getFirst();
path.add(target);
cache.putIfAbsent(Pair.of(nearestCurrent, nearestTarget), path);
return path;
}
}
26 changes: 13 additions & 13 deletions src/main/java/frc/robot/subsystems/ManipulatorSubsystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ public void periodic() {
if (Robot.ROBOT_TYPE != RobotType.REAL)
Logger.recordOutput(NAME + "/Filtered Current", currentFilterValue);

if (firstBBInputs.get && !secondBBInputs.get) {
if (getFirstBeambreak() && !getSecondBeambreak()) {
Tracer.trace("Manipulator/Zero", () -> io.resetEncoder(0.0));
zeroTimer.reset();
}

if (!firstBBInputs.get && secondBBInputs.get) {
if (!getFirstBeambreak() && getSecondBeambreak()) {
// Number calculated from coral length, may need tuning
Tracer.trace("Manipulator/Zero", () -> io.resetEncoder(1.0));
zeroTimer.reset();
Expand All @@ -95,16 +95,16 @@ public void periodic() {
public Command index() {
return Commands.sequence(
setVelocity(9.0)
.until(() -> firstBBInputs.get || secondBBInputs.get)
.unless(() -> firstBBInputs.get),
setVelocity(3.0).until(() -> secondBBInputs.get).unless(() -> secondBBInputs.get),
.until(() -> getFirstBeambreak() || getSecondBeambreak())
.unless(() -> getFirstBeambreak()),
setVelocity(3.0).until(() -> getSecondBeambreak()).unless(() -> getSecondBeambreak()),
setVelocity(-3.0)
.until(() -> firstBBInputs.get && !secondBBInputs.get)
.until(() -> getFirstBeambreak() && !getSecondBeambreak())
.unless(() -> zeroTimer.get() < 0.25),
// TODO tune timeout
// Commands.runOnce(() -> io.resetEncoder(0.0)),
Commands.run(() -> io.setPosition(Rotation2d.fromRotations(1.1)))
.until(() -> !firstBBInputs.get && !secondBBInputs.get));
.until(() -> !getFirstBeambreak() && !getSecondBeambreak()));
} // TODO check if anything got lost in merge?

public Command jog(double rotations) {
Expand Down Expand Up @@ -146,26 +146,26 @@ public Command intakeCoral() {
public Command intakeCoralAir(double vel) {
return Commands.sequence(
setVelocity(vel)
.until(() -> secondBBInputs.get)
.until(() -> getSecondBeambreak())
.finallyDo(
() -> {
io.setPosition(Rotation2d.fromRotations(0.63));
positionSetpoint = 0.63;
}),
setVoltage(2.0).until(() -> !firstBBInputs.get),
jog(CORAL_HOLD_POS).until(() -> !secondBBInputs.get && !firstBBInputs.get));
setVoltage(2.0).until(() -> !getFirstBeambreak()),
jog(CORAL_HOLD_POS).until(() -> !getSecondBeambreak() && !getFirstBeambreak()));
}

public Command intakeCoral(double vel) {
return Commands.sequence(
setVelocity(vel).until(new Trigger(() -> secondBBInputs.get).debounce(0.5)),
setVelocity(vel).until(new Trigger(() -> getSecondBeambreak()).debounce(0.5)),
Commands.runOnce(
() -> {
io.setPosition(Rotation2d.fromRotations(0.5));
positionSetpoint = 0.5;
}),
setVelocity(1.0).until(() -> !firstBBInputs.get),
jog(CORAL_HOLD_POS).until(() -> !secondBBInputs.get && !firstBBInputs.get));
setVelocity(1.0).until(() -> !getFirstBeambreak()),
jog(CORAL_HOLD_POS).until(() -> !getSecondBeambreak() && !getFirstBeambreak()));
}

public Command intakeAlgae() {
Expand Down
Loading