Go to the documentation of this file.00001 #include <ros/ros.h>
00002 #include <move_base_msgs/MoveBaseAction.h>
00003 #include <actionlib/client/simple_action_client.h>
00004 #include <geometry_msgs/PoseStamped.h>
00005 #include <visualization_msgs/Marker.h>
00006 #include <string>
00007
00008 #include <heatmap/wifi_signal.h>
00009
00010 typedef actionlib::SimpleActionClient<move_base_msgs::MoveBaseAction> MoveBaseClient;
00011
00012 MoveBaseClient* ac;
00013 ros::Publisher marker_pub;
00014 uint32_t shape = visualization_msgs::Marker::SPHERE;
00015 int marker_index = 0;
00016 heatmap::wifi_signal current_sig;
00017 std::string tf_prefix;
00018
00019 int sig_count = 0, av_sig = 0;
00020
00021 void goalCallback(const geometry_msgs::PoseStamped& lgoal)
00022 {
00023 move_base_msgs::MoveBaseGoal goal;
00024 visualization_msgs::Marker marker;
00025 double link;
00026
00027 goal.target_pose = lgoal;
00028 ROS_INFO("I heard: A goal!");
00029 ROS_INFO("Redirecting goal...");
00030 ac->sendGoal(goal);
00031
00032 ac->waitForResult();
00033
00034 if(ac->getState() == actionlib::SimpleClientGoalState::SUCCEEDED)
00035 {
00036 ROS_INFO("Hooray, the base reached its goal!");
00037 ROS_INFO("Let's take a measurement...");
00038
00039 ROS_INFO("Done!");
00040 marker.header.frame_id = tf_prefix + "/base_footprint";
00041 marker.header.stamp = ros::Time::now();
00042 marker.ns = "wifi_signal";
00043 marker.id = marker_index;
00044 marker_index++;
00045 marker.type = shape;
00046
00047
00048 marker.action = visualization_msgs::Marker::ADD;
00049
00050
00051 marker.pose.position.x = 0;
00052 marker.pose.position.y = 0;
00053 marker.pose.position.z = 0;
00054 marker.pose.orientation.x = 0.0;
00055 marker.pose.orientation.y = 0.0;
00056 marker.pose.orientation.z = 0.0;
00057 marker.pose.orientation.w = 1.0;
00058
00059
00060 marker.scale.x = 1.0;
00061 marker.scale.y = 1.0;
00062 marker.scale.z = 1.0;
00063
00064 link = ((double)((current_sig.link_quality - 35.0)* 2.0)/(double)current_sig.link_quality_max);
00065 if (link < 0) link = 0;
00066
00067
00068 marker.color.r = 1.0 - link;
00069 marker.color.g = link;
00070 marker.color.b = 0.0f;
00071 marker.color.a = 1.0;
00072
00073 marker.lifetime = ros::Duration();
00074
00075 marker_pub.publish(marker);
00076 }
00077 else
00078 {
00079 ROS_INFO("The base failed to reach its goal for some reason.");
00080 }
00081 }
00082
00083 void signalCallback(const heatmap::wifi_signal& sig)
00084 {
00085 av_sig += sig.link_quality;
00086 sig_count++;
00087
00088 if(sig_count == 5) {
00089 current_sig = sig;
00090 current_sig.link_quality = av_sig/5;
00091 av_sig = 0;
00092 sig_count = 0;
00093 }
00094 }
00095
00096 int main(int argc, char** argv){
00097 ros::init(argc, argv, "simple_navigation_goals");
00098
00099 ros::NodeHandle n;
00100
00101 n.getParam("/tf_prefix", tf_prefix);
00102 ROS_INFO("tf_prefix: %s", tf_prefix.c_str());
00103
00104 ros::Subscriber goal_sub = n.subscribe("goal", 1, goalCallback);
00105 ros::Subscriber signal_sub = n.subscribe("signal", 1, signalCallback);
00106 marker_pub = n.advertise<visualization_msgs::Marker>("visualization_marker", 1);
00107
00108
00109 ac = new MoveBaseClient("move_base", true);
00110
00111
00112 while(!ac->waitForServer(ros::Duration(5.0))){
00113 ROS_INFO("Waiting for the move_base action server to come up");
00114 }
00115
00116 ros::spin();
00117
00118 delete ac;
00119 return 0;
00120 }