5959import frc .robot .util .LimelightHelpers .PoseEstimate ;
6060import frc .robot .util .LimelightHelpers .RawFiducial ;
6161import frc .robot .util .LocalADStarAK ;
62+ import java .util .HashMap ;
6263import java .util .List ;
6364import java .util .Optional ;
6465import org .littletonrobotics .junction .AutoLogOutput ;
@@ -120,6 +121,8 @@ public TimestampedT2d(Translation2d translation, double time) {
120121
121122 CircularBuffer <TimestampedPose2d > robotPoseBuffer ;
122123
124+ private HashMap <NOTE_POSITIONS , Translation2d > noteLocations = new HashMap <>();
125+
123126 public Drive (
124127 GyroIO gyroIO ,
125128 VisionIO visionIO ,
@@ -185,6 +188,21 @@ public Drive(
185188 rotationController .setTolerance (5 );
186189 rotationController .enableContinuousInput (-180 , 180 );
187190 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 ]));
188206 }
189207
190208 public void periodic () {
@@ -698,7 +716,37 @@ public Optional<Rotation2d> turnToSpeakerAngle() {
698716 return Optional .empty ();
699717 }
700718
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 (
702750 Translation2d target ,
703751 double maxVelMetersPerSec ,
704752 double maxAccelMetersPerSecSquared ,
@@ -707,10 +755,12 @@ public PathPlannerPath generateTrajectory(
707755 double endVelMetersPerSec ) {
708756 Rotation2d targetRotation =
709757 new Rotation2d (target .getX () - getPose ().getX (), target .getY () - getPose ().getY ());
758+
759+ Logger .recordOutput ("Target Note Pose3d" , new Pose3d (new Pose2d (target , new Rotation2d ())));
710760 List <Translation2d > points =
711761 PathPlannerPath .bezierFromPoses (
712762 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 ));
714764 PathPlannerPath path =
715765 new PathPlannerPath (
716766 points ,
@@ -719,25 +769,14 @@ public PathPlannerPath generateTrajectory(
719769 maxAccelMetersPerSecSquared ,
720770 Units .degreesToRadians (maxAngVelDegPerSec ),
721771 Units .degreesToRadians (maxAngAccelDegPerSecSquared )),
722- new GoalEndState (endVelMetersPerSec , AllianceFlipUtil . apply ( targetRotation ) , true ));
772+ new GoalEndState (endVelMetersPerSec , targetRotation , true ));
723773
724- return path ;
725- }
774+ path .preventFlipping = true ;
726775
727- public void runPath (PathPlannerPath path ) {
728- AutoBuilder .followPath (path ).schedule ();
776+ return path ;
729777 }
730778
731779 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-
741780 Rotation2d targetRotation ;
742781 Logger .recordOutput ("note timeess" , getCachedNoteTime ());
743782 if (getCachedNoteTime () != -1 ) {
@@ -800,69 +839,6 @@ public PathPlannerPath generatePathToNote() {
800839 }
801840 }
802841
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-
866842 public Command createPathFindingCommand (Pose2d target ) {
867843 Pose2d coord = target ;
868844 PathConstraints constraints =
@@ -1019,11 +995,11 @@ public Command followPathCommand(String pathName, boolean lowerPID) {
1019995 );
1020996 }
1021997
1022- public void setTargetNote (NOTE_POSITIONS targetNote ) {
998+ public void setNote (NOTE_POSITIONS targetNote ) {
1023999 this .targetNote = targetNote ;
10241000 }
10251001
1026- public NOTE_POSITIONS getTargetNote () {
1002+ public NOTE_POSITIONS getNote () {
10271003 return targetNote ;
10281004 }
10291005}
0 commit comments