@@ -141,16 +141,45 @@ void RobotContainer::ConfigureBindings() {
141141 // Test Commands for Elevator
142142 m_oi.ElevatorUpTrigger .WhileTrue (m_superStructure.m_elevator .MoveUp ());
143143 m_oi.ElevatorDownTrigger .WhileTrue (m_superStructure.m_elevator .MoveDown ());
144- m_oi.FollowPathTrigger .WhileTrue (
144+ /* m_oi.FollowPathTrigger.WhileTrue(
145145 m_test.has_value() ? m_swerve.FollowPathCommand(m_test.value())
146- : frc2::cmd::None ());
146+ : frc2::cmd::None());*/
147147
148148 // End Effector
149149 m_oi.EndEffectorInTrigger .WhileTrue (m_endeffector.MotorBackwardCommand ());
150150 m_oi.EndEffectorOutTrigger .WhileTrue (m_endeffector.MotorForwardCommand ());
151151
152152 // Driver Auto Score
153+ /* Example of how to use CustomSwerveCommand to align in arbitrary ways.
154+ This code makes it so the robot aligns its angle to the nearest coral
155+ station pose */
156+ m_oi.IntakeTrigger .WhileTrue (m_swerve.CustomSwerveCommand (
157+ [this ] { return m_oi.fwd (); }, [this ] { return m_oi.strafe (); },
158+ [this ] {
159+ return ReefAssist::GetNearestCoralStationPose (m_swerve.GetPose ())
160+ .Rotation ()
161+ .Radians ();
162+ }));
153163 m_oi.IntakeTrigger .OnTrue (m_superStructure.Intake ());
164+
165+ /* Tested in sim. Auto-Aligns robot to nearest branch
166+ * Test with caution on real robot.
167+ * If it seems to be consistent, you can tune the ReefAssist values to make it
168+ * accurate.
169+ * You can also make 2 separate binds for LEFT/RIGHT if thats easier for
170+ * drivers.
171+ *
172+ * FusePose() runs here to get the latest correction from OPi.
173+ * Ideally this would run all the time (like it used to), but since its
174+ * unstable and untested, I've isolated it to a command so we only use its
175+ * values when we actually are trying to align to something.
176+ * --E
177+ */
178+ m_oi.DriveToPoseTrigger .WhileTrue (
179+ FusePose ().AlongWith (m_swerve.DriveToPoseIndefinitelyCommand ([this ] {
180+ return ReefAssist::getNearestScoringPose (m_swerve.GetPose ());
181+ })));
182+
154183 m_oi.ScoreTrigger .OnTrue (m_superStructure.Score ());
155184
156185 // Climb
@@ -253,10 +282,8 @@ void RobotContainer::ConfigureContinuous() {
253282 * any races there.
254283 */
255284 // ROS to swerve
256- frc2::CommandScheduler::GetInstance ().Schedule (frc2::cmd::Run ([this ] {
257- m_swerve.SetMapToOdom (
258- m_ros.GetMapToOdom ());
259- }).IgnoringDisable (true ));
285+ // Commented out until we really trust it
286+ // frc2::CommandScheduler::GetInstance().Schedule(FusePose());
260287
261288 if constexpr (frc::RobotBase::IsSimulation ()) {
262289 frc2::CommandScheduler::GetInstance ().Schedule (
@@ -266,6 +293,11 @@ void RobotContainer::ConfigureContinuous() {
266293 }
267294}
268295
296+ frc2::CommandPtr RobotContainer::FusePose () {
297+ return frc2::cmd::Run ([this ] { m_swerve.SetMapToOdom (m_ros.GetMapToOdom ()); })
298+ .IgnoringDisable (true );
299+ }
300+
269301frc2::CommandPtr RobotContainer::GetAutonomousCommand () {
270302 return AutoBuilder::ThreeL4Auto (m_swerve, m_superStructure);
271303}
0 commit comments