Go to the documentation of this file.00001 #include "ros/ros.h"
00002 #include "geometry_msgs/PoseWithCovarianceStamped.h"
00003 #include "nav_msgs/Odometry.h"
00004 #include "tf/transform_broadcaster.h"
00005 #include "cirkit_waypoint_navigator/TeleportAbsolute.h"
00006
00007 class RemoteMonitorClient
00008 {
00009 public:
00010 void sendPosition(const geometry_msgs::PoseWithCovarianceStamped::ConstPtr& amcl_pose);
00011
00012 public:
00013 RemoteMonitorClient(const std::string _ns) : rate_(1.0), ns_(_ns)
00014 {
00015 ros::NodeHandle n(ns_);
00016 n.param("interval_dist", interval_dist_, 5.0);
00017 n.param("pose_topic", pose_topic_, std::string("/amcl_pose"));
00018 ROS_INFO("interval_dist = %.2f.", interval_dist_);
00019 ROS_INFO("pose_topic = %s.", pose_topic_.c_str());
00020
00021 monitor_client_ = nh_.serviceClient<cirkit_waypoint_navigator::TeleportAbsolute>("remote_monitor_robot_pose");
00022 odom_sub_ = nh_.subscribe<geometry_msgs::PoseWithCovarianceStamped>(pose_topic_, 1, boost::bind(&RemoteMonitorClient::sendPosition, this, _1));
00023 }
00024
00025
00026
00027 double calculateDistance(geometry_msgs::PoseWithCovariance pose)
00028 {
00029 return sqrt(pow(pose.pose.position.x - last_pose_.pose.position.x, 2)
00030 + pow(pose.pose.position.y - last_pose_.pose.position.y, 2));
00031 }
00032
00033 void getRPY(const geometry_msgs::Quaternion &q,
00034 double &roll,double &pitch,double &yaw){
00035 tf::Quaternion tfq(q.x, q.y, q.z, q.w);
00036 tf::Matrix3x3(tfq).getRPY(roll, pitch, yaw);
00037 }
00038
00039
00040 private:
00041 ros::NodeHandle nh_;
00042 ros::Rate rate_;
00043 ros::ServiceClient monitor_client_;
00044 cirkit_waypoint_navigator::TeleportAbsolute srv_;
00045 ros::Subscriber odom_sub_;
00046
00047 geometry_msgs::PoseWithCovariance last_pose_;
00048
00049 std::string ns_;
00050 double interval_dist_;
00051 std::string pose_topic_;
00052 };
00053
00054 void RemoteMonitorClient::sendPosition(const geometry_msgs::PoseWithCovarianceStamped::ConstPtr& amcl_pose)
00055 {
00056 double dist = calculateDistance(amcl_pose->pose);
00057 if(dist >= interval_dist_)
00058 {
00059 double yaw, pitch, roll;
00060 getRPY(amcl_pose->pose.pose.orientation, roll, pitch, yaw);
00061 srv_.request.x = amcl_pose->pose.pose.position.x;
00062 srv_.request.y = amcl_pose->pose.pose.position.y;
00063 srv_.request.theta = yaw;
00064
00065 if(monitor_client_.call(srv_))
00066 {
00067 ROS_INFO("Succeed to send robot position to server.");
00068 }
00069 else
00070 {
00071 ROS_INFO("Failed to send robot position to server.");
00072 }
00073 last_pose_ = amcl_pose->pose;
00074 }
00075 }
00076
00077 int main(int argc, char **argv)
00078 {
00079 ros::init(argc, argv, "remote_monitor_client");
00080
00081 std::string ns;
00082 if(argc > 1)
00083 ns = argv[1];
00084 else
00085 ns = "remote_monitor_client";
00086
00087 RemoteMonitorClient client(ns);
00088
00089 ros::spin();
00090
00091 return 0;
00092 }