9 #include <choreo_msgs/ElementCandidatePoses.h> 10 #include <choreo_msgs/ModelInputParameters.h> 11 #include <choreo_msgs/TaskSequenceInputParameters.h> 12 #include <choreo_msgs/CollisionObjectList.h> 15 #include <moveit_msgs/ApplyPlanningScene.h> 25 double dist(
const Eigen::Vector3d& from,
const Eigen::Vector3d& to)
27 return (from - to).norm();
30 void createShrinkedEndPoint(Eigen::Vector3d& st_pt, Eigen::Vector3d& end_pt,
33 Eigen::Vector3d translation_vec = end_pt - st_pt;
34 translation_vec.normalize();
36 if(2 * shrink_length > (st_pt - end_pt).norm())
39 shrink_length = 0.2 * (st_pt - end_pt).norm();
42 st_pt = st_pt + shrink_length * translation_vec;
43 end_pt = end_pt - shrink_length * translation_vec;
46 geometry_msgs::Pose computeCylinderPose(
const Eigen::Vector3d& st_pt,
const Eigen::Vector3d& end_pt)
48 geometry_msgs::Pose cylinder_pose;
51 Eigen::Vector3d
axis = end_pt - st_pt;
53 Eigen::Vector3d z_vec(0.0, 0.0, 1.0);
54 const Eigen::Vector3d& x_vec = axis.cross(z_vec);
64 double theta = axis.dot(z_vec);
65 double angle = -1.0 * acos(theta);
83 moveit_msgs::CollisionObject convertWFEdgeToCollisionObject(
84 int edge_id,
const Eigen::Vector3d st_pt,
const Eigen::Vector3d end_pt,
double element_diameter,
85 const std::string world_frame)
87 moveit_msgs::CollisionObject collision_cylinder;
90 collision_cylinder.id = cylinder_id;
91 collision_cylinder.header.frame_id = world_frame;
92 collision_cylinder.operation = moveit_msgs::CollisionObject::ADD;
94 shape_msgs::SolidPrimitive cylinder_solid;
95 cylinder_solid.type = shape_msgs::SolidPrimitive::CYLINDER;
96 cylinder_solid.dimensions.resize(2);
98 cylinder_solid.dimensions[0] =
dist(st_pt, end_pt);
100 cylinder_solid.dimensions[1] = element_diameter;
101 collision_cylinder.primitives.push_back(cylinder_solid);
102 collision_cylinder.primitive_poses.push_back(computeCylinderPose(st_pt, end_pt));
104 return collision_cylinder;
107 void convertWireFrameToMsg(
108 const choreo_msgs::ModelInputParameters& model_params,
109 WireFrame& wire_frame, std::vector<choreo_msgs::ElementCandidatePoses>& wf_msgs,
111 const std::string world_frame)
116 switch (model_params.unit_type)
118 case choreo_msgs::ModelInputParameters::MILLIMETER:
123 case choreo_msgs::ModelInputParameters::CENTIMETER:
128 case choreo_msgs::ModelInputParameters::INCH:
133 case choreo_msgs::ModelInputParameters::FOOT:
140 ROS_ERROR(
"Unrecognized Unit type in Model Input Parameters!");
148 Eigen::Vector3d transf_vec = Eigen::Vector3d(model_params.ref_pt_x * unit_scale - base_pt.x() * 0.001,
149 model_params.ref_pt_y * unit_scale - base_pt.y() * 0.001,
150 model_params.ref_pt_z * unit_scale - base_pt.z() * 0.001);
160 choreo_msgs::ElementCandidatePoses element_msg;
161 element_msg.element_id = e->
ID();
168 eigen_st_pt = eigen_st_pt * 0.001 + transf_vec;
173 eigen_end_pt = eigen_end_pt * 0.001 + transf_vec;
179 element_msg.element_diameter = model_params.element_diameter * unit_scale;
181 element_msg.layer_id = e->
Layer();
184 Eigen::Vector3d shrinked_st_pt = eigen_st_pt;
185 Eigen::Vector3d shrinked_end_pt = eigen_end_pt;
186 createShrinkedEndPoint(shrinked_st_pt, shrinked_end_pt, model_params.shrink_length * unit_scale);
188 element_msg.both_side_shrinked_collision_object = convertWFEdgeToCollisionObject(
189 e->
ID(), shrinked_st_pt, shrinked_end_pt, element_msg.element_diameter, world_frame);
191 element_msg.st_shrinked_collision_object = convertWFEdgeToCollisionObject(
192 e->
ID(), shrinked_st_pt, eigen_end_pt, element_msg.element_diameter, world_frame );
194 element_msg.end_shrinked_collision_object = convertWFEdgeToCollisionObject(
195 e->
ID(), eigen_st_pt, shrinked_end_pt, element_msg.element_diameter, world_frame);
197 element_msg.full_collision_object = convertWFEdgeToCollisionObject(
198 e->
ID(), eigen_st_pt, eigen_end_pt, element_msg.element_diameter, world_frame);
202 wf_msgs[e->
ID()] = element_msg;
203 wf_msgs[e->
ppair_->
ID()] = element_msg;
209 moveit_msgs::CollisionObject createPrintTable(
const Eigen::Vector3d& ref_pt,
const double unit_scale,
const std::string world_frame)
215 moveit_msgs::CollisionObject collision_env_obj;
216 std::string env_obj_id =
"env_obj_table";
224 Eigen::Affine3d rtn = Eigen::Translation3d(ref_pt[0] * unit_scale,
225 ref_pt[1] * unit_scale,
226 ref_pt[2] * unit_scale - dz/2)
227 * Eigen::AngleAxisd(0, Eigen::Vector3d::UnitX())
228 * Eigen::AngleAxisd(0, Eigen::Vector3d::UnitY())
229 * Eigen::AngleAxisd(0, Eigen::Vector3d::UnitZ());
230 geometry_msgs::Pose pose;
233 collision_env_obj.id = env_obj_id;
234 collision_env_obj.header.frame_id = world_frame;
235 collision_env_obj.operation = moveit_msgs::CollisionObject::ADD;
237 shape_msgs::SolidPrimitive env_obj_solid;
238 env_obj_solid.type = shape_msgs::SolidPrimitive::BOX;
239 env_obj_solid.dimensions.resize(3);
240 env_obj_solid.dimensions[0] = dx;
241 env_obj_solid.dimensions[1] = dy;
242 env_obj_solid.dimensions[2] = dz;
243 collision_env_obj.primitives.push_back(env_obj_solid);
244 collision_env_obj.primitive_poses.push_back(pose);
246 return collision_env_obj;
249 bool addCollisionObject(
const moveit_msgs::CollisionObject& c_obj)
261 ROS_ERROR_STREAM(
"[ts planning] cannot connect with planning scene diff server...");
264 moveit_msgs::ApplyPlanningScene srv;
266 moveit_msgs::PlanningScene planning_scene_msg;
267 planning_scene_msg.world.collision_objects.push_back(c_obj);
268 planning_scene_msg.is_diff =
true;
269 srv.request.scene = planning_scene_msg;
271 if(planning_scene_diff_client.
call(srv))
278 ROS_ERROR_STREAM(
"[ts planning] Failed to publish planning scene diff srv!");
286 const std::string& hotend_group,
const std::string& hotend_tcp,
const std::string& hotend_base,
287 const std::string& robot_model_plugin)
288 : plugin_loader_(
"descartes_core",
"descartes_core::RobotModel"),
289 hotend_group_name_(hotend_group)
309 throw std::runtime_error(std::string(
"[seq planner] Could not load: ") + robot_model_plugin);
312 if (!
hotend_model_->initialize(
"robot_description", hotend_group, hotend_base, hotend_tcp))
314 throw std::runtime_error(
"[seq planner] Unable to initialize printing robot model");
323 throw std::runtime_error(
"[seq planner] Could not load moveit robot model");
411 std::vector<int> target_ids;
412 for(
int i = 37; i <= 39; i++)
414 target_ids.push_back(i);
417 if (!ptr_seqanalyzer_->SeqPrint())
430 ROS_WARN_STREAM(
"[ts planning] wireframe, fiber_print parm or output_path not initiated." 431 <<
"ts planning failed.");
437 std::vector<choreo_msgs::WireFrameCollisionObject>& collision_objs)
458 return ptr_seqanalyzer_->ConstructCollisionObjsInQueue(print_queue_edge_ids, collision_objs);
462 ROS_WARN_STREAM(
"[ts planning] wireframe, fiber_print parm or output_path not initiated." 463 <<
"constructing collision objs in ts planning failed.");
470 bool success =
false;
495 ROS_INFO_STREAM(
"[ts planner] Maximal node deforamtion (mm): " << D.maxCoeff()
500 ROS_ERROR(
"[ts planner] stiffness computation fails.");
508 ROS_ERROR(
"[ts planner] Get Deformation: init fails.");
513 ROS_ERROR(
"[ts planner] whole model deformation fails.");
518 choreo_msgs::TaskSequencePlanning::Request& req,
519 choreo_msgs::TaskSequencePlanning::Response&
res)
523 case choreo_msgs::TaskSequencePlanning::Request::READ_WIREFRAME:
525 std::string file_path = req.model_params.file_name;
529 std::vector<char> fp(file_path.begin(), file_path.end());
544 Eigen::Vector3d ref_pt(req.model_params.ref_pt_x, req.model_params.ref_pt_y, req.model_params.ref_pt_z);
549 moveit_msgs::CollisionObject
table = createPrintTable(ref_pt, unit_scale,
world_frame_);
550 addCollisionObject(table);
559 case choreo_msgs::TaskSequencePlanning::Request::TASK_SEQUENCE_SEARCHING:
574 const char* json_output_path = req.task_sequence_params.file_path.c_str();
598 case choreo_msgs::TaskSequencePlanning::Request::REQUEST_COLLISION_OBJS:
614 std::vector<int> wireframe_ids;
616 for(
const auto& element : req.element_array)
618 wireframe_ids.push_back(element.wireframe_id);
631 ROS_ERROR_STREAM(
"[ts planning] unknown task sequence planning request action.");
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
bool CalculateD(VX &D, VX *ptr_x=NULL, bool cond_num=false, int file_id=0, string file_name="")
SeqAnalyzer * ptr_seqanalyzer_
static const std::string COLLISION_OBJ_PREFIX
void poseEigenToMsg(const Eigen::Affine3d &e, geometry_msgs::Pose &m)
GLenum GLenum GLsizei void * table
FiberPrintPlugIn(const std::string &world_frame, const std::string &hotend_group, const std::string &hotend_tcp, const std::string &hotend_base, const std::string &robot_model_plugin)
bool call(MReq &req, MRes &res)
static const std::string APPLY_PLANNING_SCENE_SERVICE
void vectorEigenToTF(const Eigen::Vector3d &e, tf::Vector3 &t)
StiffnessSolver stiff_solver_
moveit::core::RobotModelConstPtr moveit_model_
static const T dist(const Vec< D, T > &v1, const Vec< D, T > &v2)
void LoadFromPWF(const char *path)
Vec3f GetBaseCenterPos() const
QuadricCollision * ptr_collision_
pluginlib::ClassLoader< descartes_core::RobotModel > plugin_loader_
descartes_core::RobotModelPtr hotend_model_
Stiffness * ptr_stiffness_
bool handleTaskSequencePlanning(choreo_msgs::TaskSequencePlanning::Request &req, choreo_msgs::TaskSequencePlanning::Response &res)
bool waitForExistence(ros::Duration timeout=ros::Duration(-1))
FiberPrintPARM * ptr_parm_
std::vector< choreo_msgs::ElementCandidatePoses > frame_msgs_
static void quaternionTFToMsg(const Quaternion &bt, geometry_msgs::Quaternion &msg)
DualGraph * ptr_dualgraph_
#define ROS_WARN_STREAM(args)
bool ConstructCollisionObjects(const std::vector< int > &print_queue_edge_ids, std::vector< choreo_msgs::WireFrameCollisionObject > &collision_objs)
void pointEigenToMsg(const Eigen::Vector3d &e, geometry_msgs::Point &m)
#define ROS_INFO_STREAM(args)
ProcAnalyzer * ptr_procanalyzer_
const robot_model::RobotModelPtr & getModel() const
#define ROS_ERROR_STREAM(args)
std::string hotend_group_name_
int SizeOfEdgeList() const