00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include <frame_marker.h>
00033 #include <moveit/robot_interaction/interactive_marker_helpers.h>
00034
00035 #include <interactive_markers/tools.h>
00036
00037 #include <eigen_conversions/eigen_msg.h>
00038
00039 #include <boost/math/constants/constants.hpp>
00040
00041 namespace benchmark_tool
00042 {
00043
00044 const float GripperMarker::GOAL_NOT_TESTED_COLOR[4] = { 0.75, 0.75, 0.75, 1.0};
00045 const float GripperMarker::GOAL_PROCESSING_COLOR[4] = { 0.9, 0.9, 0.9, 1.0};
00046 const float GripperMarker::GOAL_NOT_REACHABLE_COLOR[4] = { 1.0, 0.0, 0.0, 1.0};
00047 const float GripperMarker::GOAL_REACHABLE_COLOR[4] = { 0.0, 1.0, 0.0, 1.0};
00048 const float GripperMarker::GOAL_COLLISION_COLOR[4] = { 1.0, 1.0, 0.0, 1.0};
00049
00050 FrameMarker::FrameMarker(Ogre::SceneNode *parent_node, rviz::DisplayContext *context, const std::string &name,
00051 const std::string &frame_id, const geometry_msgs::Pose &pose, double scale, const std_msgs::ColorRGBA &color,
00052 bool is_selected, bool visible_x, bool visible_y, bool visible_z):
00053 parent_node_(parent_node),
00054 context_(context),
00055 color_(color),
00056 selected_(is_selected),
00057 visible_x_(visible_x),
00058 visible_y_(visible_y),
00059 visible_z_(visible_z),
00060 receiver_(NULL),
00061 receiver_method_(NULL)
00062 {
00063 buildFrom(name, frame_id, pose, scale, color);
00064 }
00065
00066 FrameMarker::FrameMarker(Ogre::SceneNode *parent_node, rviz::DisplayContext *context, const std::string &name,
00067 const std::string &frame_id, const geometry_msgs::Pose &pose, double scale, const float color[4],
00068 bool is_selected, bool visible_x, bool visible_y, bool visible_z):
00069 parent_node_(parent_node),
00070 context_(context),
00071 selected_(is_selected),
00072 visible_x_(visible_x),
00073 visible_y_(visible_y),
00074 visible_z_(visible_z),
00075 receiver_(NULL),
00076 receiver_method_(NULL)
00077 {
00078 color_.r = color[0];
00079 color_.g = color[1];
00080 color_.b = color[2];
00081 color_.a = color[3];
00082 buildFrom(name, frame_id, pose, scale, color_);
00083 }
00084
00085 void FrameMarker::hide(void)
00086 {
00087 if ( isVisible() )
00088 {
00089 position_ = imarker->getPosition();
00090 orientation_ = imarker->getOrientation();
00091 imarker.reset();
00092 }
00093 }
00094
00095 void FrameMarker::show(Ogre::SceneNode *scene_node, rviz::DisplayContext *context)
00096 {
00097 if ( ! isVisible() )
00098 {
00099 rebuild();
00100 }
00101 }
00102
00103 void FrameMarker::showDescription(const std::string &description)
00104 {
00105 imarker_msg.description = description;
00106
00107 if (isVisible())
00108 {
00109 Ogre::Vector3 position = imarker->getPosition();
00110 Ogre::Quaternion orientation = imarker->getOrientation();
00111 updateMarker();
00112 imarker->setPose(position, orientation, "");
00113 }
00114 imarker->setShowDescription(true);
00115 }
00116
00117 void FrameMarker::hideDescription()
00118 {
00119 imarker->setShowDescription(false);
00120 }
00121
00122 void FrameMarker::getPosition(geometry_msgs::Point &position)
00123 {
00124 if (imarker)
00125 {
00126 position.x = imarker->getPosition().x;
00127 position.y = imarker->getPosition().y;
00128 position.z = imarker->getPosition().z;
00129 }
00130 else
00131 {
00132 position.x = position_.x;
00133 position.y = position_.y;
00134 position.z = position_.z;
00135 }
00136 }
00137
00138 void FrameMarker::getOrientation(geometry_msgs::Quaternion &orientation)
00139 {
00140 if (imarker)
00141 {
00142 orientation.x = imarker->getOrientation().x;
00143 orientation.y = imarker->getOrientation().y;
00144 orientation.z = imarker->getOrientation().z;
00145 orientation.w = imarker->getOrientation().w;
00146 }
00147 else
00148 {
00149 orientation.x = orientation_.x;
00150 orientation.y = orientation_.y;
00151 orientation.z = orientation_.z;
00152 orientation.w = orientation_.w;
00153 }
00154 }
00155
00156 void FrameMarker::getPose(Eigen::Affine3d &pose)
00157 {
00158 pose = Eigen::Affine3d(Eigen::Quaterniond(imarker->getOrientation().w, imarker->getOrientation().x,
00159 imarker->getOrientation().y, imarker->getOrientation().z));
00160 pose.translation() = Eigen::Vector3d(imarker->getPosition().x,
00161 imarker->getPosition().y,
00162 imarker->getPosition().z);
00163 }
00164
00165 void FrameMarker::setPose(Eigen::Affine3d &pose)
00166 {
00167 Eigen::Quaterniond q(pose.rotation());
00168 imarker->setPose(Ogre::Vector3(pose.translation().x(), pose.translation().y(), pose.translation().z()),
00169 Ogre::Quaternion(q.w(), q.x(), q.y(), q.z()), "");
00170 }
00171
00172 void FrameMarker::setColor(float r, float g, float b, float a)
00173 {
00174
00175 color_.r = r;
00176 color_.g = g;
00177 color_.b = b;
00178 color_.a = a;
00179
00180 for (unsigned int c = 0; c < imarker_msg.controls.size(); ++c)
00181 {
00182 for (unsigned int m = 0; m < imarker_msg.controls[c].markers.size(); ++m)
00183 {
00184 if (imarker_msg.controls[c].markers[m].type == visualization_msgs::Marker::MESH_RESOURCE ||
00185 imarker_msg.controls[c].markers[m].type == visualization_msgs::Marker::SPHERE)
00186 {
00187 imarker_msg.controls[c].markers[m].color.r = r;
00188 imarker_msg.controls[c].markers[m].color.g = g;
00189 imarker_msg.controls[c].markers[m].color.b = b;
00190 imarker_msg.controls[c].markers[m].color.a = a;
00191 }
00192 }
00193 }
00194
00195 if (isVisible())
00196 {
00197 Ogre::Vector3 position = imarker->getPosition();
00198 Ogre::Quaternion orientation = imarker->getOrientation();
00199 updateMarker();
00200 imarker->setPose(position, orientation, "");
00201 }
00202 }
00203
00204 void FrameMarker::select(void)
00205 {
00206 selected_ = true;
00207 rebuild();
00208 }
00209
00210 void FrameMarker::unselect(void)
00211 {
00212 selected_ = false;
00213 rebuild();
00214 }
00215
00216 void FrameMarker::rebuild()
00217 {
00218 geometry_msgs::Pose pose;
00219 getPosition(pose.position);
00220 getOrientation(pose.orientation);
00221 buildFrom(imarker_msg.name, imarker_msg.header.frame_id, pose, imarker_msg.scale, color_);
00222 }
00223
00224 void FrameMarker::buildFrom(const std::string &name, const std::string &frame_id, const geometry_msgs::Pose &pose, double scale, const std_msgs::ColorRGBA &color)
00225 {
00226 color_ = color;
00227
00228 visualization_msgs::InteractiveMarker int_marker;
00229 if (isSelected())
00230 {
00231 geometry_msgs::PoseStamped pose_stamped;
00232 pose_stamped.header.frame_id = frame_id;
00233 pose_stamped.pose = pose;
00234 int_marker = robot_interaction::make6DOFMarker(name, pose_stamped, scale);
00235 }
00236 else
00237 {
00238 int_marker.scale = scale;
00239 int_marker.name = name;
00240 int_marker.pose = pose;
00241 }
00242 int_marker.header.frame_id = frame_id;
00243 int_marker.header.stamp = ros::Time::now();
00244
00245 int_marker.menu_entries = menu_entries_;
00246
00247 visualization_msgs::InteractiveMarkerControl m_control;
00248 m_control.always_visible = true;
00249 m_control.interaction_mode = m_control.BUTTON;
00250
00251
00252 visualization_msgs::Marker m;
00253 m.type = visualization_msgs::Marker::SPHERE;
00254 m.scale.x = 0.1 * scale;
00255 m.scale.y = 0.1 * scale;
00256 m.scale.z = 0.1 * scale;
00257 m.ns = "goal_pose_marker";
00258 m.action = visualization_msgs::Marker::ADD;
00259 m.color = color;
00260 m_control.markers.push_back(m);
00261
00262 m.type = visualization_msgs::Marker::ARROW;
00263 m.scale.x = 0.3 * scale;
00264 m.scale.y = 0.1 * m.scale.x;
00265 m.scale.z = 0.1 * m.scale.x;
00266 m.ns = "goal_pose_marker";
00267 m.action = visualization_msgs::Marker::ADD;
00268
00269
00270 if (visible_x_)
00271 {
00272 m.color.r = 1.0f;
00273 m.color.g = 0.0f;
00274 m.color.b = 0.0f;
00275 m.color.a = 1.0f;
00276 m_control.markers.push_back(m);
00277 }
00278
00279
00280 if (visible_y_)
00281 {
00282 tf::Quaternion imq;
00283 imq = tf::createQuaternionFromRPY(0, 0, boost::math::constants::pi<double>() / 2.0);
00284 tf::quaternionTFToMsg(imq, m.pose.orientation);
00285 m.color.r = 0.0f;
00286 m.color.g = 1.0f;
00287 m.color.b = 0.0f;
00288 m.color.a = 1.0f;
00289 m_control.markers.push_back(m);
00290 }
00291
00292
00293 if (visible_z_) {
00294 tf::Quaternion imq;
00295 imq = tf::createQuaternionFromRPY(0, -boost::math::constants::pi<double>() / 2.0, 0);
00296 tf::quaternionTFToMsg(imq, m.pose.orientation);
00297 m.color.r = 0.0f;
00298 m.color.g = 0.0f;
00299 m.color.b = 1.0f;
00300 m.color.a = 1.0f;
00301 m_control.markers.push_back(m);
00302 }
00303 int_marker.controls.push_back(m_control);
00304
00305 imarker.reset(new rviz::InteractiveMarker(parent_node_, context_ ));
00306 interactive_markers::autoComplete(int_marker);
00307 imarker->processMessage(int_marker);
00308 imarker->setShowVisualAids(true);
00309 imarker->setShowAxes(false);
00310 imarker->setShowDescription(false);
00311
00312
00313 if (receiver_ && receiver_method_)
00314 {
00315 connect(receiver_, receiver_method_);
00316 }
00317
00318 imarker_msg = int_marker;
00319 }
00320
00321
00322 GripperMarker::GripperMarker(const robot_state::RobotState& robot_state, Ogre::SceneNode *parent_node, rviz::DisplayContext *context, const std::string &name,
00323 const std::string &frame_id, const robot_interaction::RobotInteraction::EndEffector &eef, const geometry_msgs::Pose &pose, double scale,
00324 const GripperMarkerState &state, bool is_selected, bool visible_x, bool visible_y, bool visible_z):
00325 FrameMarker(parent_node, context, name, frame_id, pose, scale, stateToColor(state), is_selected, visible_x, visible_y, visible_z),
00326 state_(state),
00327 eef_(eef),
00328 display_gripper_mesh_(false)
00329 {
00330 robot_state_ = &robot_state;
00331 }
00332
00333 void GripperMarker::select(bool display_gripper_mesh)
00334 {
00335 display_gripper_mesh_ = display_gripper_mesh;
00336 FrameMarker::select();
00337 }
00338
00339 void GripperMarker::unselect(bool display_gripper_mesh)
00340 {
00341 display_gripper_mesh_ = display_gripper_mesh;
00342 FrameMarker::unselect();
00343 }
00344
00345 void GripperMarker::buildFrom(const std::string &name, const std::string &frame_id, const geometry_msgs::Pose &pose, double scale, const std_msgs::ColorRGBA &color)
00346 {
00347 color_ = color;
00348
00349 visualization_msgs::InteractiveMarker int_marker;
00350 if (isSelected())
00351 {
00352 geometry_msgs::PoseStamped pose_stamped;
00353 pose_stamped.pose = pose;
00354 int_marker = robot_interaction::make6DOFMarker(name, pose_stamped, scale);
00355 }
00356 else
00357 {
00358 int_marker.scale = scale;
00359 int_marker.name = name;
00360 int_marker.pose = pose;
00361 }
00362 int_marker.header.frame_id = frame_id;
00363 int_marker.header.stamp = ros::Time::now();
00364
00365 int_marker.menu_entries = menu_entries_;
00366
00367 visualization_msgs::InteractiveMarkerControl m_control;
00368 m_control.always_visible = true;
00369 m_control.interaction_mode = m_control.BUTTON;
00370
00371 if (display_gripper_mesh_)
00372 {
00373
00374 const robot_state::JointStateGroup *joint_state_group = robot_state_->getJointStateGroup(eef_.eef_group);
00375 const robot_state::RobotState *robot_state = joint_state_group->getRobotState();
00376
00377 const robot_model::JointModelGroup *joint_model_group = joint_state_group->getJointModelGroup();
00378 const std::vector<std::string> &link_names = joint_model_group->getLinkModelNames();
00379
00380 std_msgs::ColorRGBA marker_color;
00381 marker_color = color;
00382 visualization_msgs::MarkerArray marker_array;
00383 robot_state->getRobotMarkers(marker_array, link_names, marker_color, "goal_pose_marker", ros::Duration());
00384
00385 for (std::size_t i = 0 ; i < marker_array.markers.size() ; ++i)
00386 {
00387 marker_array.markers[i].header = int_marker.header;
00388 m_control.markers.push_back(marker_array.markers[i]);
00389 }
00390
00391 Eigen::Affine3d tip_pose = robot_state_->getLinkState(eef_.parent_link)->getGlobalLinkTransform();
00392 tf::poseEigenToMsg(tip_pose, int_marker.pose);
00393 }
00394 else
00395 {
00396
00397 visualization_msgs::Marker m;
00398 m.type = visualization_msgs::Marker::SPHERE;
00399 m.scale.x = 0.1 * scale;
00400 m.scale.y = 0.1 * scale;
00401 m.scale.z = 0.1 * scale;
00402 m.ns = "goal_pose_marker";
00403 m.action = visualization_msgs::Marker::ADD;
00404 m.color = color;
00405 m_control.markers.push_back(m);
00406
00407 m.type = visualization_msgs::Marker::ARROW;
00408 m.scale.x = 0.3 * scale;
00409 m.scale.y = 0.1 * m.scale.x;
00410 m.scale.z = 0.1 * m.scale.x;
00411 m.ns = "goal_pose_marker";
00412 m.action = visualization_msgs::Marker::ADD;
00413
00414
00415 if (visible_x_)
00416 {
00417 m.color.r = 1.0f;
00418 m.color.g = 0.0f;
00419 m.color.b = 0.0f;
00420 m.color.a = 1.0f;
00421 m_control.markers.push_back(m);
00422 }
00423
00424
00425 if (visible_y_)
00426 {
00427 tf::Quaternion imq;
00428 imq = tf::createQuaternionFromRPY(0, 0, boost::math::constants::pi<double>() / 2.0);
00429 tf::quaternionTFToMsg(imq, m.pose.orientation);
00430 m.color.r = 0.0f;
00431 m.color.g = 1.0f;
00432 m.color.b = 0.0f;
00433 m.color.a = 1.0f;
00434 m_control.markers.push_back(m);
00435 }
00436
00437
00438 if (visible_z_) {
00439 tf::Quaternion imq;
00440 imq = tf::createQuaternionFromRPY(0, -boost::math::constants::pi<double>() / 2.0, 0);
00441 tf::quaternionTFToMsg(imq, m.pose.orientation);
00442 m.color.r = 0.0f;
00443 m.color.g = 0.0f;
00444 m.color.b = 1.0f;
00445 m.color.a = 1.0f;
00446 m_control.markers.push_back(m);
00447 }
00448 }
00449
00450 int_marker.controls.push_back(m_control);
00451
00452 imarker.reset(new rviz::InteractiveMarker(parent_node_, context_ ));
00453 interactive_markers::autoComplete(int_marker);
00454 imarker->processMessage(int_marker);
00455 imarker->setShowAxes(false);
00456 imarker->setShowVisualAids(true);
00457 imarker->setShowDescription(false);
00458 imarker->setPose(Ogre::Vector3(pose.position.x, pose.position.y, pose.position.z),
00459 Ogre::Quaternion(pose.orientation.w, pose.orientation.x, pose.orientation.y, pose.orientation.z), "");
00460
00461
00462 if (receiver_ && receiver_method_)
00463 {
00464 connect(receiver_, receiver_method_);
00465 }
00466
00467 imarker_msg = int_marker;
00468 }
00469
00470 const float *GripperMarker::stateToColor(const GripperMarkerState &state)
00471 {
00472 const float *color = 0;
00473 if (state == NOT_TESTED)
00474 color = GOAL_NOT_TESTED_COLOR;
00475 else if (state == PROCESSING)
00476 color = GOAL_PROCESSING_COLOR;
00477 else if (state == REACHABLE)
00478 color = GOAL_REACHABLE_COLOR;
00479 else if (state == NOT_REACHABLE)
00480 color = GOAL_NOT_REACHABLE_COLOR;
00481 else if (state == IN_COLLISION)
00482 color = GOAL_COLLISION_COLOR;
00483 else
00484 color = GOAL_NOT_TESTED_COLOR;
00485
00486 return color;
00487 }
00488 }