pan_tilt_object_tracking.cpp
Go to the documentation of this file.
1 
2 
3 #include <ros/ros.h>
4 #include <std_msgs/Float64MultiArray.h>
6 #include <geometry_msgs/PoseStamped.h>
8 #include <pr2_controllers_msgs/PointHeadAction.h>
10 #include <std_srvs/SetBool.h>
11 
12 // Our Action interface type, provided as a typedef for convenience
14 
15 
16 void callback(const geometry_msgs::PoseStamped::ConstPtr& pose);
18 
19 /*
20 void callback(const geometry_msgs::PoseStamped::ConstPtr& pose)
21 {
22 
23  //the goal message we will be sending
24  pr2_controllers_msgs::PointHeadGoal goal;
25 
26  //the target point, expressed in the requested frame
27  geometry_msgs::PointStamped point;
28  point.header.frame_id = pose->header.frame_id;
29  point.point.x = pose->pose.position.x; point.point.y = pose->pose.position.y; point.point.z = pose->pose.position.z;
30  goal.target = point;
31 
32  //we are pointing the high-def camera frame
33  //(pointing_axis defaults to X-axis)
34  goal.pointing_frame = "kinect2_depth_frame";
35  goal.pointing_axis.x = 1;
36  goal.pointing_axis.y = 0;
37  goal.pointing_axis.z = 0;
38 
39  //take at least 0.5 seconds to get there
40  goal.min_duration = ros::Duration(0.5);
41 
42  //and go no faster than 0.2 rad/s
43  goal.max_velocity = 0.2;
44 
45  //send the goal
46  point_head_client->sendGoal(goal);
47 
48  //wait for it to get there (abort after 2 secs to prevent getting stuck)
49  point_head_client->waitForResult(goal.min_duration );
50 
51 }
52 */
53 
54 
55 
56 int main(int argc, char **argv) {
57  ros::init(argc, argv, "pan_tilt_object_trackking");
59  ros::NodeHandle pn("~");
60 
61  std::string object_name;
62  pn.param<std::string>("object_name", object_name, "can");
63 
64 
66 
67  //Initialize the client for the Action interface to the head controller
68  point_head_client = new PointHeadClient("/pan_tilt_trajectory_controller/point_head_action", true);
69 
70  //wait for head controller action server to come up
71  while(!point_head_client->waitForServer(ros::Duration(5.0))){
72  ROS_INFO("Waiting for the point_head_action server to come up");
73  }
74 
75  ROS_INFO("Ready to track!");
76  ros::Rate r(10);
77 
78  ros::ServiceClient uc_client = n.serviceClient<std_srvs::SetBool>("update_collision_objects");
79  ROS_INFO("Waiting for update_collision service...");
80  uc_client.waitForExistence();
81  std_srvs::SetBool srv;
82  srv.request.data=true;
83  uc_client.call(srv);
84 
85  while (ros::ok()) {
86 
87  std::vector<std::string> ids;
88  ids.push_back(object_name);
89  std::map<std::string, moveit_msgs::CollisionObject> poses=planning_scene_interface.getObjects(ids);
90  std::map<std::string, moveit_msgs::CollisionObject>::iterator it;
91 
92  it = poses.find(object_name);
93 
94  if (it != poses.end()) {
95  moveit_msgs::CollisionObject obj=it->second;
96  //the goal message we will be sending
97  pr2_controllers_msgs::PointHeadGoal goal;
98 
99  //the target point, expressed in the requested frame
100 
101  geometry_msgs::PointStamped point;
102 
103  point.header.frame_id = obj.header.frame_id;
104  point.header.stamp=obj.header.stamp;
105  point.point = obj.primitive_poses[0].position;
106 
107  goal.target = point;
108 
109  //we are pointing the high-def camera frame
110  //(pointing_axis defaults to X-axis)
111  goal.pointing_frame = "kinect2_depth_frame";
112  goal.pointing_axis.x = 1;
113  goal.pointing_axis.y = 0;
114  goal.pointing_axis.z = 0;
115 
116  //take at least 0.5 seconds to get there
117  goal.min_duration = ros::Duration(0.5);
118 
119  //and go no faster than 0.2 rad/s
120  goal.max_velocity = 0.2;
121 
122  //send the goal
123  point_head_client->sendGoal(goal);
124 
125  //wait for it to get there (abort after 2 secs to prevent getting stuck)
126  point_head_client->waitForResult(goal.min_duration );
127  }
128 
129  ros::spinOnce();
130  r.sleep();
131  }
132 
133 
134  return 0;
135 
136 
137 }
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
bool waitForServer(const ros::Duration &timeout=ros::Duration(0, 0)) const
int main(int argc, char **argv)
bool waitForResult(const ros::Duration &timeout=ros::Duration(0, 0))
std::string object_name
void callback(const geometry_msgs::PoseStamped::ConstPtr &pose)
actionlib::SimpleActionClient< pr2_controllers_msgs::PointHeadAction > PointHeadClient
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
bool call(MReq &req, MRes &res)
bool waitForExistence(ros::Duration timeout=ros::Duration(-1))
#define ROS_INFO(...)
bool param(const std::string &param_name, T &param_val, const T &default_val) const
PointHeadClient * point_head_client
ROSCPP_DECL bool ok()
bool sleep()
void sendGoal(const Goal &goal, SimpleDoneCallback done_cb=SimpleDoneCallback(), SimpleActiveCallback active_cb=SimpleActiveCallback(), SimpleFeedbackCallback feedback_cb=SimpleFeedbackCallback())
ROSCPP_DECL void spinOnce()
r


robotican_common
Author(s):
autogenerated on Wed Jan 3 2018 03:48:33