Go to the documentation of this file.00001
00032 #ifndef VRPN_CLIENT_ROS_VRPN_CLIENT_ROS_H
00033 #define VRPN_CLIENT_ROS_VRPN_CLIENT_ROS_H
00034
00035 #include "vrpn_client_ros/vrpn_client_ros.h"
00036
00037 #include "ros/ros.h"
00038 #include "geometry_msgs/PoseStamped.h"
00039 #include "geometry_msgs/TwistStamped.h"
00040 #include "geometry_msgs/AccelStamped.h"
00041 #include "geometry_msgs/TransformStamped.h"
00042
00043 #include <vrpn_Tracker.h>
00044 #include <vrpn_Connection.h>
00045 #include <map>
00046 #include <string>
00047 #include <unordered_map>
00048
00049 namespace vrpn_client_ros
00050 {
00051
00052 typedef std::shared_ptr<vrpn_Connection> ConnectionPtr;
00053 typedef std::shared_ptr<vrpn_Tracker_Remote> TrackerRemotePtr;
00054
00055 class VrpnTrackerRos
00056 {
00057 public:
00058
00059 typedef std::shared_ptr<VrpnTrackerRos> Ptr;
00064 VrpnTrackerRos(std::string tracker_name, ConnectionPtr connection, ros::NodeHandle nh);
00065
00070 VrpnTrackerRos(std::string tracker_name, std::string host, ros::NodeHandle nh);
00071
00072 ~VrpnTrackerRos();
00073
00077 void mainloop();
00078
00079 private:
00080 TrackerRemotePtr tracker_remote_;
00081 std::vector<ros::Publisher> pose_pubs_, twist_pubs_, accel_pubs_;
00082 ros::NodeHandle output_nh_;
00083 bool use_server_time_, broadcast_tf_, process_sensor_id_;
00084 std::string tracker_name;
00085
00086 ros::Timer mainloop_timer;
00087
00088 geometry_msgs::PoseStamped pose_msg_;
00089 geometry_msgs::TwistStamped twist_msg_;
00090 geometry_msgs::AccelStamped accel_msg_;
00091 geometry_msgs::TransformStamped transform_stamped_;
00092
00093 void init(std::string tracker_name, ros::NodeHandle nh, bool create_mainloop_timer);
00094
00095 static void VRPN_CALLBACK handle_pose(void *userData, const vrpn_TRACKERCB tracker_pose);
00096
00097 static void VRPN_CALLBACK handle_twist(void *userData, const vrpn_TRACKERVELCB tracker_twist);
00098
00099 static void VRPN_CALLBACK handle_accel(void *userData, const vrpn_TRACKERACCCB tracker_accel);
00100 };
00101
00102 class VrpnClientRos
00103 {
00104 public:
00105
00106 typedef std::shared_ptr<VrpnClientRos> Ptr;
00107 typedef std::unordered_map<std::string, VrpnTrackerRos::Ptr> TrackerMap;
00108
00112 VrpnClientRos(ros::NodeHandle nh, ros::NodeHandle private_nh);
00113
00114 static std::string getHostStringFromParams(ros::NodeHandle host_nh);
00115
00119 void mainloop();
00120
00124 void updateTrackers();
00125
00126 private:
00127 std::string host_;
00128 ros::NodeHandle output_nh_;
00129
00133 ConnectionPtr connection_;
00134
00138 TrackerMap trackers_;
00139
00140 ros::Timer refresh_tracker_timer_, mainloop_timer;
00141 };
00142 }
00143
00144 #endif // VRPN_CLIENT_ROS_VRPN_CLIENT_ROS_H