Go to the documentation of this file.00001
00002
00003 #include <ros/ros.h>
00004 #include <std_msgs/Float64MultiArray.h>
00005 #include <tf/transform_listener.h>
00006 #include <geometry_msgs/PoseStamped.h>
00007 #include <actionlib/client/simple_action_client.h>
00008 #include <pr2_controllers_msgs/PointHeadAction.h>
00009 #include <moveit/planning_scene_interface/planning_scene_interface.h>
00010 #include <std_srvs/SetBool.h>
00011
00012
00013 typedef actionlib::SimpleActionClient<pr2_controllers_msgs::PointHeadAction> PointHeadClient;
00014
00015
00016 void callback(const geometry_msgs::PoseStamped::ConstPtr& pose);
00017 PointHeadClient* point_head_client;
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056 int main(int argc, char **argv) {
00057 ros::init(argc, argv, "pan_tilt_object_trackking");
00058 ros::NodeHandle n;
00059 ros::NodeHandle pn("~");
00060
00061 std::string object_name;
00062 pn.param<std::string>("object_name", object_name, "can");
00063
00064
00065 moveit::planning_interface::PlanningSceneInterface planning_scene_interface;
00066
00067
00068 point_head_client = new PointHeadClient("/pan_tilt_trajectory_controller/point_head_action", true);
00069
00070
00071 while(!point_head_client->waitForServer(ros::Duration(5.0))){
00072 ROS_INFO("Waiting for the point_head_action server to come up");
00073 }
00074
00075 ROS_INFO("Ready to track!");
00076 ros::Rate r(10);
00077
00078 ros::ServiceClient uc_client = n.serviceClient<std_srvs::SetBool>("update_collision_objects");
00079 ROS_INFO("Waiting for update_collision service...");
00080 uc_client.waitForExistence();
00081 std_srvs::SetBool srv;
00082 srv.request.data=true;
00083 uc_client.call(srv);
00084
00085 while (ros::ok()) {
00086
00087 std::vector<std::string> ids;
00088 ids.push_back(object_name);
00089 std::map<std::string, moveit_msgs::CollisionObject> poses=planning_scene_interface.getObjects(ids);
00090 std::map<std::string, moveit_msgs::CollisionObject>::iterator it;
00091
00092 it = poses.find(object_name);
00093
00094 if (it != poses.end()) {
00095 moveit_msgs::CollisionObject obj=it->second;
00096
00097 pr2_controllers_msgs::PointHeadGoal goal;
00098
00099
00100
00101 geometry_msgs::PointStamped point;
00102
00103 point.header.frame_id = obj.header.frame_id;
00104 point.header.stamp=obj.header.stamp;
00105 point.point = obj.primitive_poses[0].position;
00106
00107 goal.target = point;
00108
00109
00110
00111 goal.pointing_frame = "kinect2_depth_frame";
00112 goal.pointing_axis.x = 1;
00113 goal.pointing_axis.y = 0;
00114 goal.pointing_axis.z = 0;
00115
00116
00117 goal.min_duration = ros::Duration(0.5);
00118
00119
00120 goal.max_velocity = 0.2;
00121
00122
00123 point_head_client->sendGoal(goal);
00124
00125
00126 point_head_client->waitForResult(goal.min_duration );
00127 }
00128
00129 ros::spinOnce();
00130 r.sleep();
00131 }
00132
00133
00134 return 0;
00135
00136
00137 }