5 #include <ram_msgs/AdditiveManufacturingTrajectory.h> 8 #include <ram_utils/AddEntryExitStrategies.h> 9 #include <ram_utils/EntryExitParameters.h> 19 ram_utils::EntryExitParameters::Response &)
25 entry_params.request.number_of_poses = req.number_of_poses;
30 ram_utils::EntryExitParameters::Response &)
36 exit_params.request.number_of_poses = req.number_of_poses;
41 std::vector<ram_msgs::AdditiveManufacturingPose> req_poses,
42 std::vector<ram_msgs::AdditiveManufacturingPose>&res_poses)
44 Eigen::Vector3d ref_vector(Eigen::Vector3d::Identity());
46 if (req_poses.size() != 1)
48 ref_vector.x() = req_poses[ref_pose_id].pose.position.x - req_poses[ref_pose_id + 1].pose.position.x;
49 ref_vector.y() = req_poses[ref_pose_id].pose.position.y - req_poses[ref_pose_id + 1].pose.position.y;
50 ref_vector.z() = req_poses[ref_pose_id].pose.position.z - req_poses[ref_pose_id + 1].pose.position.z;
57 ram_msgs::AdditiveManufacturingPose pose(req_poses[ref_pose_id]);
58 pose.params.laser_power = 0;
59 pose.params.feed_rate = 0;
60 pose.entry_pose =
true;
61 pose.polygon_start =
false;
62 pose.polygon_end =
false;
64 phi =
atan2(ref_vector.y(), ref_vector.x());
67 for (
unsigned j(
entry_params.request.number_of_poses); j > 0; --j)
71 ram_msgs::AdditiveManufacturingPose pose_tmp(pose);
73 pose_tmp.pose.position.x += rho *
sin(theta) *
cos(phi);
74 pose_tmp.pose.position.y += rho *
sin(theta) *
sin(phi);
75 pose_tmp.pose.position.z += rho * cos(theta);
78 res_poses.push_back(pose_tmp);
84 std::vector<ram_msgs::AdditiveManufacturingPose> req_poses,
85 std::vector<ram_msgs::AdditiveManufacturingPose>&res_poses)
87 Eigen::Vector3d ref_vector(Eigen::Vector3d::Identity());
91 if (req_poses.size() != 1 && ref_pose_id != 0)
93 ref_vector.x() = req_poses[ref_pose_id].pose.position.x - req_poses[ref_pose_id - 1].pose.position.x;
94 ref_vector.y() = req_poses[ref_pose_id].pose.position.y - req_poses[ref_pose_id - 1].pose.position.y;
95 ref_vector.z() = req_poses[ref_pose_id].pose.position.z - req_poses[ref_pose_id - 1].pose.position.z;
101 ram_msgs::AdditiveManufacturingPose pose(req_poses[ref_pose_id]);
102 pose.params.laser_power = 0;
103 pose.params.feed_rate = 0;
104 pose.exit_pose =
true;
105 pose.polygon_start =
false;
106 pose.polygon_end =
false;
108 phi =
atan2(ref_vector.y(), ref_vector.x());
111 for (
unsigned j(1); j <=
exit_params.request.number_of_poses; ++j)
115 ram_msgs::AdditiveManufacturingPose pose_tmp(pose);
117 pose_tmp.pose.position.x += rho *
sin(theta) *
cos(phi);
118 pose_tmp.pose.position.y += rho *
sin(theta) *
sin(phi);
119 pose_tmp.pose.position.z += rho * cos(theta);
122 res_poses.push_back(pose_tmp);
130 int pose_in_polygon = 0;
131 for (
unsigned i(0); i < poses.size(); ++i)
134 return pose_in_polygon;
136 if (poses[i].polygon_start && poses[i].polygon_end)
139 if (poses[i].polygon_start)
141 if (poses[i].polygon_end)
148 ram_utils::AddEntryExitStrategies::Response &res)
152 for (
unsigned i(0); i < req.poses.size(); ++i)
154 bool limit_between_polygons =
false;
155 bool add_entry_strategy =
false;
156 bool add_exit_strategy =
false;
159 if (req.poses[i].polygon_start && req.poses[i].polygon_end)
162 if (pose_in_polygon < 0 || pose_in_polygon > 1)
164 if (pose_in_polygon == 1)
166 limit_between_polygons =
true;
168 if (i != 0 && req.poses[i - 1].entry_pose ==
true)
170 if (i != (req.poses.size() - 1) && req.poses[i + 1].exit_pose ==
true)
177 if (req.poses[i].polygon_start)
181 add_entry_strategy =
true;
182 if (i != 0 && req.poses[i - 1].entry_pose ==
false)
183 add_entry_strategy =
true;
187 if (req.poses[i].polygon_end)
190 if (i == (req.poses.size() - 1))
191 add_exit_strategy =
true;
192 if (i != (req.poses.size() - 1) && req.poses[i + 1].exit_pose ==
false)
193 add_exit_strategy =
true;
197 if (limit_between_polygons)
199 res.poses.push_back(req.poses[i]);
200 res.poses.back().polygon_start =
false;
203 add_exit_strategy =
false;
206 add_entry_strategy =
false;
208 res.poses.push_back(req.poses[i]);
209 res.poses.back().polygon_end =
false;
214 if (add_entry_strategy)
217 add_entry_strategy =
false;
220 res.poses.push_back(req.poses[i]);
222 if (add_exit_strategy)
225 add_exit_strategy =
false;
237 ros::init(argc, argv,
"entry_exit_strategies");
static boost::uuids::uuid fromRandom(void)
std::unique_ptr< ros::NodeHandle > nh
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
ram_utils::EntryExitParameters exit_params
bool addEntryExitStrategiesCallback(ram_utils::AddEntryExitStrategies::Request &req, ram_utils::AddEntryExitStrategies::Response &res)
bool entryStrategy(unsigned ref_pose_id, std::vector< ram_msgs::AdditiveManufacturingPose > req_poses, std::vector< ram_msgs::AdditiveManufacturingPose > &res_poses)
int poseInPolygon(std::vector< ram_msgs::AdditiveManufacturingPose > poses, unsigned pose_id)
int main(int argc, char **argv)
bool exitParametersCallback(ram_utils::EntryExitParameters::Request &req, ram_utils::EntryExitParameters::Response &)
bool entryParametersCallback(ram_utils::EntryExitParameters::Request &req, ram_utils::EntryExitParameters::Response &)
INLINE Rall1d< T, V, S > atan2(const Rall1d< T, V, S > &y, const Rall1d< T, V, S > &x)
static uuid_msgs::UniqueID toMsg(boost::uuids::uuid const &uu)
INLINE Rall1d< T, V, S > cos(const Rall1d< T, V, S > &arg)
INLINE Rall1d< T, V, S > sin(const Rall1d< T, V, S > &arg)
bool exitStrategy(unsigned ref_pose_id, std::vector< ram_msgs::AdditiveManufacturingPose > req_poses, std::vector< ram_msgs::AdditiveManufacturingPose > &res_poses)
ROSCPP_DECL void waitForShutdown()
ram_utils::EntryExitParameters entry_params