Project

General

Profile

Statistics
| Branch: | Revision:

root / vision / src / rviz_interactive_target.cpp @ 3bdc7bfd

History | View | Annotate | Download (2.24 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
#include <functional>
6

    
7
using namespace std;
8
using namespace visualization_msgs;
9

    
10
/* TODO:
11
 * -replace the three MOVE_AXIS directions with one MOVE_AXIS and one MOVE_PLANE
12
 */
13

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

    
28
Marker3DOF::Marker3DOF(interactive_markers::InteractiveMarkerServer& server,
29
    int pubRate = 0)
30
{
31
  marker.header.frame_id = "/quadrotor";
32
  marker.pose.position.x = 5;
33
  marker.pose.position.y = 0;
34
  marker.pose.position.z = 0;
35
  marker.scale = 1;
36
  marker.name = "target";
37
  addControl("target_x", 1, 0, 0, 1);
38
  addControl("target_y", 0, 1, 0, 1);
39
  addControl("target_z", 0, 0, 1, 1);
40
  server.insert(marker);
41
  server.setCallback("target", bind(&Marker3DOF::processFeedback, this, _1));
42
  server.applyChanges();
43
  pub = nh.advertise<geometry_msgs::Point>("/v2v3_converter/target_3d", 100);
44
  if (pubRate > 0)
45
    timer = nh.createTimer(ros::Duration(1./pubRate),
46
        bind(&Marker3DOF::timerCallback, this, _1));
47
}
48

    
49
void Marker3DOF::addControl(string name, float x, float y, float z, float w)
50
{
51
  InteractiveMarkerControl control;
52
  control.orientation.x = x;
53
  control.orientation.y = y;
54
  control.orientation.z = z;
55
  control.orientation.w = w;
56
  control.name = name;
57
  control.interaction_mode = InteractiveMarkerControl::MOVE_AXIS;
58
  marker.controls.push_back(control);
59
}
60

    
61
void Marker3DOF::processFeedback(const InteractiveMarkerFeedbackConstPtr& feedback)
62
{
63
  marker.pose.position = feedback->pose.position;
64
}
65

    
66
void Marker3DOF::timerCallback(const ros::TimerEvent& event)
67
{
68
  pub.publish(marker.pose.position);
69
}
70

    
71
int main(int argc, char **argv)
72
{
73
  ros::init(argc, argv, "rviz_interactive_targets");
74
  interactive_markers::InteractiveMarkerServer server(
75
      "rviz_interactive_targets");
76
  Marker3DOF marker(server, 10);
77
  ros::spin();
78
  return 0;
79
}