Go to the documentation of this file.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
00033
00034
00035
00036
00037
00038
00039
00040
00041 #include "imarker.h"
00042 #include "pose_string.h"
00043 #include <eigen_conversions/eigen_msg.h>
00044
00045
00046
00047 void IMarker::printFeedback(
00048 const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback )
00049 {
00050 ROS_INFO_STREAM(feedback->marker_name.c_str()
00051 << "is now at :"
00052 << PoseString(feedback->pose));
00053 }
00054
00055
00056
00057
00058 visualization_msgs::Marker IMarker::makeAxisCyl( IMarker::Axis axis )
00059 {
00060 visualization_msgs::Marker marker;
00061 double scale = imarker_.scale * 0.4;
00062
00063 marker.type = visualization_msgs::Marker::CYLINDER;
00064 marker.scale.x = scale * 0.15;
00065 marker.scale.y = scale * 0.15;
00066 marker.scale.z = scale;
00067 marker.pose.orientation.w = 1.0;
00068 marker.color.r = 0.0;
00069 marker.color.g = 0.0;
00070 marker.color.b = 0.0;
00071 marker.color.a = 1.0;
00072
00073 switch( axis )
00074 {
00075 case X:
00076 marker.pose.position.x = 0.5 * scale;
00077 marker.pose.orientation.y = 1.0;
00078 marker.color.r = 0.5;
00079 break;
00080 case Y:
00081 marker.pose.position.y = 0.5 * scale;
00082 marker.pose.orientation.x = 1.0;
00083 marker.color.g = 0.5;
00084 break;
00085 case Z:
00086 default:
00087 marker.pose.position.z = 0.5 * scale;
00088 marker.color.b = 0.5;
00089 break;
00090 }
00091
00092 return marker;
00093 }
00094
00095
00096 void IMarker::makeBallControl()
00097 {
00098 visualization_msgs::InteractiveMarkerControl control;
00099 control.always_visible = true;
00100 imarker_.controls.push_back( control );
00101 }
00102
00103
00104 void IMarker::makeAxisControl()
00105 {
00106 visualization_msgs::InteractiveMarkerControl control;
00107 control.always_visible = true;
00108 control.markers.push_back( makeAxisCyl(X) );
00109 control.markers.push_back( makeAxisCyl(Y) );
00110 control.markers.push_back( makeAxisCyl(Z) );
00111 imarker_.controls.push_back( control );
00112 }
00113
00114
00115 void IMarker::move(const Eigen::Affine3d& pose)
00116 {
00117 tf::poseEigenToMsg(pose, imarker_.pose);
00118 server_->applyChanges();
00119 }
00120
00121
00122 void IMarker::initialize(
00123 interactive_markers::InteractiveMarkerServer& server,
00124 const std::string& name,
00125 const Eigen::Vector3d& position,
00126 const Eigen::Quaterniond& orientation,
00127 const std::string& frame_id,
00128 boost::function<void (const visualization_msgs::InteractiveMarkerFeedbackConstPtr &)> callback,
00129 IMarker::Dof dof)
00130 {
00131 server_ = &server;
00132 imarker_.header.frame_id = frame_id;
00133 tf::pointEigenToMsg(position, imarker_.pose.position);
00134 tf::quaternionEigenToMsg(orientation, imarker_.pose.orientation);
00135 imarker_.scale = 0.3;
00136
00137 imarker_.name = name;
00138 imarker_.description = name;
00139
00140
00141 switch (dof)
00142 {
00143 case POS:
00144 makeBallControl();
00145 break;
00146 case ORIENT:
00147 case BOTH:
00148 default:
00149 makeAxisControl();
00150 break;
00151 }
00152
00153 visualization_msgs::InteractiveMarkerControl control;
00154
00155 control.orientation_mode = visualization_msgs::InteractiveMarkerControl::FIXED;
00156
00157
00158 for (int i=0; i<3; i++)
00159 {
00160 static const char *dirname = "xyz";
00161
00162 control.orientation.w = 1;
00163 control.orientation.x = 0;
00164 control.orientation.y = 0;
00165 control.orientation.z = 0;
00166 switch(i) {
00167 case 0: control.orientation.x = 1; break;
00168 case 1: control.orientation.y = 1; break;
00169 case 2: control.orientation.z = 1; break;
00170 }
00171
00172 if (dof == ORIENT || dof == BOTH)
00173 {
00174 control.name = std::string("rotate_") + std::string(1,dirname[i]);
00175 control.interaction_mode = visualization_msgs::InteractiveMarkerControl::ROTATE_AXIS;
00176 imarker_.controls.push_back(control);
00177 }
00178 if (dof == POS || dof == BOTH)
00179 {
00180 control.name = std::string("move_") + std::string(1,dirname[i]);
00181 control.interaction_mode = visualization_msgs::InteractiveMarkerControl::MOVE_AXIS;
00182 imarker_.controls.push_back(control);
00183 }
00184 }
00185
00186
00187 server_->insert(imarker_);
00188 server_->setCallback(imarker_.name, callback);
00189 server_->applyChanges();
00190 }