@@ -599,6 +599,111 @@ TEST_F(RobotTrajectoryTestFixture, RobotTrajectoryDensity)
599599 EXPECT_FALSE (density.has_value ());
600600}
601601
602+ TEST_F (RobotTrajectoryTestFixture, RobotTrajectoryFindWayPointIndicesBetweenWaypoints)
603+ {
604+ robot_trajectory::RobotTrajectoryPtr trajectory;
605+ initTestTrajectory (trajectory);
606+ EXPECT_EQ (trajectory->size (), 5 );
607+ EXPECT_EQ (trajectory->getDuration (), 0.5 );
608+
609+ int before = -1 ;
610+ int after = -1 ;
611+ double blend = -1.0 ;
612+
613+ EXPECT_NO_THROW (trajectory->findWayPointIndicesForDurationAfterStart (0.15 , before, after, blend));
614+ EXPECT_EQ (before, 0 );
615+ EXPECT_EQ (after, 1 );
616+ EXPECT_NEAR (blend, /* between 0 and 1*/ 0.5 , 1e-6 );
617+
618+ EXPECT_NO_THROW (trajectory->findWayPointIndicesForDurationAfterStart (0.3 , before, after, blend));
619+ EXPECT_EQ (before, 1 );
620+ EXPECT_EQ (after, 2 );
621+ EXPECT_NEAR (blend, /* exactly at 2*/ 1.0 , 1e-6 );
622+ }
623+
624+ TEST_F (RobotTrajectoryTestFixture, RobotTrajectoryFindWayPointIndicesAtLastOfManyWaypoints)
625+ {
626+ robot_trajectory::RobotTrajectoryPtr trajectory;
627+ initTestTrajectory (trajectory);
628+
629+ int before = -1 ;
630+ int after = -1 ;
631+ double blend = -1.0 ;
632+
633+ const double total_duration = trajectory->getDuration ();
634+ EXPECT_NO_THROW (trajectory->findWayPointIndicesForDurationAfterStart (total_duration, before, after, blend));
635+ EXPECT_EQ (before, 3 );
636+ EXPECT_EQ (after, 4 );
637+ EXPECT_DOUBLE_EQ (blend, 1.0 );
638+ }
639+
640+ TEST_F (RobotTrajectoryTestFixture, RobotTrajectoryFindWayPointIndicesAfterLastWaypoint)
641+ {
642+ robot_trajectory::RobotTrajectoryPtr trajectory;
643+ initTestTrajectory (trajectory);
644+
645+ const double total_duration = trajectory->getDuration ();
646+ const double outbound_duration = total_duration + 100.0 ;
647+ EXPECT_GT (outbound_duration, total_duration);
648+
649+ int before = -1 ;
650+ int after = -1 ;
651+ double blend = -1.0 ;
652+ EXPECT_NO_THROW (trajectory->findWayPointIndicesForDurationAfterStart (outbound_duration, before, after, blend));
653+ EXPECT_EQ (before, 4 );
654+ EXPECT_EQ (after, 4 );
655+ EXPECT_DOUBLE_EQ (blend, 1.0 );
656+ }
657+
658+ TEST_F (RobotTrajectoryTestFixture, RobotTrajectoryFindWayPointIndicesEmptyWaypoints)
659+ {
660+ robot_trajectory::RobotTrajectory empty_traj (robot_model_, arm_jmg_name_);
661+ const double total_duration = empty_traj.getDuration ();
662+ EXPECT_DOUBLE_EQ (total_duration, 0.0 );
663+
664+ const double outbound_duration = 1.0 ;
665+ EXPECT_GT (outbound_duration, total_duration);
666+
667+ int before = -1 ;
668+ int after = -1 ;
669+ double blend = -1.0 ;
670+ EXPECT_NO_THROW (empty_traj.findWayPointIndicesForDurationAfterStart (outbound_duration, before, after, blend));
671+ EXPECT_EQ (before, 0 );
672+ EXPECT_EQ (after, 0 );
673+ EXPECT_DOUBLE_EQ (blend, 0.0 );
674+ }
675+
676+ TEST_F (RobotTrajectoryTestFixture, RobotTrajectoryFindWayPointIndicesBeforeFirstWaypoint)
677+ {
678+ robot_trajectory::RobotTrajectoryPtr trajectory;
679+ initTestTrajectory (trajectory);
680+
681+ int before = -1 ;
682+ int after = -1 ;
683+ double blend = -1.0 ;
684+
685+ EXPECT_NO_THROW (trajectory->findWayPointIndicesForDurationAfterStart (-0.1 , before, after, blend));
686+ EXPECT_EQ (before, 0 );
687+ EXPECT_EQ (after, 0 );
688+ EXPECT_DOUBLE_EQ (blend, 0.0 );
689+ }
690+
691+ TEST_F (RobotTrajectoryTestFixture, RobotTrajectoryFindWayPointIndicesAtLastOfSingleWaypoint)
692+ {
693+ robot_trajectory::RobotTrajectory trajectory (robot_model_, arm_jmg_name_);
694+ trajectory.addSuffixWayPoint (robot_state_, 0.0 );
695+
696+ int before = -1 ;
697+ int after = -1 ;
698+ double blend = -1.0 ;
699+
700+ const double total_duration = trajectory.getDuration ();
701+ EXPECT_NO_THROW (trajectory.findWayPointIndicesForDurationAfterStart (total_duration, before, after, blend));
702+ EXPECT_EQ (before, 0 );
703+ EXPECT_EQ (after, 0 );
704+ EXPECT_DOUBLE_EQ (blend, 1.0 );
705+ }
706+
602707TEST_F (OneRobot, Unwind)
603708{
604709 const double epsilon = 1e-4 ;
0 commit comments