pan_tilt_object_tracking.cpp
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 // Our Action interface type, provided as a typedef for convenience
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 void callback(const geometry_msgs::PoseStamped::ConstPtr& pose)
00021 {
00022 
00023     //the goal message we will be sending
00024     pr2_controllers_msgs::PointHeadGoal goal;
00025 
00026     //the target point, expressed in the requested frame
00027     geometry_msgs::PointStamped point;
00028     point.header.frame_id = pose->header.frame_id;
00029     point.point.x = pose->pose.position.x; point.point.y = pose->pose.position.y; point.point.z = pose->pose.position.z;
00030     goal.target = point;
00031 
00032     //we are pointing the high-def camera frame
00033     //(pointing_axis defaults to X-axis)
00034     goal.pointing_frame = "kinect2_depth_frame";
00035     goal.pointing_axis.x = 1;
00036     goal.pointing_axis.y = 0;
00037     goal.pointing_axis.z = 0;
00038 
00039     //take at least 0.5 seconds to get there
00040     goal.min_duration = ros::Duration(0.5);
00041 
00042     //and go no faster than 0.2 rad/s
00043     goal.max_velocity = 0.2;
00044 
00045     //send the goal
00046     point_head_client->sendGoal(goal);
00047 
00048     //wait for it to get there (abort after 2 secs to prevent getting stuck)
00049     point_head_client->waitForResult(goal.min_duration );
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     //Initialize the client for the Action interface to the head controller
00068     point_head_client = new PointHeadClient("/pan_tilt_trajectory_controller/point_head_action", true);
00069 
00070     //wait for head controller action server to come up
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             //the goal message we will be sending
00097             pr2_controllers_msgs::PointHeadGoal goal;
00098 
00099             //the target point, expressed in the requested frame
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             //we are pointing the high-def camera frame
00110             //(pointing_axis defaults to X-axis)
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             //take at least 0.5 seconds to get there
00117             goal.min_duration = ros::Duration(0.5);
00118 
00119             //and go no faster than 0.2 rad/s
00120             goal.max_velocity = 0.2;
00121 
00122             //send the goal
00123             point_head_client->sendGoal(goal);
00124 
00125             //wait for it to get there (abort after 2 secs to prevent getting stuck)
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 }


robotican_common
Author(s):
autogenerated on Fri Oct 27 2017 03:02:37