36 #include <interactive_markers/interactive_marker_server.h>
39 #include <interactive_markers/menu_handler.h>
40 #include <tf/transform_broadcaster.h>
43 #include <sensor_msgs/JointState.h>
45 using namespace visualization_msgs;
49 boost::shared_ptr<interactive_markers::InteractiveMarkerServer>
server;
79 void processFeedback(
const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback )
82 s <<
"Feedback from marker '" << feedback->marker_name <<
"' "
83 <<
" / control '" << feedback->control_name <<
"'";
85 std::ostringstream mouse_point_ss;
86 if( feedback->mouse_point_valid )
88 mouse_point_ss <<
" at " << feedback->mouse_point.x
89 <<
", " << feedback->mouse_point.y
90 <<
", " << feedback->mouse_point.z
91 <<
" in frame " << feedback->header.frame_id;
94 switch ( feedback->event_type )
104 case visualization_msgs::InteractiveMarkerFeedback::POSE_UPDATE:
107 q[0] = feedback->pose.orientation.x;
108 q[1] = feedback->pose.orientation.y;
109 q[2] = feedback->pose.orientation.z;
110 q[3] = feedback->pose.orientation.w;
113 #if ROS_VERSION_MINIMUM(1, 8, 0) // if current ros version is >= 1.8.0
114 M.getEulerYPR(y, p, r);
115 #else // Code for earlier versions (Electric, diamondback, ...)
119 sensor_msgs::JointState joint_state;
120 joint_state.header.stamp = ros::Time::now();
121 joint_state.name.resize(2);
122 joint_state.position.resize(2);
123 joint_state.name[0] =ros::names::remap(
"pan");
124 joint_state.position[0] = y;
125 joint_state.name[1] =ros::names::remap(
"tilt");
126 joint_state.position[1] = p;
127 pub.publish(joint_state);
131 ROS_INFO_STREAM( s.str() <<
": pose changed"
133 << feedback->pose.position.x
134 <<
", " << feedback->pose.position.y
135 <<
", " << feedback->pose.position.z
136 <<
"\norientation = "
137 << feedback->pose.orientation.w
138 <<
", " << feedback->pose.orientation.x
139 <<
", " << feedback->pose.orientation.y
140 <<
", " << feedback->pose.orientation.z
141 <<
"\nframe: " << feedback->header.frame_id
142 <<
" time: " << feedback->header.stamp.sec <<
"sec, "
143 << feedback->header.stamp.nsec <<
" nsec" );
160 void alignMarker(
const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback )
162 geometry_msgs::Pose pose = feedback->pose;
164 pose.position.x = round(pose.position.x-0.5)+0.5;
165 pose.position.y = round(pose.position.y-0.5)+0.5;
167 ROS_INFO_STREAM( feedback->marker_name <<
":"
168 <<
" aligning position = "
169 << feedback->pose.position.x
170 <<
", " << feedback->pose.position.y
171 <<
", " << feedback->pose.position.z
174 <<
", " << pose.position.y
175 <<
", " << pose.position.z );
177 server->setPose( feedback->marker_name, pose );
182 double rand(
double min,
double max )
184 double t = (double)
rand() / (double)RAND_MAX;
185 return min + t*(max-min);
193 marker.type = Marker::SPHERE;
194 marker.scale.x = msg.scale * 0.45;
195 marker.scale.y = msg.scale * 0.45;
196 marker.scale.z = msg.scale * 0.45;
198 marker.color.g = 0.7;
200 marker.color.a = 0.6;
207 InteractiveMarkerControl control;
208 control.always_visible =
true;
209 control.markers.push_back(
makeBox(msg) );
210 msg.controls.push_back( control );
212 return msg.controls.back();
218 server->insert(int_marker);
227 InteractiveMarker int_marker;
228 int_marker.header.frame_id =
"/atc/vehicle/center_bumper";
229 int_marker.pose.position.x = 2;
230 int_marker.pose.position.y = 0;
231 int_marker.pose.position.z = 0.5;
232 int_marker.scale = 0.5;
234 int_marker.name =
"Fovetation Control Target";
235 int_marker.description =
"Foveation_control will try \nto aim the PTU towards\n the marker";
239 InteractiveMarkerControl control;
248 control.orientation.w = 1;
249 control.orientation.x = 1;
250 control.orientation.y = 0;
251 control.orientation.z = 0;
255 control.name =
"move_x";
256 control.interaction_mode = InteractiveMarkerControl::MOVE_AXIS;
257 int_marker.controls.push_back(control);
259 control.orientation.w = 1;
260 control.orientation.x = 0;
261 control.orientation.y = 1;
262 control.orientation.z = 0;
266 control.name =
"move_z";
267 control.interaction_mode = InteractiveMarkerControl::MOVE_AXIS;
268 int_marker.controls.push_back(control);
270 control.orientation.w = 1;
271 control.orientation.x = 0;
272 control.orientation.y = 0;
273 control.orientation.z = 1;
277 control.name =
"move_y";
278 control.interaction_mode = InteractiveMarkerControl::MOVE_AXIS;
279 int_marker.controls.push_back(control);
281 server->insert(int_marker);
289 InteractiveMarker int_marker;
290 int_marker.header.frame_id =
"/base_link";
291 int_marker.pose.position.y = -3.0 *
marker_pos++;;
292 int_marker.scale = 1;
294 int_marker.name =
"6dof_random_axes";
295 int_marker.description =
"6-DOF\n(Arbitrary Axes)";
299 InteractiveMarkerControl control;
301 for (
int i=0; i<3; i++ )
303 control.orientation.w =
rand(-1,1);
304 control.orientation.x =
rand(-1,1);
305 control.orientation.y =
rand(-1,1);
306 control.orientation.z =
rand(-1,1);
307 control.interaction_mode = InteractiveMarkerControl::ROTATE_AXIS;
308 int_marker.controls.push_back(control);
309 control.interaction_mode = InteractiveMarkerControl::MOVE_AXIS;
310 int_marker.controls.push_back(control);
313 server->insert(int_marker);
322 InteractiveMarker int_marker;
323 int_marker.header.frame_id =
"/base_link";
324 int_marker.pose.position.y = -3.0 *
marker_pos++;;
325 int_marker.scale = 1;
327 int_marker.name =
"view_facing";
328 int_marker.description =
"View Facing 6-DOF";
330 InteractiveMarkerControl control;
333 control.orientation_mode = InteractiveMarkerControl::VIEW_FACING;
334 control.interaction_mode = InteractiveMarkerControl::ROTATE_AXIS;
335 control.orientation.w = 1;
336 control.name =
"rotate";
338 int_marker.controls.push_back(control);
342 control.orientation_mode = InteractiveMarkerControl::VIEW_FACING;
343 control.interaction_mode = InteractiveMarkerControl::MOVE_PLANE;
344 control.independent_marker_orientation =
true;
345 control.name =
"move";
347 control.markers.push_back(
makeBox(int_marker) );
348 control.always_visible =
true;
350 int_marker.controls.push_back(control);
352 server->insert(int_marker);
361 InteractiveMarker int_marker;
362 int_marker.header.frame_id =
"/base_link";
363 int_marker.pose.position.y = -3.0 *
marker_pos++;;
364 int_marker.scale = 1;
366 int_marker.name =
"quadrocopter";
367 int_marker.description =
"Quadrocopter";
371 InteractiveMarkerControl control;
373 control.orientation.w = 1;
374 control.orientation.x = 0;
375 control.orientation.y = 1;
376 control.orientation.z = 0;
377 control.interaction_mode = InteractiveMarkerControl::MOVE_ROTATE;
378 int_marker.controls.push_back(control);
379 control.interaction_mode = InteractiveMarkerControl::MOVE_AXIS;
380 int_marker.controls.push_back(control);
382 server->insert(int_marker);
390 InteractiveMarker int_marker;
391 int_marker.header.frame_id =
"/base_link";
392 int_marker.pose.position.y = -3.0 *
marker_pos++;;
393 int_marker.scale = 1;
395 int_marker.name =
"chess_piece";
396 int_marker.description =
"Chess Piece\n(2D Move + Alignment)";
398 InteractiveMarkerControl control;
400 control.orientation.w = 1;
401 control.orientation.x = 0;
402 control.orientation.y = 1;
403 control.orientation.z = 0;
404 control.interaction_mode = InteractiveMarkerControl::MOVE_PLANE;
405 int_marker.controls.push_back(control);
408 control.markers.push_back(
makeBox(int_marker) );
409 control.always_visible =
true;
410 int_marker.controls.push_back(control);
413 server->insert(int_marker);
417 server->setCallback(int_marker.name, &
alignMarker, visualization_msgs::InteractiveMarkerFeedback::POSE_UPDATE );
424 InteractiveMarker int_marker;
425 int_marker.header.frame_id =
"/atc/ptu/base";
426 int_marker.pose.position.x = 0;
427 int_marker.pose.position.y = 0;
428 int_marker.pose.position.z = 0;
429 int_marker.scale = 0.5;
431 int_marker.name =
"/marker";
432 int_marker.description =
" Pan/Tilt control";
436 InteractiveMarkerControl control;
438 control.orientation.w = 1;
439 control.orientation.x = 0;
440 control.orientation.y = 1;
441 control.orientation.z = 0;
442 control.interaction_mode = InteractiveMarkerControl::ROTATE_AXIS;
443 control.orientation_mode = InteractiveMarkerControl::FIXED;
444 int_marker.controls.push_back(control);
446 control.orientation.w = 1;
447 control.orientation.x = 0;
448 control.orientation.y = 0;
449 control.orientation.z = 1;
450 control.interaction_mode = InteractiveMarkerControl::ROTATE_AXIS;
451 control.orientation_mode = InteractiveMarkerControl::INHERIT;
452 int_marker.controls.push_back(control);
454 server->insert(int_marker);
462 InteractiveMarker int_marker;
463 int_marker.header.frame_id =
"/atc/ptu/base";
464 int_marker.pose.position.y = -3.0 *
marker_pos++;;
465 int_marker.scale = 1;
467 int_marker.name =
"context_menu";
468 int_marker.description =
"Context Menu\n(Right Click)";
470 InteractiveMarkerControl control;
473 control.interaction_mode = InteractiveMarkerControl::MENU;
474 control.description=
"Options";
475 control.name =
"menu_only_control";
476 int_marker.controls.push_back(control);
479 Marker marker =
makeBox( int_marker );
480 control.markers.push_back( marker );
481 control.always_visible =
true;
482 int_marker.controls.push_back(control);
484 server->insert(int_marker);
493 InteractiveMarker int_marker;
494 int_marker.header.frame_id =
"/moving_frame";
495 int_marker.pose.position.y = -3.0 *
marker_pos++;;
496 int_marker.scale = 1;
498 int_marker.name =
"moving";
499 int_marker.description =
"Marker Attached to a\nMoving Frame";
501 InteractiveMarkerControl control;
503 control.orientation.w = 1;
504 control.orientation.x = 1;
505 control.orientation.y = 0;
506 control.orientation.z = 0;
507 control.interaction_mode = InteractiveMarkerControl::ROTATE_AXIS;
508 int_marker.controls.push_back(control);
510 control.interaction_mode = InteractiveMarkerControl::MOVE_PLANE;
511 control.always_visible =
true;
512 control.markers.push_back(
makeBox(int_marker) );
513 int_marker.controls.push_back(control);
515 server->insert(int_marker);
521 int main(
int argc,
char** argv)
523 ros::init(argc, argv,
"ptu_interactive_control_node");
527 pub = n.advertise<sensor_msgs::JointState>(
"/ptu_cmd", 1);
533 server.reset(
new interactive_markers::InteractiveMarkerServer(
"direct/im",
"",
false) );
535 ros::Duration(0.1).sleep();
540 interactive_markers::MenuHandler::EntryHandle sub_menu_handle =
menu_handler.insert(
"Submenu" );
void makeQuadrocopterMarker()
int main(int argc, char **argv)
void makeViewFacingMarker()
void frameCallback(const ros::TimerEvent &)
void makeRandomDofMarker()
void processFeedback(const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback)
void alignMarker(const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback)
double rand(double min, double max)
void makeChessPieceMarker()
InteractiveMarkerControl & makeBoxControl(InteractiveMarker &msg)
void saveMarker(InteractiveMarker int_marker)
Marker makeBox(InteractiveMarker &msg)
void make6DofMarker(bool fixed)
boost::shared_ptr< interactive_markers::InteractiveMarkerServer > server
interactive_markers::MenuHandler menu_handler