24 #include <descartes_planner/ladder_graph_dag_search_lazy_collision.h> 25 #include <descartes_planner/ladder_graph_dag_search.h> 26 #include <descartes_planner/dense_planner.h> 27 #include <descartes_core/trajectory_pt.h> 32 #include <descartes_parser/descartes_parser.h> 37 #include <descartes_msgs/LadderGraphList.h> 39 #include <trajectory_msgs/JointTrajectoryPoint.h> 43 bool saveLadderGraph(
const std::string &filename,
const descartes_msgs::LadderGraphList &graph_list_msg)
58 std::vector <descartes_planner::ConstrainedSegment> &segs,
59 const double clt_rrt_unit_process_timeout,
60 const double clt_rrt_timeout,
61 const std::vector <planning_scene::PlanningScenePtr> &planning_scenes_approach,
62 const std::vector <planning_scene::PlanningScenePtr> &planning_scenes_depart,
63 const std::vector <choreo_msgs::ElementCandidatePoses> &task_seq,
64 std::vector <choreo_msgs::UnitProcessPlan> &plans,
65 const std::string &saved_graph_file_name,
69 assert(segs.size() == task_seq.size());
75 std::vector <descartes_planner::LadderGraph> graphs;
76 std::vector<int> graph_indices;
77 descartes_msgs::LadderGraphList graph_list_msg;
87 graphs = descartes_parser::convertToLadderGraphList(graph_list_msg);
91 ROS_WARN_STREAM(
"[CLT RRT*] read saved ladder graph list fails. Reconstruct graph.");
93 use_saved_graph =
false;
99 if (!use_saved_graph || segs.size() > graphs.size())
102 clt_cost = CLT_RRT.
solve(*model, clt_rrt_unit_process_timeout, clt_rrt_timeout);
109 graph_list_msg = descartes_parser::convertToLadderGraphListMsg(graphs);
110 saveLadderGraph(saved_graph_file_name, graph_list_msg);
115 std::vector <descartes_planner::LadderGraph> chosen_graphs(graphs.begin(), graphs.begin() + segs.size());
118 graph_indices, use_saved_graph);
122 ROS_INFO_STREAM(
"[CLT RRT*] CLT RRT* Search took " << (clt_end - clt_start).toSec()
127 auto it = ros_traj.points.begin();
128 for (
size_t i = 0; i < task_seq.size(); i++)
130 choreo_msgs::SubProcess sub_process;
132 sub_process.unit_process_id = i;
133 sub_process.process_type = choreo_msgs::SubProcess::PROCESS;
134 sub_process.main_data_type = choreo_msgs::SubProcess::CART;
136 switch (task_seq[i].type)
138 case choreo_msgs::ElementCandidatePoses::SUPPORT:
140 sub_process.element_process_type = choreo_msgs::SubProcess::SUPPORT;
143 case choreo_msgs::ElementCandidatePoses::CREATE:
145 sub_process.element_process_type = choreo_msgs::SubProcess::CREATE;
148 case choreo_msgs::ElementCandidatePoses::CONNECT:
150 sub_process.element_process_type = choreo_msgs::SubProcess::CONNECT;
155 sub_process.element_process_type = choreo_msgs::SubProcess::NONE;
156 ROS_WARN_STREAM(
"[Process Planning] printing process #" << i <<
" have no element process type!");
160 sub_process.joint_array.points = std::vector<trajectory_msgs::JointTrajectoryPoint>(it, it + graph_indices[i]);
162 plans[i].sub_process_array.push_back(sub_process);
164 it = it + graph_indices[i];
170 const choreo_msgs::AssemblySequencePickNPlace& as_pnp,
171 const double clt_rrt_unit_process_timeout,
172 const double clt_rrt_timeout,
173 const double& linear_vel,
174 const double& linear_disc,
175 const std::vector<std::vector<planning_scene::PlanningScenePtr>>& planning_scenes_subprocess,
176 std::vector <choreo_msgs::UnitProcessPlan>& plans,
177 const std::string &saved_graph_file_name,
178 bool use_saved_graph)
185 std::vector <descartes_planner::LadderGraph> graphs;
186 std::vector<std::vector<int>> graph_indices;
187 std::vector<int> flat_graph_ids;
189 descartes_msgs::LadderGraphList graph_list_msg;
199 graphs = descartes_parser::convertToLadderGraphList(graph_list_msg, graph_indices);
203 ROS_WARN_STREAM(
"[CLT RRT*] read saved ladder graph list fails. Reconstruct graph.");
205 use_saved_graph =
false;
210 const std::vector<descartes_planner::ConstrainedSegmentPickNPlace> segs =
219 if (!use_saved_graph || segs.size() > graphs.size())
223 clt_cost = CLT_RRT.
solvePickNPlace(*model, clt_rrt_unit_process_timeout, clt_rrt_timeout);
232 assert(graph_indices.size() == graphs.size());
233 graph_list_msg = descartes_parser::convertToLadderGraphListMsg(graphs, graph_indices);
234 saveLadderGraph(saved_graph_file_name, graph_list_msg);
240 std::vector <descartes_planner::LadderGraph> chosen_graphs(graphs.begin(), graphs.begin() + segs.size());
250 assert(graph_indices.size() == flat_graph_ids.size());
251 for(
int k=0; k<flat_graph_ids.size(); k++)
254 for(
auto& chuck_num : graph_indices[k])
258 assert(sum == flat_graph_ids[k]);
263 ROS_INFO_STREAM(
"[CLT RRT*] CLT RRT* Search took " << (clt_end - clt_start).toSec()
268 auto it = ros_traj.points.begin();
269 for (
size_t i = 0; i < segs.size(); i++)
271 choreo_msgs::SubProcess sub_process;
273 sub_process.unit_process_id = i;
274 sub_process.process_type = choreo_msgs::SubProcess::RETRACTION;
275 sub_process.main_data_type = choreo_msgs::SubProcess::CART;
278 assert(graph_indices[i].
size() == 4);
280 for(
int k = 0; k < 4; k++)
284 sub_process.element_process_type = choreo_msgs::SubProcess::APPROACH;
288 sub_process.element_process_type = choreo_msgs::SubProcess::DEPART;
293 sub_process.comment =
"pick";
297 sub_process.comment =
"place";
300 sub_process.joint_array.points = std::vector<trajectory_msgs::JointTrajectoryPoint>(it, it + graph_indices[i][k]);
301 plans[i].sub_process_array.push_back(sub_process);
303 it = it + graph_indices[i][k];
bool fromFile(const std::string &path, T &msg)
void CLTRRTforProcessROSTraj(descartes_core::RobotModelPtr model, std::vector< descartes_planner::ConstrainedSegment > &segs, const double clt_rrt_unit_process_timeout, const double clt_rrt_timeout, const std::vector< planning_scene::PlanningScenePtr > &planning_scenes_approach, const std::vector< planning_scene::PlanningScenePtr > &planning_scenes_depart, const std::vector< choreo_msgs::ElementCandidatePoses > &task_seq, std::vector< choreo_msgs::UnitProcessPlan > &plans, const std::string &saved_graph_file_name, bool use_saved_graph)
std::size_t size(custom_string const &s)
trajectory_msgs::JointTrajectory toROSTrajectory(const DescartesTraj &solution, const descartes_core::RobotModel &model)
double solve(descartes_core::RobotModel &model, double clt_rrt_unit_process_timeout, double clt_rrt_timeout)
bool toFile(const std::string &path, const T &msg)
std::vector< descartes_planner::ConstrainedSegmentPickNPlace > toDescartesConstrainedPath(const choreo_msgs::AssemblySequencePickNPlace &as_pnp, const std::vector< std::vector< planning_scene::PlanningScenePtr >> &planning_scene_subprocess, const double &linear_vel, const double &linear_disc)
double solvePickNPlace(descartes_core::RobotModel &model, double clt_rrt_unit_process_timeout, double clt_rrt_timeout)
#define ROS_WARN_STREAM(args)
std::vector< descartes_core::TrajectoryPtPtr > DescartesTraj
#define ROS_INFO_STREAM(args)
void extractSolution(descartes_core::RobotModel &model, std::vector< descartes_core::TrajectoryPtPtr > &sol, std::vector< descartes_planner::LadderGraph > &graphs, std::vector< int > &graph_indices, const bool use_saved_graph)
std::vector< std::vector< int > > getGraphPartitionIds() const