59
59
import frc .robot .util .LimelightHelpers .PoseEstimate ;
60
60
import frc .robot .util .LimelightHelpers .RawFiducial ;
61
61
import frc .robot .util .LocalADStarAK ;
62
+ import java .util .HashMap ;
62
63
import java .util .List ;
63
64
import java .util .Optional ;
64
65
import org .littletonrobotics .junction .AutoLogOutput ;
@@ -120,6 +121,8 @@ public TimestampedT2d(Translation2d translation, double time) {
120
121
121
122
CircularBuffer <TimestampedPose2d > robotPoseBuffer ;
122
123
124
+ private HashMap <NOTE_POSITIONS , Translation2d > noteLocations = new HashMap <>();
125
+
123
126
public Drive (
124
127
GyroIO gyroIO ,
125
128
VisionIO visionIO ,
@@ -185,6 +188,21 @@ public Drive(
185
188
rotationController .setTolerance (5 );
186
189
rotationController .enableContinuousInput (-180 , 180 );
187
190
robotPoseBuffer = new CircularBuffer <>(11 );
191
+
192
+ noteLocations .put (NOTE_POSITIONS .C5 , FieldConstants .StagingLocations .centerlineTranslations [0 ]);
193
+ noteLocations .put (NOTE_POSITIONS .C4 , FieldConstants .StagingLocations .centerlineTranslations [1 ]);
194
+ noteLocations .put (NOTE_POSITIONS .C3 , FieldConstants .StagingLocations .centerlineTranslations [2 ]);
195
+ noteLocations .put (NOTE_POSITIONS .C2 , FieldConstants .StagingLocations .centerlineTranslations [3 ]);
196
+ noteLocations .put (NOTE_POSITIONS .C1 , FieldConstants .StagingLocations .centerlineTranslations [4 ]);
197
+ noteLocations .put (
198
+ NOTE_POSITIONS .B1 ,
199
+ AllianceFlipUtil .apply (FieldConstants .StagingLocations .spikeTranslations [2 ]));
200
+ noteLocations .put (
201
+ NOTE_POSITIONS .B2 ,
202
+ AllianceFlipUtil .apply (FieldConstants .StagingLocations .spikeTranslations [1 ]));
203
+ noteLocations .put (
204
+ NOTE_POSITIONS .B3 ,
205
+ AllianceFlipUtil .apply (FieldConstants .StagingLocations .spikeTranslations [0 ]));
188
206
}
189
207
190
208
public void periodic () {
@@ -698,7 +716,37 @@ public Optional<Rotation2d> turnToSpeakerAngle() {
698
716
return Optional .empty ();
699
717
}
700
718
701
- public PathPlannerPath generateTrajectory (
719
+ public void runPath (PathPlannerPath path ) {
720
+ AutoBuilder .followPath (path ).schedule ();
721
+ }
722
+
723
+ public Translation2d getTargetNoteLocation () {
724
+ if (visionInputs .iTX != 0.0 ) {
725
+ double taThreshold = 0 ;
726
+ if (visionInputs .iTA >= taThreshold ) {
727
+ lastNoteLocT2d .translation =
728
+ calculateNotePositionFieldRelative ().getTranslation ().toTranslation2d ();
729
+ lastNoteLocT2d .time = Timer .getFPGATimestamp ();
730
+ }
731
+ }
732
+
733
+ Translation2d visionCoords = getCachedNoteLocation ();
734
+ Translation2d fieldCoords = noteLocations .get (getNote ());
735
+ boolean useVisionNoteCoords =
736
+ getCachedNoteLocation ().getDistance (fieldCoords ) < 1.25
737
+ && getCachedNoteLocation () != null
738
+ && getCachedNoteTime () != -1
739
+ && noteImageIsNew ();
740
+
741
+ Logger .recordOutput (
742
+ "cached note distance to field " , getCachedNoteLocation ().getDistance (fieldCoords ));
743
+ Logger .recordOutput ("use vision note coords" , useVisionNoteCoords );
744
+
745
+ if (useVisionNoteCoords ) return visionCoords ;
746
+ return fieldCoords ;
747
+ }
748
+
749
+ public PathPlannerPath generateTrajectoryToNote (
702
750
Translation2d target ,
703
751
double maxVelMetersPerSec ,
704
752
double maxAccelMetersPerSecSquared ,
@@ -707,10 +755,12 @@ public PathPlannerPath generateTrajectory(
707
755
double endVelMetersPerSec ) {
708
756
Rotation2d targetRotation =
709
757
new Rotation2d (target .getX () - getPose ().getX (), target .getY () - getPose ().getY ());
758
+
759
+ Logger .recordOutput ("Target Note Pose3d" , new Pose3d (new Pose2d (target , new Rotation2d ())));
710
760
List <Translation2d > points =
711
761
PathPlannerPath .bezierFromPoses (
712
762
new Pose2d (getPose ().getX (), getPose ().getY (), getPose ().getRotation ()),
713
- new Pose2d (target .getX (), target .getY (), AllianceFlipUtil . apply ( targetRotation ) ));
763
+ new Pose2d (target .getX (), target .getY (), targetRotation ));
714
764
PathPlannerPath path =
715
765
new PathPlannerPath (
716
766
points ,
@@ -719,25 +769,14 @@ public PathPlannerPath generateTrajectory(
719
769
maxAccelMetersPerSecSquared ,
720
770
Units .degreesToRadians (maxAngVelDegPerSec ),
721
771
Units .degreesToRadians (maxAngAccelDegPerSecSquared )),
722
- new GoalEndState (endVelMetersPerSec , AllianceFlipUtil . apply ( targetRotation ) , true ));
772
+ new GoalEndState (endVelMetersPerSec , targetRotation , true ));
723
773
724
- return path ;
725
- }
774
+ path .preventFlipping = true ;
726
775
727
- public void runPath (PathPlannerPath path ) {
728
- AutoBuilder .followPath (path ).schedule ();
776
+ return path ;
729
777
}
730
778
731
779
public PathPlannerPath generatePathToNote () {
732
- if (visionInputs .iTX != 0.0 ) {
733
- double taThreshold = 0 ;
734
- if (visionInputs .iTA >= taThreshold ) {
735
- lastNoteLocT2d .translation =
736
- calculateNotePositionFieldRelative ().getTranslation ().toTranslation2d ();
737
- lastNoteLocT2d .time = Timer .getFPGATimestamp ();
738
- }
739
- }
740
-
741
780
Rotation2d targetRotation ;
742
781
Logger .recordOutput ("note timeess" , getCachedNoteTime ());
743
782
if (getCachedNoteTime () != -1 ) {
@@ -800,69 +839,6 @@ public PathPlannerPath generatePathToNote() {
800
839
}
801
840
}
802
841
803
- public PathPlannerPath generatePathToNoteBlind (Translation2d targetNoteLocation ) {
804
- // if (visionInputs.iTX != 0.0) {
805
- // double taThreshold = 0;
806
- // if (visionInputs.iTA >= taThreshold) {
807
- // lastNoteLocT2d.translation =
808
- // calculateNotePositionFieldRelative().getTranslation().toTranslation2d();
809
- // lastNoteLocT2d.time = Timer.getFPGATimestamp();
810
- // }
811
- // }
812
- // Pose2d targetNoteLocation = noteLocations.get(drive.getTargetNote());
813
-
814
- Rotation2d targetRotation ;
815
- Logger .recordOutput ("note timeess" , getCachedNoteTime ());
816
- // led.setState(LED_STATE.FLASHING_RED);
817
- // Translation2d targetNoteLocation = getCachedNoteLocation();
818
- Logger .recordOutput ("better translate" , targetNoteLocation );
819
- if (noteImageIsNew ()) {
820
-
821
- targetRotation =
822
- new Rotation2d (
823
- targetNoteLocation .getX () - getPose ().getX (),
824
- targetNoteLocation .getY () - getPose ().getY ());
825
- List <Translation2d > pointsToNote ;
826
- if (DriverStation .getAlliance ().get ().equals (Alliance .Blue )) {
827
- Logger .recordOutput (
828
- "goal point blue" ,
829
- new Pose2d (targetNoteLocation .getX (), targetNoteLocation .getY (), targetRotation ));
830
- pointsToNote =
831
- PathPlannerPath .bezierFromPoses (
832
- new Pose2d (getPose ().getX (), getPose ().getY (), targetRotation ),
833
- new Pose2d (targetNoteLocation .getX (), targetNoteLocation .getY (), targetRotation ));
834
- } else {
835
- Logger .recordOutput (
836
- "goal point red" ,
837
- new Pose2d (targetNoteLocation .getX (), targetNoteLocation .getY (), targetRotation ));
838
- pointsToNote =
839
- PathPlannerPath .bezierFromPoses (
840
- new Pose2d (getPose ().getX (), getPose ().getY (), targetRotation ),
841
- new Pose2d (targetNoteLocation .getX (), targetNoteLocation .getY (), targetRotation ));
842
- }
843
- PathPlannerPath path =
844
- new PathPlannerPath (
845
- pointsToNote ,
846
- new PathConstraints (
847
- 3 , 2.45 , Units .degreesToRadians (100 ), Units .degreesToRadians (180 )),
848
- new GoalEndState (0.5 , targetRotation , true ));
849
-
850
- path .preventFlipping = true ;
851
- // AutoBuilder.followPath(path).schedule();
852
- Logger .recordOutput ("follow path" , true );
853
- return path ;
854
- } else {
855
- // return;
856
- // led.setState(LED_STATE.PAPAYA_ORANGE);
857
- return new PathPlannerPath (
858
- PathPlannerPath .bezierFromPoses (
859
- new Pose2d (getPose ().getX (), getPose ().getY (), getPose ().getRotation ()),
860
- new Pose2d (getPose ().getX (), getPose ().getY (), getPose ().getRotation ())),
861
- new PathConstraints (0.1 , 1.5 , Units .degreesToRadians (100 ), Units .degreesToRadians (180 )),
862
- new GoalEndState (0.5 , getPose ().getRotation (), true ));
863
- }
864
- }
865
-
866
842
public Command createPathFindingCommand (Pose2d target ) {
867
843
Pose2d coord = target ;
868
844
PathConstraints constraints =
@@ -1019,11 +995,11 @@ public Command followPathCommand(String pathName, boolean lowerPID) {
1019
995
);
1020
996
}
1021
997
1022
- public void setTargetNote (NOTE_POSITIONS targetNote ) {
998
+ public void setNote (NOTE_POSITIONS targetNote ) {
1023
999
this .targetNote = targetNote ;
1024
1000
}
1025
1001
1026
- public NOTE_POSITIONS getTargetNote () {
1002
+ public NOTE_POSITIONS getNote () {
1027
1003
return targetNote ;
1028
1004
}
1029
1005
}
0 commit comments