19 #include "sensor_msgs/PointCloud2.h" 20 #include <geometry_msgs/Point.h> 21 #include <geometry_msgs/Vector3.h> 26 #include <haf_grasping/CalcGraspPointsServerAction.h> 28 #include <haf_grasping/GraspSearchCenter.h> 29 #include <haf_grasping/GraspSearchRectangleSize.h> 30 #include <haf_grasping/GraspCalculationTimeMax.h> 31 #include <haf_grasping/GraspApproachVector.h> 32 #include <haf_grasping/ShowOnlyBestGrasp.h> 33 #include <haf_grasping/GraspPreGripperOpeningWidth.h> 36 #include <pcl/io/pcd_io.h> 37 #include <pcl/point_types.h> 67 void get_grasp_cb(
const sensor_msgs::PointCloud2ConstPtr& pc_in);
69 bool set_grasp_center(haf_grasping::GraspSearchCenter::Request &req, haf_grasping::GraspSearchCenter::Response &res);
70 bool set_grasp_search_area_size(haf_grasping::GraspSearchRectangleSize::Request &req, haf_grasping::GraspSearchRectangleSize::Response &res);
72 bool set_approach_vector(haf_grasping::GraspApproachVector::Request &req, haf_grasping::GraspApproachVector::Response &res);
73 bool set_show_only_best_grasp(haf_grasping::ShowOnlyBestGrasp::Request &req, haf_grasping::ShowOnlyBestGrasp::Response &res);
74 bool set_gripper_width(haf_grasping::GraspPreGripperOpeningWidth::Request &req, haf_grasping::GraspPreGripperOpeningWidth::Response &res);
79 this->graspsearchcenter.x = this->graspsearchcenter.y = this->graspsearchcenter.z = 0.0;
80 std::vector<float> grasp_search_center_tmp;
81 if ( nh_.
getParam(
"grasp_search_center", grasp_search_center_tmp) ) {
82 this->graspsearchcenter.x = grasp_search_center_tmp[0];
83 this->graspsearchcenter.y = grasp_search_center_tmp[1];
84 this->graspsearchcenter.z = grasp_search_center_tmp[2];
87 this->approach_vector.x = this->approach_vector.y = 0.0;
88 this->approach_vector.z = 1.0;
89 std::vector<float> gripper_approach_vector_tmp;
90 if ( nh_.
getParam(
"gripper_approach_vector", gripper_approach_vector_tmp) ) {
91 this->approach_vector.x = gripper_approach_vector_tmp[0];
92 this->approach_vector.y = gripper_approach_vector_tmp[1];
93 this->approach_vector.z = gripper_approach_vector_tmp[2];
97 nh_.
param(
"grasp_search_size_x", this->grasp_search_size_x, 18);
98 nh_.
param(
"grasp_search_size_y", this->grasp_search_size_y, 30);
99 this->max_grasp_search_size_x = 18;
100 this->max_grasp_search_size_y = 30;
101 if (this->grasp_search_size_x < 1 or this->grasp_search_size_x > this->max_grasp_search_size_x)
103 if (this->grasp_search_size_y < 1 or this->grasp_search_size_y > this->max_grasp_search_size_y)
107 int max_calculation_time;
108 nh_.
param(
"max_calculation_time", max_calculation_time, 50);
109 this->grasp_calculation_time_max =
ros::Duration(max_calculation_time);
112 nh_.
param(
"show_only_best_grasp", this->show_only_best_grasp,
true);
116 nh_.
param(
"base_frame", this->base_frame_default, std::string(
"base_link"));
118 nh_.
param(
"gripper_width", this->gripper_opening_width, 1);
122 std::string input_pc_topic =
"/haf_grasping/depth_registered/single_cloud/points_in_lcs";
123 nh_.
param(
"input_pc_topic", input_pc_topic, input_pc_topic);
139 pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (
new pcl::PointCloud<pcl::PointXYZ>);
141 if (pcl::io::loadPCDFile<pcl::PointXYZ> (pcd_path.data.c_str(), *cloud) == -1)
143 PCL_ERROR (
"Couldn't read input file (pcd) \n");
146 std::cout <<
"Loaded " 147 << cloud->width * cloud->height
148 <<
" data points from " << pcd_path.data.c_str();
151 sensor_msgs::PointCloud2 pcd_as_ros_msg;
154 pcd_as_ros_msg.header.stamp =
ros::Time(0);
155 const sensor_msgs::PointCloud2ConstPtr pcd_as_ros_msg_const_ptr = boost::make_shared<sensor_msgs::PointCloud2>(pcd_as_ros_msg);
162 ROS_INFO(
"\nFrom calc_grasppoints_action_client: point cloud received");
168 ROS_INFO(
"Waiting for action server to start.");
172 ROS_INFO(
"Action server started, sending goal.");
174 haf_grasping::CalcGraspPointsServerGoal goal;
175 goal.graspinput.input_pc = *pc_in;
201 if (finished_before_timeout)
209 ROS_INFO(
"Action did not finish before the time out.");
215 haf_grasping::GraspSearchCenter::Response &res)
221 ROS_INFO(
"Set grasp search center to: x=%f, y=%f, z=%f", req.graspsearchcenter.x, req.graspsearchcenter.y, req.graspsearchcenter.z);
223 ROS_INFO(
"sending back response: [%ld]", (
long int)res.result);
229 haf_grasping::GraspSearchRectangleSize::Response &res)
232 if (req.grasp_search_size_x >= 0 and req.grasp_search_size_x <= this->max_grasp_search_size_x){
234 ROS_INFO(
"Set grasp rectangle size to: x=%ld", (
long int)req.grasp_search_size_x);
236 ROS_INFO(
"Could not set grasp rectangle size for x. Allowed values: [0, %ld ]. Received value was: x=%ld", (
long int)this->
max_grasp_search_size_x,(
long int)req.grasp_search_size_x);
240 if (req.grasp_search_size_y >= 0 and req.grasp_search_size_y <= this->max_grasp_search_size_y){
242 ROS_INFO(
"Set grasp rectangle size to: y=%ld", (
long int)req.grasp_search_size_y);
244 ROS_INFO(
"Could not set grasp rectangle size for y. Allowed values: [0, %ld ]. Received value was: y=%ld", (
long int)this->
max_grasp_search_size_y,(
long int)req.grasp_search_size_y);
250 ROS_INFO(
"sending back response: [%ld]", (
long int)res.result);
257 haf_grasping::GraspCalculationTimeMax::Response &res)
261 ROS_INFO(
"Set max calculation time (sec) to: x=%d", (
int)req.max_calculation_time.toSec());
263 ROS_INFO(
"sending back response: [%d]", (
int)res.result);
272 ROS_INFO(
"Set approach vector to: [%f,%f,%f]", this->
approach_vector.x,this->approach_vector.y,this->approach_vector.z);
274 ROS_INFO(
"sending back response: [%d]", (
int)res.result);
280 haf_grasping::ShowOnlyBestGrasp::Response &res)
286 ROS_INFO(
"sending back response: [%d]", (
int)res.result);
292 haf_grasping::GraspPreGripperOpeningWidth::Response &res)
296 ROS_INFO(
"Set gripper_opening_width (factor for scaling pc) to: x=%d", (
int)req.gripper_opening_width);
298 ROS_INFO(
"sending back response: [%d]", (
int)res.result);
303 int main (
int argc,
char **argv)
305 ROS_INFO(
"ROS NODE calc_grasppoints_client started");
306 ros::init(argc, argv,
"calc_grasppoint_client");
int main(int argc, char **argv)
geometry_msgs::Point graspsearchcenter
bool waitForServer(const ros::Duration &timeout=ros::Duration(0, 0)) const
geometry_msgs::Vector3 approach_vector
bool set_grasp_calculation_time_max(haf_grasping::GraspCalculationTimeMax::Request &req, haf_grasping::GraspCalculationTimeMax::Response &res)
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
bool waitForResult(const ros::Duration &timeout=ros::Duration(0, 0))
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
int gripper_opening_width
ROSCPP_DECL void spin(Spinner &spinner)
std::string toString() const
bool set_grasp_search_area_size(haf_grasping::GraspSearchRectangleSize::Request &req, haf_grasping::GraspSearchRectangleSize::Response &res)
int max_grasp_search_size_y
bool set_grasp_center(haf_grasping::GraspSearchCenter::Request &req, haf_grasping::GraspSearchCenter::Response &res)
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
void open_pcd_and_trig_get_grasp_cb(std_msgs::String pcd_path)
ros::ServiceServer srv_set_show_only_best_grasp
bool set_approach_vector(haf_grasping::GraspApproachVector::Request &req, haf_grasping::GraspApproachVector::Response &res)
int max_grasp_search_size_x
ros::ServiceServer srv_set_approach_vector
void sendGoal(const Goal &goal, SimpleDoneCallback done_cb=SimpleDoneCallback(), SimpleActiveCallback active_cb=SimpleActiveCallback(), SimpleFeedbackCallback feedback_cb=SimpleFeedbackCallback())
ros::Duration grasp_calculation_time_max
ros::ServiceServer srv_set_gripper_width
#define ROS_INFO_STREAM(args)
bool show_only_best_grasp
CCalcGrasppointsClient(ros::NodeHandle nh_)
bool set_show_only_best_grasp(haf_grasping::ShowOnlyBestGrasp::Request &req, haf_grasping::ShowOnlyBestGrasp::Response &res)
bool getParam(const std::string &key, std::string &s) const
ros::ServiceServer srv_set_grasp_center
void toROSMsg(const sensor_msgs::PointCloud2 &cloud, sensor_msgs::Image &image)
void get_grasp_cb(const sensor_msgs::PointCloud2ConstPtr &pc_in)
std::string base_frame_default
SimpleClientGoalState getState() const
ResultConstPtr getResult() const
bool set_gripper_width(haf_grasping::GraspPreGripperOpeningWidth::Request &req, haf_grasping::GraspPreGripperOpeningWidth::Response &res)
ros::ServiceServer srv_set_grasp_calculation_time_max
ros::ServiceServer srv_set_grasp_search_area_size