38 #include <geometry_msgs/PoseArray.h>
39 #include <geometry_msgs/PoseStamped.h>
47 ConnectionBasedNodelet::onInit();
53 pub_ = advertise<geometry_msgs::PoseArray>(*pnh_,
"output", 1);
54 pub_best_ = advertise<geometry_msgs::PoseStamped>(*pnh_,
"output_best", 1);
55 pub_selected_ = advertise<geometry_msgs::PoseStamped>(*pnh_,
"output_selected", 1);
57 pub_preapproach_ = advertise<geometry_msgs::PoseArray>(*pnh_,
"output_preapproach", 1);
80 sync_ = boost::make_shared<message_filters::Synchronizer<SyncPolicy> >(100);
93 const jsk_recognition_msgs::BoundingBox::ConstPtr& box_msg)
96 std::vector<double> dimensions;
97 dimensions.push_back(
box_msg->dimensions.x);
98 dimensions.push_back(
box_msg->dimensions.y);
99 dimensions.push_back(
box_msg->dimensions.z);
100 size_t longest_index = 0;
101 for (
size_t i = 1;
i < 3;
i++) {
102 if (dimensions[
i] > dimensions[longest_index]) {
109 if (longest_index == 2) {
118 if (longest_index == 0) {
140 const sensor_msgs::PointCloud2::ConstPtr& cloud_msg,
141 const jsk_recognition_msgs::BoundingBox::ConstPtr& box_msg)
158 const sensor_msgs::PointCloud2::ConstPtr& cloud_msg,
159 const jsk_recognition_msgs::BoundingBox::ConstPtr& box_msg)
161 geometry_msgs::PoseArray pose_array;
162 geometry_msgs::PoseArray prepose_array;
163 pose_array.header =
box_msg->header;
164 prepose_array.header =
box_msg->header;
165 Eigen::Affine3d center;
167 Eigen::Vector3d
z = center.rotation().col(2);
168 Plane
p(Eigen::Vector3f(
z[0],
z[1],
z[2]), 0);
169 Eigen::Vector3d ray = center.translation().normalized();
170 Eigen::Vector3d ray_projected;
171 p.project(ray, ray_projected);
172 ray_projected.normalize();
174 Eigen::Matrix3d center_refined_mat;
175 center_refined_mat.col(0) = ray_projected;
176 center_refined_mat.col(2) =
z;
177 center_refined_mat.col(1) =
z.cross(ray_projected);
178 Eigen::Affine3d center_refined
179 = Eigen::Translation3d(center.translation()) * Eigen::Quaterniond(center_refined_mat);
181 const double angle_margin = 0.2;
182 const double start_angle =
M_PI / 2.0 + angle_margin;
183 const double end_angle =
M_PI +
M_PI / 2.0 - angle_margin;
186 Eigen::Vector3d offset_vec = Eigen::Vector3d(
cos(theta),
sin(theta), 0);
187 Eigen::Vector3d pre_approach_pos
189 Eigen::Matrix3d orientation;
190 Eigen::Vector3d x_vec
191 = (center_refined.translation() - pre_approach_pos).normalized();
192 Eigen::Vector3d y_vec =
z.cross(x_vec);
194 orientation.col(0) = x_vec;
195 orientation.col(1) = y_vec;
196 orientation.col(2) =
z;
198 Eigen::Affine3d pre_grasp_pose = Eigen::Translation3d(pre_approach_pos) * Eigen::Quaterniond(orientation);
199 Eigen::Affine3d grasp_pose = Eigen::Translation3d(center.translation()) * Eigen::Quaterniond(orientation);
200 geometry_msgs::Pose ros_prepose;
201 geometry_msgs::Pose ros_pose;
204 prepose_array.poses.push_back(ros_prepose);
205 pose_array.poses.push_back(ros_pose);
209 geometry_msgs::PoseStamped best;
210 best.header = pose_array.header;
211 best.pose = pose_array.poses[pose_array.poses.size() / 2];
214 output_buf.push_front(boost::make_tuple(pose_array, prepose_array));
218 const sensor_msgs::PointCloud2::ConstPtr& cloud_msg,
219 const jsk_recognition_msgs::BoundingBox::ConstPtr& box_msg,
222 geometry_msgs::PoseArray pose_array;
223 geometry_msgs::PoseArray prepose_array;
224 pose_array.header =
box_msg->header;
225 prepose_array.header =
box_msg->header;
227 Eigen::Affine3d center;
229 const double angle_margin = 0.2;
230 const double start_angle = angle_margin;
231 const double end_angle =
M_PI - angle_margin;
236 Eigen::Vector3d offset_vec;
238 offset_vec = Eigen::Vector3d(
sin(theta), 0,
cos(theta));
241 offset_vec = Eigen::Vector3d(0,
cos(theta),
sin(theta));
243 Eigen::Vector3d pre_approach_pos
246 Eigen::Matrix3d orientation;
248 Eigen::Vector3d x_vec
249 = (center.translation() - pre_approach_pos).normalized();
250 Eigen::Vector3d z_vec = center.rotation().col(1);
251 Eigen::Vector3d y_vec = z_vec.cross(x_vec);
252 orientation.col(0) = x_vec;
253 orientation.col(1) = y_vec;
254 orientation.col(2) = z_vec;
257 Eigen::Vector3d x_vec = (center.translation() - pre_approach_pos).normalized();
258 Eigen::Vector3d z_vec = center.rotation().col(0);
259 Eigen::Vector3d y_vec = z_vec.cross(x_vec);
260 orientation.col(0) = x_vec;
261 orientation.col(1) = y_vec;
262 orientation.col(2) = z_vec;
265 Eigen::Affine3d pre_grasp_pose = Eigen::Translation3d(pre_approach_pos) * Eigen::Quaterniond(orientation);
266 Eigen::Affine3d grasp_pose = Eigen::Translation3d(center.translation()) * Eigen::Quaterniond(orientation);
267 geometry_msgs::Pose ros_prepose, ros_pose;
270 pose_array.poses.push_back(ros_pose);
271 prepose_array.poses.push_back(ros_prepose);
275 geometry_msgs::PoseStamped best;
276 best.header = pose_array.header;
277 best.pose = pose_array.poses[pose_array.poses.size() / 2];
280 output_buf.push_front(boost::make_tuple(pose_array, prepose_array));
284 boost::circular_buffer<boost::tuple<geometry_msgs::PoseArray, geometry_msgs::PoseArray> >::iterator it =
output_buf.begin();
286 geometry_msgs::PoseArray pose_array = it->get<0>();
287 geometry_msgs::PoseArray prepose_array = it->get<1>();
289 if(pose_array.header.stamp ==
index->header.stamp){
290 geometry_msgs::PoseStamped ps;
291 ps.header = pose_array.header;
292 ps.pose = pose_array.poses[
index->data];
295 ps.header = prepose_array.header;
296 ps.pose = prepose_array.poses[
index->data];