117 const std::shared_ptr<TrajectoryCache>& cache)
125 moveit_msgs::msg::MotionPlanRequest plan_req;
126 move_group->constructMotionPlanRequest(plan_req);
127 plan_req.workspace_parameters.header.frame_id =
ROBOT_FRAME;
128 plan_req.workspace_parameters.max_corner.x = 10;
129 plan_req.workspace_parameters.max_corner.y = 10;
130 plan_req.workspace_parameters.max_corner.z = 10;
131 plan_req.workspace_parameters.min_corner.x = -10;
132 plan_req.workspace_parameters.min_corner.y = -10;
133 plan_req.workspace_parameters.min_corner.z = -10;
134 plan_req.start_state.multi_dof_joint_state.joint_names.clear();
135 plan_req.start_state.multi_dof_joint_state.transforms.clear();
136 plan_req.start_state.multi_dof_joint_state.twist.clear();
137 plan_req.start_state.multi_dof_joint_state.wrench.clear();
140 moveit_msgs::msg::MotionPlanRequest empty_frame_plan_req = plan_req;
141 empty_frame_plan_req.workspace_parameters.header.frame_id =
"";
144 auto is_diff_plan_req = plan_req;
145 is_diff_plan_req.start_state.is_diff =
true;
146 is_diff_plan_req.start_state.joint_state.header.frame_id =
"";
147 is_diff_plan_req.start_state.joint_state.name.clear();
148 is_diff_plan_req.start_state.joint_state.position.clear();
149 is_diff_plan_req.start_state.joint_state.velocity.clear();
150 is_diff_plan_req.start_state.joint_state.effort.clear();
153 auto close_matching_plan_req = plan_req;
154 close_matching_plan_req.workspace_parameters.max_corner.x += 0.05;
155 close_matching_plan_req.workspace_parameters.min_corner.x -= 0.05;
156 close_matching_plan_req.start_state.joint_state.position.at(0) -= 0.05;
157 close_matching_plan_req.start_state.joint_state.position.at(1) += 0.05;
158 close_matching_plan_req.start_state.joint_state.position.at(2) -= 0.05;
159 close_matching_plan_req.goal_constraints.at(0).joint_constraints.at(0).position -= 0.05;
160 close_matching_plan_req.goal_constraints.at(0).joint_constraints.at(1).position += 0.05;
161 close_matching_plan_req.goal_constraints.at(0).joint_constraints.at(2).position -= 0.05;
164 auto swapped_close_matching_plan_req = close_matching_plan_req;
165 std::swap(swapped_close_matching_plan_req.goal_constraints.at(0).joint_constraints.at(0),
166 swapped_close_matching_plan_req.goal_constraints.at(0).joint_constraints.at(1));
169 auto smaller_workspace_plan_req = plan_req;
170 smaller_workspace_plan_req.workspace_parameters.max_corner.x = 1;
171 smaller_workspace_plan_req.workspace_parameters.max_corner.y = 1;
172 smaller_workspace_plan_req.workspace_parameters.max_corner.z = 1;
173 smaller_workspace_plan_req.workspace_parameters.min_corner.x = -1;
174 smaller_workspace_plan_req.workspace_parameters.min_corner.y = -1;
175 smaller_workspace_plan_req.workspace_parameters.min_corner.z = -1;
178 auto larger_workspace_plan_req = plan_req;
179 larger_workspace_plan_req.workspace_parameters.max_corner.x = 50;
180 larger_workspace_plan_req.workspace_parameters.max_corner.y = 50;
181 larger_workspace_plan_req.workspace_parameters.max_corner.z = 50;
182 larger_workspace_plan_req.workspace_parameters.min_corner.x = -50;
183 larger_workspace_plan_req.workspace_parameters.min_corner.y = -50;
184 larger_workspace_plan_req.workspace_parameters.min_corner.z = -50;
187 auto different_plan_req = plan_req;
188 different_plan_req.workspace_parameters.max_corner.x += 1.05;
189 different_plan_req.workspace_parameters.min_corner.x -= 2.05;
190 different_plan_req.start_state.joint_state.position.at(0) -= 3.05;
191 different_plan_req.start_state.joint_state.position.at(1) += 4.05;
192 different_plan_req.start_state.joint_state.position.at(2) -= 5.05;
193 different_plan_req.goal_constraints.at(0).joint_constraints.at(0).position -= 6.05;
194 different_plan_req.goal_constraints.at(0).joint_constraints.at(1).position += 7.05;
195 different_plan_req.goal_constraints.at(0).joint_constraints.at(2).position -= 8.05;
203 auto empty_frame_traj = traj;
204 empty_frame_traj.joint_trajectory.header.frame_id =
"";
206 auto different_traj = traj;
207 different_traj.joint_trajectory.points.at(0).positions.at(0) = 999;
208 different_traj.joint_trajectory.points.at(0).positions.at(1) = 999;
209 different_traj.joint_trajectory.points.at(0).positions.at(2) = 999;
213 std::string test_case;
218 test_case =
"testMotionTrajectories.empty";
223 "Fetch all trajectories on empty cache returns empty");
226 "Fetch best trajectory on empty cache returns nullptr");
231 test_case =
"testMotionTrajectories.insertTrajectory_empty_frame";
232 double execution_time = 999;
233 double planning_time = 999;
236 planning_time,
false),
237 test_case,
"Put empty frame trajectory, no prune_worse_trajectories, not ok");
244 test_case =
"testMotionTrajectories.insertTrajectory_req_empty_frame";
245 execution_time = 1000;
246 planning_time = 1000;
249 planning_time,
false),
250 test_case,
"Put empty frame req trajectory, no prune_worse_trajectories, ok");
255 test_case =
"testMotionTrajectories.put_second";
256 execution_time = 999;
260 test_case,
"Put second valid trajectory, no prune_worse_trajectories, ok");
267 test_case =
"testMotionTrajectories.put_second.fetch_matching_no_tolerance";
269 auto fetched_trajectories = cache->fetchAllMatchingTrajectories(*
move_group,
ROBOT_NAME, plan_req, 0, 0);
271 auto fetched_traj = cache->fetchBestMatchingTrajectory(*
move_group,
ROBOT_NAME, plan_req, 0, 0);
273 checkAndEmit(fetched_trajectories.size() == 2, test_case,
"Fetch all returns two");
274 checkAndEmit(fetched_traj !=
nullptr, test_case,
"Fetch best trajectory is not nullptr");
276 checkAndEmit(*fetched_trajectories.at(0) == *fetched_traj, test_case,
"Fetched trajectory on both fetches match");
278 checkAndEmit(*fetched_traj == traj, test_case,
"Fetched trajectory matches original");
280 checkAndEmit(fetched_traj->lookupDouble(
"execution_time_s") == execution_time, test_case,
281 "Fetched trajectory has correct execution time");
283 checkAndEmit(fetched_traj->lookupDouble(
"planning_time_s") == planning_time, test_case,
284 "Fetched trajectory has correct planning time");
290 test_case =
"testMotionTrajectories.put_second.fetch_is_diff_no_tolerance";
292 fetched_trajectories = cache->fetchAllMatchingTrajectories(*
move_group,
ROBOT_NAME, is_diff_plan_req, 0, 0);
294 fetched_traj = cache->fetchBestMatchingTrajectory(*
move_group,
ROBOT_NAME, is_diff_plan_req, 0, 0);
296 checkAndEmit(fetched_trajectories.size() == 2, test_case,
"Fetch all returns two");
297 checkAndEmit(fetched_traj !=
nullptr, test_case,
"Fetch best trajectory is not nullptr");
299 checkAndEmit(*fetched_trajectories.at(0) == *fetched_traj, test_case,
"Fetched trajectory on both fetches match");
301 checkAndEmit(*fetched_traj == traj, test_case,
"Fetched trajectory matches original");
303 checkAndEmit(fetched_traj->lookupDouble(
"execution_time_s") == execution_time, test_case,
304 "Fetched trajectory has correct execution time");
306 checkAndEmit(fetched_traj->lookupDouble(
"planning_time_s") == planning_time, test_case,
307 "Fetched trajectory has correct planning time");
312 test_case =
"testMotionTrajectories.put_second.fetch_non_matching_out_of_tolerance";
314 fetched_trajectories = cache->fetchAllMatchingTrajectories(*
move_group,
ROBOT_NAME, close_matching_plan_req, 0, 0);
316 fetched_traj = cache->fetchBestMatchingTrajectory(*
move_group,
ROBOT_NAME, close_matching_plan_req, 0, 0);
318 checkAndEmit(fetched_trajectories.empty(), test_case,
"Fetch all returns empty");
319 checkAndEmit(fetched_traj ==
nullptr, test_case,
"Fetch best trajectory is nullptr");
324 test_case =
"testMotionTrajectories.put_second.fetch_non_matching_only_start_in_tolerance";
326 fetched_trajectories = cache->fetchAllMatchingTrajectories(*
move_group,
ROBOT_NAME, close_matching_plan_req, 999, 0);
328 fetched_traj = cache->fetchBestMatchingTrajectory(*
move_group,
ROBOT_NAME, close_matching_plan_req, 999, 0);
330 checkAndEmit(fetched_trajectories.empty(), test_case,
"Fetch all returns empty");
331 checkAndEmit(fetched_traj ==
nullptr, test_case,
"Fetch best trajectory is nullptr");
336 test_case =
"testMotionTrajectories.put_second.fetch_non_matching_only_goal_in_tolerance";
338 fetched_trajectories = cache->fetchAllMatchingTrajectories(*
move_group,
ROBOT_NAME, close_matching_plan_req, 0, 999);
340 fetched_traj = cache->fetchBestMatchingTrajectory(*
move_group,
ROBOT_NAME, close_matching_plan_req, 0, 999);
342 checkAndEmit(fetched_trajectories.empty(), test_case,
"Fetch all returns empty");
343 checkAndEmit(fetched_traj ==
nullptr, test_case,
"Fetch best trajectory is nullptr");
348 test_case =
"testMotionTrajectories.put_second.fetch_non_matching_in_tolerance";
350 fetched_trajectories =
351 cache->fetchAllMatchingTrajectories(*
move_group,
ROBOT_NAME, close_matching_plan_req, 0.1, 0.1);
353 fetched_traj = cache->fetchBestMatchingTrajectory(*
move_group,
ROBOT_NAME, close_matching_plan_req, 0.1, 0.1);
355 checkAndEmit(fetched_trajectories.size() == 2, test_case,
"Fetch all returns two");
356 checkAndEmit(fetched_traj !=
nullptr, test_case,
"Fetch best trajectory is not nullptr");
358 checkAndEmit(*fetched_trajectories.at(0) == *fetched_traj, test_case,
"Fetched trajectory on both fetches match");
360 checkAndEmit(*fetched_traj == traj, test_case,
"Fetched trajectory matches original");
362 checkAndEmit(fetched_traj->lookupDouble(
"execution_time_s") == execution_time, test_case,
363 "Fetched trajectory has correct execution time");
365 checkAndEmit(fetched_traj->lookupDouble(
"planning_time_s") == planning_time, test_case,
366 "Fetched trajectory has correct planning time");
371 test_case =
"testMotionTrajectories.put_second.fetch_swapped";
373 fetched_trajectories =
374 cache->fetchAllMatchingTrajectories(*
move_group,
ROBOT_NAME, swapped_close_matching_plan_req, 0.1, 0.1);
376 fetched_traj = cache->fetchBestMatchingTrajectory(*
move_group,
ROBOT_NAME, swapped_close_matching_plan_req, 0.1, 0.1);
378 checkAndEmit(fetched_trajectories.size() == 2, test_case,
"Fetch all returns two");
379 checkAndEmit(fetched_traj !=
nullptr, test_case,
"Fetch best trajectory is not nullptr");
381 checkAndEmit(*fetched_trajectories.at(0) == *fetched_traj, test_case,
"Fetched trajectory on both fetches match");
383 checkAndEmit(*fetched_traj == traj, test_case,
"Fetched trajectory matches original");
385 checkAndEmit(fetched_traj->lookupDouble(
"execution_time_s") == execution_time, test_case,
386 "Fetched trajectory has correct execution time");
388 checkAndEmit(fetched_traj->lookupDouble(
"planning_time_s") == planning_time, test_case,
389 "Fetched trajectory has correct planning time");
395 test_case =
"testMotionTrajectories.put_second.fetch_smaller_workspace";
397 fetched_trajectories =
398 cache->fetchAllMatchingTrajectories(*
move_group,
ROBOT_NAME, smaller_workspace_plan_req, 999, 999);
400 fetched_traj = cache->fetchBestMatchingTrajectory(*
move_group,
ROBOT_NAME, smaller_workspace_plan_req, 999, 999);
402 checkAndEmit(fetched_trajectories.empty(), test_case,
"Fetch all returns empty");
403 checkAndEmit(fetched_traj ==
nullptr, test_case,
"Fetch best trajectory is nullptr");
409 test_case =
"testMotionTrajectories.put_second.fetch_larger_workspace";
411 fetched_trajectories =
412 cache->fetchAllMatchingTrajectories(*
move_group,
ROBOT_NAME, larger_workspace_plan_req, 999, 999);
414 fetched_traj = cache->fetchBestMatchingTrajectory(*
move_group,
ROBOT_NAME, larger_workspace_plan_req, 999, 999);
416 checkAndEmit(fetched_trajectories.size() == 2, test_case,
"Fetch all returns two");
417 checkAndEmit(fetched_traj !=
nullptr, test_case,
"Fetch best trajectory is not nullptr");
419 checkAndEmit(*fetched_trajectories.at(0) == *fetched_traj, test_case,
"Fetched trajectory on both fetches match");
421 checkAndEmit(*fetched_traj == traj, test_case,
"Fetched trajectory matches original");
423 checkAndEmit(fetched_traj->lookupDouble(
"execution_time_s") == execution_time, test_case,
424 "Fetched trajectory has correct execution time");
426 checkAndEmit(fetched_traj->lookupDouble(
"planning_time_s") == planning_time, test_case,
427 "Fetched trajectory has correct planning time");
429 checkAndEmit(fetched_traj->lookupDouble(
"workspace_parameters.max_corner.x") <=
430 larger_workspace_plan_req.workspace_parameters.max_corner.x,
431 test_case,
"Fetched trajectory has more restrictive workspace max_corner");
433 checkAndEmit(fetched_traj->lookupDouble(
"workspace_parameters.max_corner.x") >=
434 larger_workspace_plan_req.workspace_parameters.min_corner.x,
435 test_case,
"Fetched trajectory has more restrictive workspace min_corner");
440 test_case =
"testMotionTrajectories.put_worse";
441 double worse_execution_time = execution_time + 100;
445 test_case,
"Put worse trajectory, no prune_worse_trajectories, not ok");
452 test_case =
"testMotionTrajectories.put_better";
453 double better_execution_time = execution_time - 100;
457 test_case,
"Put better trajectory, no prune_worse_trajectories, ok");
464 test_case =
"testMotionTrajectories.put_better.fetch_sorted";
466 fetched_trajectories = cache->fetchAllMatchingTrajectories(*
move_group,
ROBOT_NAME, plan_req, 0, 0);
470 checkAndEmit(fetched_trajectories.size() == 3, test_case,
"Fetch all returns three");
471 checkAndEmit(fetched_traj !=
nullptr, test_case,
"Fetch best trajectory is not nullptr");
473 checkAndEmit(*fetched_trajectories.at(0) == *fetched_traj, test_case,
"Fetched trajectory on both fetches match");
475 checkAndEmit(*fetched_traj == traj, test_case,
"Fetched trajectory matches original");
477 checkAndEmit(fetched_traj->lookupDouble(
"execution_time_s") == better_execution_time, test_case,
478 "Fetched trajectory has correct execution time");
480 checkAndEmit(fetched_traj->lookupDouble(
"planning_time_s") == planning_time, test_case,
481 "Fetched trajectory has correct planning time");
483 checkAndEmit(fetched_trajectories.at(0)->lookupDouble(
"execution_time_s") == better_execution_time &&
484 fetched_trajectories.at(1)->lookupDouble(
"execution_time_s") == execution_time,
485 test_case,
"Fetched trajectories are sorted correctly");
490 test_case =
"testMotionTrajectories.put_better_prune_worse_trajectories";
491 double even_better_execution_time = better_execution_time - 100;
494 planning_time,
true),
495 test_case,
"Put better trajectory, prune_worse_trajectories, ok");
500 test_case =
"testMotionTrajectories.put_better_prune_worse_trajectories.fetch";
502 fetched_trajectories = cache->fetchAllMatchingTrajectories(*
move_group,
ROBOT_NAME, plan_req, 0, 0);
506 checkAndEmit(fetched_trajectories.size() == 1, test_case,
"Fetch all returns one");
507 checkAndEmit(fetched_traj !=
nullptr, test_case,
"Fetch best trajectory is not nullptr");
509 checkAndEmit(*fetched_trajectories.at(0) == *fetched_traj, test_case,
"Fetched trajectory on both fetches match");
511 checkAndEmit(*fetched_traj == different_traj, test_case,
"Fetched trajectory matches original");
513 checkAndEmit(fetched_traj->lookupDouble(
"execution_time_s") == even_better_execution_time, test_case,
514 "Fetched trajectory has correct execution time");
516 checkAndEmit(fetched_traj->lookupDouble(
"planning_time_s") == planning_time, test_case,
517 "Fetched trajectory has correct planning time");
522 test_case =
"testMotionTrajectories.put_different_req";
525 better_execution_time, planning_time,
true),
526 test_case,
"Put different trajectory req, prune_worse_trajectories, ok");
533 test_case =
"testMotionTrajectories.put_different_req.fetch";
535 fetched_trajectories = cache->fetchAllMatchingTrajectories(*
move_group,
ROBOT_NAME, different_plan_req, 0, 0);
537 fetched_traj = cache->fetchBestMatchingTrajectory(*
move_group,
ROBOT_NAME, different_plan_req, 0, 0);
539 checkAndEmit(fetched_trajectories.size() == 1, test_case,
"Fetch all returns one");
540 checkAndEmit(fetched_traj !=
nullptr, test_case,
"Fetch best trajectory is not nullptr");
542 checkAndEmit(*fetched_trajectories.at(0) == *fetched_traj, test_case,
"Fetched trajectory on both fetches match");
544 checkAndEmit(*fetched_traj == different_traj, test_case,
"Fetched trajectory matches original");
546 checkAndEmit(fetched_traj->lookupDouble(
"execution_time_s") == better_execution_time, test_case,
547 "Fetched trajectory has correct execution time");
549 checkAndEmit(fetched_traj->lookupDouble(
"planning_time_s") == planning_time, test_case,
550 "Fetched trajectory has correct planning time");
555 test_case =
"testMotionTrajectories.different_robot.empty";
556 std::string different_robot_name =
"different_robot";
558 checkAndEmit(cache->countCartesianTrajectories(different_robot_name) == 0, test_case,
"No trajectories in cache");
563 test_case =
"testMotionTrajectories.different_robot.put_first";
564 checkAndEmit(cache->insertTrajectory(*
move_group, different_robot_name, different_plan_req, different_traj,
565 better_execution_time, planning_time,
true),
566 test_case,
"Put different trajectory req, prune_worse_trajectories, ok");
568 checkAndEmit(cache->countTrajectories(different_robot_name) == 1, test_case,
"One trajectory in cache");
570 checkAndEmit(cache->countTrajectories(
ROBOT_NAME) == 2, test_case,
"Two trajectories in original robot's cache");
572 fetched_trajectories = cache->fetchAllMatchingTrajectories(*
move_group,
ROBOT_NAME, different_plan_req, 0, 0);
574 checkAndEmit(fetched_trajectories.size() == 1, test_case,
"Fetch all on original still returns one");
578 const std::shared_ptr<TrajectoryCache>& cache)
580 std::string test_case;
585 test_case =
"testCartesianTrajectories.constructGetCartesianPathRequest";
590 auto cartesian_plan_req_under_test =
591 constructGetCartesianPathRequest(*
move_group, test_waypoints, test_step, test_jump,
false);
593 checkAndEmit(cartesian_plan_req_under_test.waypoints == test_waypoints &&
594 static_cast<int>(cartesian_plan_req_under_test.max_step) == test_step &&
595 static_cast<int>(cartesian_plan_req_under_test.jump_threshold) == test_jump &&
596 !cartesian_plan_req_under_test.avoid_collisions,
606 auto cartesian_plan_req = constructGetCartesianPathRequest(*
move_group, waypoints, 1, 1,
false);
607 cartesian_plan_req.start_state.multi_dof_joint_state.joint_names.clear();
608 cartesian_plan_req.start_state.multi_dof_joint_state.transforms.clear();
609 cartesian_plan_req.start_state.multi_dof_joint_state.twist.clear();
610 cartesian_plan_req.start_state.multi_dof_joint_state.wrench.clear();
611 cartesian_plan_req.path_constraints.joint_constraints.clear();
612 cartesian_plan_req.path_constraints.position_constraints.clear();
613 cartesian_plan_req.path_constraints.orientation_constraints.clear();
614 cartesian_plan_req.path_constraints.visibility_constraints.clear();
617 auto empty_frame_cartesian_plan_req = cartesian_plan_req;
618 empty_frame_cartesian_plan_req.header.frame_id =
"";
621 auto is_diff_cartesian_plan_req = cartesian_plan_req;
622 is_diff_cartesian_plan_req.start_state.is_diff =
true;
623 is_diff_cartesian_plan_req.start_state.joint_state.header.frame_id =
"";
624 is_diff_cartesian_plan_req.start_state.joint_state.name.clear();
625 is_diff_cartesian_plan_req.start_state.joint_state.position.clear();
626 is_diff_cartesian_plan_req.start_state.joint_state.velocity.clear();
627 is_diff_cartesian_plan_req.start_state.joint_state.effort.clear();
630 auto close_matching_cartesian_plan_req = cartesian_plan_req;
631 close_matching_cartesian_plan_req.start_state.joint_state.position.at(0) -= 0.05;
632 close_matching_cartesian_plan_req.start_state.joint_state.position.at(1) += 0.05;
633 close_matching_cartesian_plan_req.start_state.joint_state.position.at(2) -= 0.05;
634 close_matching_cartesian_plan_req.waypoints.at(0).position.x -= 0.05;
635 close_matching_cartesian_plan_req.waypoints.at(1).position.x += 0.05;
636 close_matching_cartesian_plan_req.waypoints.at(2).position.x -= 0.05;
639 auto different_cartesian_plan_req = cartesian_plan_req;
640 different_cartesian_plan_req.start_state.joint_state.position.at(0) -= 1.05;
641 different_cartesian_plan_req.start_state.joint_state.position.at(1) += 2.05;
642 different_cartesian_plan_req.start_state.joint_state.position.at(2) -= 3.05;
643 different_cartesian_plan_req.waypoints.at(0).position.x -= 1.05;
644 different_cartesian_plan_req.waypoints.at(1).position.x += 2.05;
645 different_cartesian_plan_req.waypoints.at(2).position.x -= 3.05;
653 auto empty_frame_traj = traj;
654 empty_frame_traj.joint_trajectory.header.frame_id =
"";
656 auto different_traj = traj;
657 different_traj.joint_trajectory.points.at(0).positions.at(0) = 999;
658 different_traj.joint_trajectory.points.at(0).positions.at(1) = 999;
659 different_traj.joint_trajectory.points.at(0).positions.at(2) = 999;
664 test_case =
"testCartesianTrajectories.empty";
666 checkAndEmit(cache->countCartesianTrajectories(
ROBOT_NAME) == 0, test_case,
"Trajectory cache initially empty");
669 cache->fetchAllMatchingCartesianTrajectories(*
move_group,
ROBOT_NAME, cartesian_plan_req, 0, 999, 999).empty(),
670 test_case,
"Fetch all trajectories on empty cache returns empty");
674 test_case,
"Fetch best trajectory on empty cache returns nullptr");
679 test_case =
"testCartesianTrajectories.insertTrajectory_empty_frame";
680 double execution_time = 999;
681 double planning_time = 999;
682 double fraction = 0.5;
685 execution_time, planning_time, fraction,
false),
686 test_case,
"Put empty frame trajectory, no prune_worse_trajectories, not ok");
693 test_case =
"testCartesianTrajectories.insertTrajectory_req_empty_frame";
694 execution_time = 1000;
695 planning_time = 1000;
698 execution_time, planning_time, fraction,
false),
699 test_case,
"Put empty frame req trajectory, no prune_worse_trajectories, ok");
704 test_case =
"testCartesianTrajectories.put_second";
705 execution_time = 999;
709 planning_time, fraction,
false),
710 test_case,
"Put second valid trajectory, no prune_worse_trajectories, ok");
717 test_case =
"testCartesianTrajectories.put_second.fetch_matching_no_tolerance";
719 auto fetched_trajectories =
720 cache->fetchAllMatchingCartesianTrajectories(*
move_group,
ROBOT_NAME, cartesian_plan_req, fraction, 0, 0);
723 cache->fetchBestMatchingCartesianTrajectory(*
move_group,
ROBOT_NAME, cartesian_plan_req, fraction, 0, 0);
725 checkAndEmit(fetched_trajectories.size() == 2, test_case,
"Fetch all returns two");
726 checkAndEmit(fetched_traj !=
nullptr, test_case,
"Fetch best trajectory is not nullptr");
728 checkAndEmit(*fetched_trajectories.at(0) == *fetched_traj, test_case,
"Fetched trajectory on both fetches match");
730 checkAndEmit(*fetched_traj == traj, test_case,
"Fetched trajectory matches original");
732 checkAndEmit(fetched_traj->lookupDouble(
"execution_time_s") == execution_time, test_case,
733 "Fetched trajectory has correct execution time");
735 checkAndEmit(fetched_traj->lookupDouble(
"planning_time_s") == planning_time, test_case,
736 "Fetched trajectory has correct planning time");
738 checkAndEmit(fetched_traj->lookupDouble(
"fraction") == fraction, test_case,
"Fetched trajectory has correct fraction");
744 test_case =
"testCartesianTrajectories.put_second.fetch_is_diff_no_tolerance";
746 fetched_trajectories =
747 cache->fetchAllMatchingCartesianTrajectories(*
move_group,
ROBOT_NAME, is_diff_cartesian_plan_req, fraction, 0, 0);
750 cache->fetchBestMatchingCartesianTrajectory(*
move_group,
ROBOT_NAME, is_diff_cartesian_plan_req, fraction, 0, 0);
752 checkAndEmit(fetched_trajectories.size() == 2, test_case,
"Fetch all returns two");
753 checkAndEmit(fetched_traj !=
nullptr, test_case,
"Fetch best trajectory is not nullptr");
755 checkAndEmit(*fetched_trajectories.at(0) == *fetched_traj, test_case,
"Fetched trajectory on both fetches match");
757 checkAndEmit(*fetched_traj == traj, test_case,
"Fetched trajectory matches original");
759 checkAndEmit(fetched_traj->lookupDouble(
"execution_time_s") == execution_time, test_case,
760 "Fetched trajectory has correct execution time");
762 checkAndEmit(fetched_traj->lookupDouble(
"planning_time_s") == planning_time, test_case,
763 "Fetched trajectory has correct planning time");
765 checkAndEmit(fetched_traj->lookupDouble(
"fraction") == fraction, test_case,
"Fetched trajectory has correct fraction");
770 test_case =
"testCartesianTrajectories.put_second.fetch_non_matching_out_of_tolerance";
772 fetched_trajectories = cache->fetchAllMatchingCartesianTrajectories(
775 fetched_traj = cache->fetchBestMatchingCartesianTrajectory(*
move_group,
ROBOT_NAME, close_matching_cartesian_plan_req,
778 checkAndEmit(fetched_trajectories.empty(), test_case,
"Fetch all returns empty");
779 checkAndEmit(fetched_traj ==
nullptr, test_case,
"Fetch best trajectory is nullptr");
784 test_case =
"testMotionTrajectories.put_second.fetch_non_matching_only_start_in_tolerance";
786 fetched_trajectories = cache->fetchAllMatchingCartesianTrajectories(
789 fetched_traj = cache->fetchBestMatchingCartesianTrajectory(*
move_group,
ROBOT_NAME, close_matching_cartesian_plan_req,
792 checkAndEmit(fetched_trajectories.empty(), test_case,
"Fetch all returns empty");
793 checkAndEmit(fetched_traj ==
nullptr, test_case,
"Fetch best trajectory is nullptr");
798 test_case =
"testMotionTrajectories.put_second.fetch_non_matching_only_goal_in_tolerance";
800 fetched_trajectories = cache->fetchAllMatchingCartesianTrajectories(
803 fetched_traj = cache->fetchBestMatchingCartesianTrajectory(*
move_group,
ROBOT_NAME, close_matching_cartesian_plan_req,
806 checkAndEmit(fetched_trajectories.empty(), test_case,
"Fetch all returns empty");
807 checkAndEmit(fetched_traj ==
nullptr, test_case,
"Fetch best trajectory is nullptr");
812 test_case =
"testCartesianTrajectories.put_second.fetch_non_matching_in_tolerance";
814 fetched_trajectories = cache->fetchAllMatchingCartesianTrajectories(
817 fetched_traj = cache->fetchBestMatchingCartesianTrajectory(*
move_group,
ROBOT_NAME, close_matching_cartesian_plan_req,
820 checkAndEmit(fetched_trajectories.size() == 2, test_case,
"Fetch all returns two");
821 checkAndEmit(fetched_traj !=
nullptr, test_case,
"Fetch best trajectory is not nullptr");
823 checkAndEmit(*fetched_trajectories.at(0) == *fetched_traj, test_case,
"Fetched trajectory on both fetches match");
825 checkAndEmit(*fetched_traj == traj, test_case,
"Fetched trajectory matches original");
827 checkAndEmit(fetched_traj->lookupDouble(
"execution_time_s") == execution_time, test_case,
828 "Fetched trajectory has correct execution time");
830 checkAndEmit(fetched_traj->lookupDouble(
"planning_time_s") == planning_time, test_case,
831 "Fetched trajectory has correct planning time");
833 checkAndEmit(fetched_traj->lookupDouble(
"fraction") == fraction, test_case,
"Fetched trajectory has correct fraction");
839 test_case =
"testCartesianTrajectories.put_second.fetch_higher_fraction";
841 fetched_trajectories =
842 cache->fetchAllMatchingCartesianTrajectories(*
move_group,
ROBOT_NAME, cartesian_plan_req, 1, 999, 999);
844 fetched_traj = cache->fetchBestMatchingCartesianTrajectory(*
move_group,
ROBOT_NAME, cartesian_plan_req, 1, 999, 999);
846 checkAndEmit(fetched_trajectories.empty(), test_case,
"Fetch all returns empty");
847 checkAndEmit(fetched_traj ==
nullptr, test_case,
"Fetch best trajectory is nullptr");
853 test_case =
"testCartesianTrajectories.put_second.fetch_lower_fraction";
855 fetched_trajectories =
856 cache->fetchAllMatchingCartesianTrajectories(*
move_group,
ROBOT_NAME, cartesian_plan_req, 0, 999, 999);
858 fetched_traj = cache->fetchBestMatchingCartesianTrajectory(*
move_group,
ROBOT_NAME, cartesian_plan_req, 0, 999, 999);
860 checkAndEmit(fetched_trajectories.size() == 2, test_case,
"Fetch all returns two");
861 checkAndEmit(fetched_traj !=
nullptr, test_case,
"Fetch best trajectory is not nullptr");
863 checkAndEmit(*fetched_trajectories.at(0) == *fetched_traj, test_case,
"Fetched trajectory on both fetches match");
865 checkAndEmit(*fetched_traj == traj, test_case,
"Fetched trajectory matches original");
867 checkAndEmit(fetched_traj->lookupDouble(
"execution_time_s") == execution_time, test_case,
868 "Fetched trajectory has correct execution time");
870 checkAndEmit(fetched_traj->lookupDouble(
"planning_time_s") == planning_time, test_case,
871 "Fetched trajectory has correct planning time");
873 checkAndEmit(fetched_traj->lookupDouble(
"fraction") == fraction, test_case,
"Fetched trajectory has correct fraction");
878 test_case =
"testCartesianTrajectories.put_worse";
879 double worse_execution_time = execution_time + 100;
882 worse_execution_time, planning_time, fraction,
false),
883 test_case,
"Put worse trajectory, no prune_worse_trajectories, not ok");
890 test_case =
"testCartesianTrajectories.put_better";
891 double better_execution_time = execution_time - 100;
894 better_execution_time, planning_time, fraction,
false),
895 test_case,
"Put better trajectory, no prune_worse_trajectories, ok");
897 checkAndEmit(cache->countCartesianTrajectories(
ROBOT_NAME) == 3, test_case,
"Three trajectories in cache");
902 test_case =
"testCartesianTrajectories.put_better.fetch_sorted";
904 fetched_trajectories =
905 cache->fetchAllMatchingCartesianTrajectories(*
move_group,
ROBOT_NAME, cartesian_plan_req, fraction, 0, 0);
908 cache->fetchBestMatchingCartesianTrajectory(*
move_group,
ROBOT_NAME, cartesian_plan_req, fraction, 0, 0);
910 checkAndEmit(fetched_trajectories.size() == 3, test_case,
"Fetch all returns three");
911 checkAndEmit(fetched_traj !=
nullptr, test_case,
"Fetch best trajectory is not nullptr");
913 checkAndEmit(*fetched_trajectories.at(0) == *fetched_traj, test_case,
"Fetched trajectory on both fetches match");
915 checkAndEmit(*fetched_traj == traj, test_case,
"Fetched trajectory matches original");
917 checkAndEmit(fetched_traj->lookupDouble(
"execution_time_s") == better_execution_time, test_case,
918 "Fetched trajectory has correct execution time");
920 checkAndEmit(fetched_traj->lookupDouble(
"planning_time_s") == planning_time, test_case,
921 "Fetched trajectory has correct planning time");
923 checkAndEmit(fetched_traj->lookupDouble(
"fraction") == fraction, test_case,
"Fetched trajectory has correct fraction");
925 checkAndEmit(fetched_trajectories.at(0)->lookupDouble(
"execution_time_s") == better_execution_time &&
926 fetched_trajectories.at(1)->lookupDouble(
"execution_time_s") == execution_time,
927 test_case,
"Fetched trajectories are sorted correctly");
932 test_case =
"testCartesianTrajectories.put_better_prune_worse_trajectories";
933 double even_better_execution_time = better_execution_time - 100;
936 even_better_execution_time, planning_time, fraction,
true),
937 test_case,
"Put better trajectory, prune_worse_trajectories, ok");
942 test_case =
"testCartesianTrajectories.put_better_prune_worse_trajectories.fetch";
944 fetched_trajectories =
945 cache->fetchAllMatchingCartesianTrajectories(*
move_group,
ROBOT_NAME, cartesian_plan_req, fraction, 0, 0);
948 cache->fetchBestMatchingCartesianTrajectory(*
move_group,
ROBOT_NAME, cartesian_plan_req, fraction, 0, 0);
950 checkAndEmit(fetched_trajectories.size() == 1, test_case,
"Fetch all returns one");
951 checkAndEmit(fetched_traj !=
nullptr, test_case,
"Fetch best trajectory is not nullptr");
953 checkAndEmit(*fetched_trajectories.at(0) == *fetched_traj, test_case,
"Fetched trajectory on both fetches match");
955 checkAndEmit(*fetched_traj == different_traj, test_case,
"Fetched trajectory matches original");
957 checkAndEmit(fetched_traj->lookupDouble(
"execution_time_s") == even_better_execution_time, test_case,
958 "Fetched trajectory has correct execution time");
960 checkAndEmit(fetched_traj->lookupDouble(
"planning_time_s") == planning_time, test_case,
961 "Fetched trajectory has correct planning time");
963 checkAndEmit(fetched_traj->lookupDouble(
"fraction") == fraction, test_case,
"Fetched trajectory has correct fraction");
968 test_case =
"testCartesianTrajectories.put_different_req";
971 better_execution_time, planning_time, fraction,
true),
972 test_case,
"Put different trajectory req, prune_worse_trajectories, ok");
979 test_case =
"testCartesianTrajectories.put_different_req.fetch";
982 different_cartesian_plan_req, fraction, 0, 0);
984 fetched_traj = cache->fetchBestMatchingCartesianTrajectory(*
move_group,
ROBOT_NAME, different_cartesian_plan_req,
987 checkAndEmit(fetched_trajectories.size() == 1, test_case,
"Fetch all returns one");
988 checkAndEmit(fetched_traj !=
nullptr, test_case,
"Fetch best trajectory is not nullptr");
990 checkAndEmit(*fetched_trajectories.at(0) == *fetched_traj, test_case,
"Fetched trajectory on both fetches match");
992 checkAndEmit(*fetched_traj == different_traj, test_case,
"Fetched trajectory matches original");
994 checkAndEmit(fetched_traj->lookupDouble(
"execution_time_s") == better_execution_time, test_case,
995 "Fetched trajectory has correct execution time");
997 checkAndEmit(fetched_traj->lookupDouble(
"planning_time_s") == planning_time, test_case,
998 "Fetched trajectory has correct planning time");
1000 checkAndEmit(fetched_traj->lookupDouble(
"fraction") == fraction, test_case,
"Fetched trajectory has correct fraction");
1005 test_case =
"testCartesianTrajectories.different_robot.empty";
1006 std::string different_robot_name =
"different_robot";
1008 checkAndEmit(cache->countCartesianTrajectories(different_robot_name) == 0, test_case,
"No trajectories in cache");
1013 test_case =
"testCartesianTrajectories.different_robot.put_first";
1014 checkAndEmit(cache->insertCartesianTrajectory(*
move_group, different_robot_name, different_cartesian_plan_req,
1015 different_traj, better_execution_time, planning_time, fraction,
true),
1016 test_case,
"Put different trajectory req, prune_worse_trajectories, ok");
1018 checkAndEmit(cache->countCartesianTrajectories(different_robot_name) == 1, test_case,
"One trajectory in cache");
1021 "Two trajectories in original robot's cache");
1024 different_cartesian_plan_req, fraction, 0, 0);
1026 checkAndEmit(fetched_trajectories.size() == 1, test_case,
"Fetch all on original still returns one");