55 marker.type = Marker::CUBE;
56 marker.scale.x = msg.scale * 0.45;
57 marker.scale.y = msg.scale * 0.45;
58 marker.scale.z = msg.scale * 0.45;
69 InteractiveMarkerControl control;
70 control.always_visible =
true;
71 control.markers.push_back(
makeBox(msg) );
72 msg.controls.push_back( control );
74 return msg.controls.back();
102 void processFeedback(
const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback )
104 std::ostringstream
s;
105 s <<
"Feedback from marker '" << feedback->marker_name <<
"' " 106 <<
" / control '" << feedback->control_name <<
"'";
108 std::ostringstream mouse_point_ss;
109 if( feedback->mouse_point_valid )
111 mouse_point_ss <<
" at " << feedback->mouse_point.x
112 <<
", " << feedback->mouse_point.y
113 <<
", " << feedback->mouse_point.z
114 <<
" in frame " << feedback->header.frame_id;
117 switch ( feedback->event_type )
119 case visualization_msgs::InteractiveMarkerFeedback::BUTTON_CLICK:
120 ROS_INFO_STREAM( s.str() <<
": button click" << mouse_point_ss.str() <<
"." );
123 case visualization_msgs::InteractiveMarkerFeedback::MENU_SELECT:
124 ROS_INFO_STREAM( s.str() <<
": menu item " << feedback->menu_entry_id <<
" clicked" << mouse_point_ss.str() <<
"." );
127 case visualization_msgs::InteractiveMarkerFeedback::POSE_UPDATE:
130 << feedback->pose.position.x
131 <<
", " << feedback->pose.position.y
132 <<
", " << feedback->pose.position.z
133 <<
"\norientation = " 134 << feedback->pose.orientation.w
135 <<
", " << feedback->pose.orientation.x
136 <<
", " << feedback->pose.orientation.y
137 <<
", " << feedback->pose.orientation.z
138 <<
"\nframe: " << feedback->header.frame_id
139 <<
" time: " << feedback->header.stamp.sec <<
"sec, " 140 << feedback->header.stamp.nsec <<
" nsec" );
143 case visualization_msgs::InteractiveMarkerFeedback::MOUSE_DOWN:
144 ROS_INFO_STREAM( s.str() <<
": mouse down" << mouse_point_ss.str() <<
"." );
147 case visualization_msgs::InteractiveMarkerFeedback::MOUSE_UP:
148 ROS_INFO_STREAM( s.str() <<
": mouse up" << mouse_point_ss.str() <<
"." );
152 server->applyChanges();
157 void alignMarker(
const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback )
159 geometry_msgs::Pose pose = feedback->pose;
161 pose.position.x = round(pose.position.x-0.5)+0.5;
162 pose.position.y = round(pose.position.y-0.5)+0.5;
165 <<
" aligning position = " 166 << feedback->pose.position.x
167 <<
", " << feedback->pose.position.y
168 <<
", " << feedback->pose.position.z
171 <<
", " << pose.position.y
172 <<
", " << pose.position.z );
174 server->setPose( feedback->marker_name, pose );
175 server->applyChanges();
179 double rand(
double min,
double max )
181 double t = (double)
rand() / (double)RAND_MAX;
182 return min + t*(max-min);
191 int_marker.header.frame_id =
"base_link";
193 int_marker.scale = 1;
195 int_marker.name =
"simple_6dof";
196 int_marker.description =
"Simple 6-DOF Control";
202 InteractiveMarkerControl control;
206 int_marker.name +=
"_fixed";
207 int_marker.description +=
"\n(fixed orientation)";
208 control.orientation_mode = InteractiveMarkerControl::FIXED;
211 if (interaction_mode != visualization_msgs::InteractiveMarkerControl::NONE)
213 std::string mode_text;
214 if( interaction_mode == visualization_msgs::InteractiveMarkerControl::MOVE_3D ) mode_text =
"MOVE_3D";
215 if( interaction_mode == visualization_msgs::InteractiveMarkerControl::ROTATE_3D ) mode_text =
"ROTATE_3D";
216 if( interaction_mode == visualization_msgs::InteractiveMarkerControl::MOVE_ROTATE_3D ) mode_text =
"MOVE_ROTATE_3D";
217 int_marker.name +=
"_" + mode_text;
218 int_marker.description = std::string(
"3D Control") + (show_6dof ?
" + 6-DOF controls" :
"") +
"\n" + mode_text;
226 control.name =
"rotate_x";
227 control.interaction_mode = InteractiveMarkerControl::ROTATE_AXIS;
228 int_marker.controls.push_back(control);
229 control.name =
"move_x";
230 control.interaction_mode = InteractiveMarkerControl::MOVE_AXIS;
231 int_marker.controls.push_back(control);
236 control.name =
"rotate_z";
237 control.interaction_mode = InteractiveMarkerControl::ROTATE_AXIS;
238 int_marker.controls.push_back(control);
239 control.name =
"move_z";
240 control.interaction_mode = InteractiveMarkerControl::MOVE_AXIS;
241 int_marker.controls.push_back(control);
246 control.name =
"rotate_y";
247 control.interaction_mode = InteractiveMarkerControl::ROTATE_AXIS;
248 int_marker.controls.push_back(control);
249 control.name =
"move_y";
250 control.interaction_mode = InteractiveMarkerControl::MOVE_AXIS;
251 int_marker.controls.push_back(control);
254 server->insert(int_marker);
256 if (interaction_mode != visualization_msgs::InteractiveMarkerControl::NONE)
257 menu_handler.
apply( *server, int_marker.name );
265 int_marker.header.frame_id =
"base_link";
267 int_marker.scale = 1;
269 int_marker.name =
"6dof_random_axes";
270 int_marker.description =
"6-DOF\n(Arbitrary Axes)";
274 InteractiveMarkerControl control;
276 for (
int i=0; i<3; i++ )
281 control.interaction_mode = InteractiveMarkerControl::ROTATE_AXIS;
282 int_marker.controls.push_back(control);
283 control.interaction_mode = InteractiveMarkerControl::MOVE_AXIS;
284 int_marker.controls.push_back(control);
287 server->insert(int_marker);
297 int_marker.header.frame_id =
"base_link";
299 int_marker.scale = 1;
301 int_marker.name =
"view_facing";
302 int_marker.description =
"View Facing 6-DOF";
304 InteractiveMarkerControl control;
307 control.orientation_mode = InteractiveMarkerControl::VIEW_FACING;
308 control.interaction_mode = InteractiveMarkerControl::ROTATE_AXIS;
309 control.orientation.w = 1;
310 control.name =
"rotate";
312 int_marker.controls.push_back(control);
316 control.orientation_mode = InteractiveMarkerControl::VIEW_FACING;
317 control.interaction_mode = InteractiveMarkerControl::MOVE_PLANE;
318 control.independent_marker_orientation =
true;
319 control.name =
"move";
321 control.markers.push_back(
makeBox(int_marker) );
322 control.always_visible =
true;
324 int_marker.controls.push_back(control);
326 server->insert(int_marker);
336 int_marker.header.frame_id =
"base_link";
338 int_marker.scale = 1;
340 int_marker.name =
"quadrocopter";
341 int_marker.description =
"Quadrocopter";
345 InteractiveMarkerControl control;
350 control.interaction_mode = InteractiveMarkerControl::MOVE_ROTATE;
351 int_marker.controls.push_back(control);
352 control.interaction_mode = InteractiveMarkerControl::MOVE_AXIS;
353 int_marker.controls.push_back(control);
355 server->insert(int_marker);
364 int_marker.header.frame_id =
"base_link";
366 int_marker.scale = 1;
368 int_marker.name =
"chess_piece";
369 int_marker.description =
"Chess Piece\n(2D Move + Alignment)";
371 InteractiveMarkerControl control;
376 control.interaction_mode = InteractiveMarkerControl::MOVE_PLANE;
377 int_marker.controls.push_back(control);
380 control.markers.push_back(
makeBox(int_marker) );
381 control.always_visible =
true;
382 int_marker.controls.push_back(control);
385 server->insert(int_marker);
389 server->setCallback(int_marker.name, &
alignMarker, visualization_msgs::InteractiveMarkerFeedback::POSE_UPDATE );
397 int_marker.header.frame_id =
"base_link";
399 int_marker.scale = 1;
401 int_marker.name =
"pan_tilt";
402 int_marker.description =
"Pan / Tilt";
406 InteractiveMarkerControl control;
411 control.interaction_mode = InteractiveMarkerControl::ROTATE_AXIS;
412 control.orientation_mode = InteractiveMarkerControl::FIXED;
413 int_marker.controls.push_back(control);
418 control.interaction_mode = InteractiveMarkerControl::ROTATE_AXIS;
419 control.orientation_mode = InteractiveMarkerControl::INHERIT;
420 int_marker.controls.push_back(control);
422 server->insert(int_marker);
431 int_marker.header.frame_id =
"base_link";
433 int_marker.scale = 1;
435 int_marker.name =
"context_menu";
436 int_marker.description =
"Context Menu\n(Right Click)";
438 InteractiveMarkerControl control;
440 control.interaction_mode = InteractiveMarkerControl::MENU;
441 control.name =
"menu_only_control";
443 Marker marker =
makeBox( int_marker );
444 control.markers.push_back( marker );
445 control.always_visible =
true;
446 int_marker.controls.push_back(control);
448 server->insert(int_marker);
450 menu_handler.
apply( *server, int_marker.name );
458 int_marker.header.frame_id =
"base_link";
460 int_marker.scale = 1;
462 int_marker.name =
"button";
463 int_marker.description =
"Button\n(Left Click)";
465 InteractiveMarkerControl control;
467 control.interaction_mode = InteractiveMarkerControl::BUTTON;
468 control.name =
"button_control";
470 Marker marker =
makeBox( int_marker );
471 control.markers.push_back( marker );
472 control.always_visible =
true;
473 int_marker.controls.push_back(control);
475 server->insert(int_marker);
484 int_marker.header.frame_id =
"moving_frame";
486 int_marker.scale = 1;
488 int_marker.name =
"moving";
489 int_marker.description =
"Marker Attached to a\nMoving Frame";
491 InteractiveMarkerControl control;
496 control.interaction_mode = InteractiveMarkerControl::ROTATE_AXIS;
497 int_marker.controls.push_back(control);
499 control.interaction_mode = InteractiveMarkerControl::MOVE_PLANE;
500 control.always_visible =
true;
501 control.markers.push_back(
makeBox(int_marker) );
502 int_marker.controls.push_back(control);
504 server->insert(int_marker);
510 int main(
int argc,
char** argv)
530 make6DofMarker(
false, visualization_msgs::InteractiveMarkerControl::NONE, position,
true );
532 make6DofMarker(
true, visualization_msgs::InteractiveMarkerControl::NONE, position,
true );
536 make6DofMarker(
false, visualization_msgs::InteractiveMarkerControl::ROTATE_3D, position,
false );
538 make6DofMarker(
false, visualization_msgs::InteractiveMarkerControl::MOVE_ROTATE_3D, position,
true );
540 make6DofMarker(
false, visualization_msgs::InteractiveMarkerControl::MOVE_3D, position,
false );
556 server->applyChanges();
static tf::Quaternion createQuaternionFromRPY(double roll, double pitch, double yaw)
void makePanTiltMarker(const tf::Vector3 &position)
void processFeedback(const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback)
boost::shared_ptr< interactive_markers::InteractiveMarkerServer > server
interactive_markers::MenuHandler menu_handler
void makeMovingMarker(const tf::Vector3 &position)
void alignMarker(const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
void makeButtonMarker(const tf::Vector3 &position)
bool apply(InteractiveMarkerServer &server, const std::string &marker_name)
ROSCPP_DECL void spin(Spinner &spinner)
void makeQuadrocopterMarker(const tf::Vector3 &position)
InteractiveMarkerControl & makeBoxControl(InteractiveMarker &msg)
static void quaternionTFToMsg(const Quaternion &bt, geometry_msgs::Quaternion &msg)
void makeViewFacingMarker(const tf::Vector3 &position)
void makeChessPieceMarker(const tf::Vector3 &position)
void frameCallback(const ros::TimerEvent &)
Timer createTimer(Rate r, Handler h, Obj o, bool oneshot=false, bool autostart=true) const
int main(int argc, char **argv)
void makeMenuMarker(const tf::Vector3 &position)
EntryHandle insert(const std::string &title, const FeedbackCallback &feedback_cb)
#define ROS_INFO_STREAM(args)
Marker makeBox(InteractiveMarker &msg)
void makeRandomDofMarker(const tf::Vector3 &position)
double rand(double min, double max)
void make6DofMarker(bool fixed, unsigned int interaction_mode, const tf::Vector3 &position, bool show_6dof)
static void pointTFToMsg(const Point &bt_v, geometry_msgs::Point &msg_v)