Project

General

Profile

Statistics
| Branch: | Revision:

root / vision / src / rviz_interactive_target.cpp @ 643083a8

History | View | Annotate | Download (2.42 KB)

1
#include <ros/ros.h>
2
#include <string.h>
3
#include <geometry_msgs/Quaternion.h>
4
#include <interactive_markers/interactive_marker_server.h>
5

    
6
using namespace std;
7
using namespace visualization_msgs;
8

    
9
/* TODO:
10
 * -replace the three MOVE_AXIS directions with one MOVE_AXIS and one MOVE_PLANE
11
 * -make it compile without needing class Callback
12
 * -have it constantly publish current position, instead of only publishing
13
 *  when the marker is moved
14
 */
15

    
16
class Marker3DOF
17
{
18
public:
19
  Marker3DOF(interactive_markers::InteractiveMarkerServer& server);
20
  void processFeedback(const InteractiveMarkerFeedbackConstPtr& feedback);
21
private:
22
  void addControl(string name, float x, float y, float z, float w);
23
  ros::NodeHandle nh;
24
  InteractiveMarker marker;
25
  ros::Publisher pub;
26
};
27

    
28
// boost should be able to do this, but... I could _not_ make it compile
29
// so, I wrote my own
30
template <class class_t, class arg_t> class Callback
31
{
32
public:
33
  Callback(void (class_t::*cb)(arg_t), class_t* obj) : cb(cb), obj(obj) {}
34
  void operator()(arg_t arg) {(obj->*cb)(arg);}
35
private:
36
  void (class_t::*cb)(arg_t);
37
  class_t* obj;
38
};
39

    
40
Marker3DOF::Marker3DOF(interactive_markers::InteractiveMarkerServer& server)
41
{
42
  marker.header.frame_id = "/quadrotor";
43
  marker.pose.position.x = 5;
44
  marker.pose.position.y = 0;
45
  marker.pose.position.z = 0;
46
  marker.scale = 1;
47
  marker.name = "target";
48
  addControl("target_x", 1, 0, 0, 1);
49
  addControl("target_y", 0, 1, 0, 1);
50
  addControl("target_z", 0, 0, 1, 1);
51
  server.insert(marker);
52
  server.setCallback("target", Callback<Marker3DOF, const
53
      InteractiveMarkerFeedbackConstPtr&>(&Marker3DOF::processFeedback, this));
54
  server.applyChanges();
55
  pub = nh.advertise<geometry_msgs::Point>("/v2v3_converter/target_3d", 100);
56
}
57

    
58
void Marker3DOF::addControl(string name, float x, float y, float z, float w)
59
{
60
  InteractiveMarkerControl control;
61
  control.orientation.x = x;
62
  control.orientation.y = y;
63
  control.orientation.z = z;
64
  control.orientation.w = w;
65
  control.name = name;
66
  control.interaction_mode = InteractiveMarkerControl::MOVE_AXIS;
67
  marker.controls.push_back(control);
68
}
69

    
70
void Marker3DOF::processFeedback(const InteractiveMarkerFeedbackConstPtr&
71
    feedback)
72
{
73
  pub.publish(feedback->pose.position);
74
}
75

    
76
int main(int argc, char **argv)
77
{
78
  ros::init(argc, argv, "rviz_interactive_targets");
79
  interactive_markers::InteractiveMarkerServer server(
80
      "rviz_interactive_targets");
81
  Marker3DOF marker(server);
82
  ros::spin();
83
  return 0;
84
}