00001 00002 #include "move_base_to_manip/desired_robot_pose.h" // Service that provides a desired pose 00003 #include "ros/ros.h" 00004 #include "visualization_msgs/Marker.h" 00005 00006 namespace provide_target 00007 { 00008 visualization_msgs::Marker desired_ee_pose; // Stores the target pose 00009 bool shutdown_now = false; 00010 } 00011 00012 00013 // This service provides a desired pose to the requester, then shuts down the node. 00014 bool desired_robot_pose(move_base_to_manip::desired_robot_pose::Request &req, 00015 move_base_to_manip::desired_robot_pose::Response &res) 00016 { 00017 res.desired_robot_pose.header.frame_id = provide_target::desired_ee_pose.header.frame_id; 00018 00019 res.desired_robot_pose.pose.position.x = provide_target::desired_ee_pose.pose.position.x; 00020 res.desired_robot_pose.pose.position.y = provide_target::desired_ee_pose.pose.position.y; 00021 res.desired_robot_pose.pose.position.z = provide_target::desired_ee_pose.pose.position.z; 00022 00023 res.desired_robot_pose.pose.orientation.x = provide_target::desired_ee_pose.pose.orientation.x; 00024 res.desired_robot_pose.pose.orientation.y = provide_target::desired_ee_pose.pose.orientation.y; 00025 res.desired_robot_pose.pose.orientation.z = provide_target::desired_ee_pose.pose.orientation.z; 00026 res.desired_robot_pose.pose.orientation.w = provide_target::desired_ee_pose.pose.orientation.w; 00027 00028 // If shutdown_now is true, this node will shut down 00029 provide_target::shutdown_now = req.shutdown_service; 00030 00031 return provide_target::shutdown_now; 00032 } 00033 00035 // MAIN 00037 int main(int argc, char **argv) 00038 { 00039 00040 ros::init(argc, argv, "provide_target"); 00041 ros::NodeHandle nh; 00042 00044 // Show the pose we want in Rviz 00046 00047 ros::Publisher approachVisualizationPublisher = nh.advertise<visualization_msgs::Marker>("desired_ee_pose", 1); 00048 ros::Duration(1).sleep(); 00049 00050 provide_target::desired_ee_pose.header.frame_id = "base_link"; 00051 provide_target::desired_ee_pose.header.stamp = ros::Time(); 00052 00053 // For this example, we'll use a meaningless default 00054 provide_target::desired_ee_pose.pose.position.x = 0.; 00055 provide_target::desired_ee_pose.pose.position.y = 0.; 00056 provide_target::desired_ee_pose.pose.position.z = 0.; 00057 00058 provide_target::desired_ee_pose.pose.orientation.x = 0.; 00059 provide_target::desired_ee_pose.pose.orientation.y = 0.; 00060 provide_target::desired_ee_pose.pose.orientation.z = 0.; 00061 provide_target::desired_ee_pose.pose.orientation.w = 1.; 00062 00063 // Cosmetic details for Rviz arrow 00064 // Head is at points.at(0), tail is at points.at(1) 00065 visualization_msgs::Marker arrow_marker; 00066 arrow_marker.header.frame_id = "/base_link"; 00067 arrow_marker.header.stamp = ros::Time(); 00068 arrow_marker.id = 47; 00069 arrow_marker.type = visualization_msgs::Marker::ARROW; 00070 arrow_marker.action = visualization_msgs::Marker::ADD; 00071 00072 arrow_marker.scale.x = 0.02; // Shaft dia 00073 arrow_marker.scale.y = 0.04; // Head dia 00074 arrow_marker.color.r = 0.0; 00075 arrow_marker.color.g = 1.0; 00076 arrow_marker.color.b = 0.0; 00077 arrow_marker.color.a = 1.0; 00078 00079 arrow_marker.points.resize(2); 00080 // Head of the arrow 00081 arrow_marker.points[1] = provide_target::desired_ee_pose.pose.position; 00082 // Tail of the arrow 00083 arrow_marker.points[0].x = provide_target::desired_ee_pose.pose.position.x; 00084 arrow_marker.points[0].y = provide_target::desired_ee_pose.pose.position.y; 00085 arrow_marker.points[0].z = provide_target::desired_ee_pose.pose.position.z+0.25; 00086 00087 provide_target::desired_ee_pose.lifetime = ros::Duration(); 00088 approachVisualizationPublisher.publish(arrow_marker); 00089 00090 // Start a service. Wait until another node requests the desired pose, then shut down (if requested). 00091 ros::ServiceServer service = nh.advertiseService("desired_robot_pose", desired_robot_pose); 00092 while ( !provide_target::shutdown_now && ros::ok() ) // Until the client(s) requests a shutdown 00093 { 00094 ros::spinOnce(); 00095 ros::Duration(0.5).sleep(); 00096 } 00097 00098 ros::shutdown(); 00099 return 0; 00100 }