Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include <srs_assisted_grasping/manual_grasping_node.h>
00029
00030 using namespace srs_assisted_grasping;
00031 using namespace srs_assisted_grasping_msgs;
00032 using namespace std;
00033
00034
00035 ReactiveGrasping::ReactiveGrasping(std::string name) {
00036
00037
00038
00039 double tmp;
00040 ros::param::param<double>("~default_time", tmp, 3.0);
00041
00042 params_.default_time_ = ros::Duration(tmp);
00043
00044 ros::param::param<double>("~max_force", params_.max_force_, 1000.0);
00045 ros::param::param<double>("~max_velocity", params_.max_velocity_, 1.5);
00046 ros::param::param<double>("~ramp", params_.ramp_, 10.0);
00047 ros::param::param<double>("~rate", params_.rate_, 5.0);
00048
00049
00050 ros::NodeHandle nh("~");
00051 XmlRpc::XmlRpcValue joints_list;
00052
00053
00054 if (nh.getParam("joints",joints_list)) {
00055
00056 std::map<std::string, XmlRpc::XmlRpcValue>::iterator i;
00057
00058 for (i = joints_list.begin(); i != joints_list.end(); i++) {
00059
00060 joints_.joints.push_back(i->first);
00061 joints_.has_tactile_pad.push_back((bool)i->second["has_tactile_pad"]);
00062
00063 }
00064
00065 ROS_INFO("Configured for %d joints with %d tactile pads",(int)joints_.joints.size(),(int)joints_.has_tactile_pad.size());
00066
00067
00068 } else {
00069
00070 ROS_ERROR("Can't get list of joints!");
00071
00072 }
00073
00074
00075
00076
00077
00078 server_ = new actionlib::SimpleActionServer<srs_assisted_grasping_msgs::ReactiveGraspingAction>(nh_, name, boost::bind(&ReactiveGrasping::execute, this, _1), false);
00079
00080 sdh_mode_client_ = nh_.serviceClient<cob_srvs::SetOperationMode>("/sdh_controller/set_operation_mode");
00081
00082
00083
00084
00085
00086 action_name_ = name;
00087
00088 tact_sub_ = nh_.subscribe("/sdh_controller/mean_values", 10, &ReactiveGrasping::TactileDataCallback,this);
00089 state_sub_ = nh_.subscribe("/sdh_controller/state", 10, &ReactiveGrasping::SdhStateCallback,this);
00090 server_->start();
00091
00092
00093 }
00094
00095
00096 void ReactiveGrasping::execute(const ReactiveGraspingGoalConstPtr &goal) {
00097
00098 ROS_INFO("Reactive grasping action triggered");
00099
00100
00101 ReactiveGraspingResult res;
00102 ReactiveGraspingFeedback feedback;
00103
00104
00105
00106
00107 }
00108
00109 void ReactiveGrasping::SdhStateCallback(const pr2_controllers_msgs::JointTrajectoryControllerState::ConstPtr & msg) {
00110
00111 data_mutex_.lock();
00112
00113 data_mutex_.unlock();
00114
00115 }
00116
00117
00118 void ReactiveGrasping::TactileDataCallback(const std_msgs::Float32MultiArray::ConstPtr& msg) {
00119
00120 data_mutex_.lock();
00121
00122 data_mutex_.unlock();
00123
00124 }
00125
00126
00127 bool ReactiveGrasping::setMode(std::string mode) {
00128
00129
00130 cob_srvs::SetOperationMode srv;
00131
00132 srv.request.operation_mode.data = mode;
00133
00134 if (sdh_mode_client_.call(srv)) {
00135
00136 if (srv.response.success.data) {
00137
00138 ROS_INFO("SDH should be in %s mode",mode.c_str());
00139 return true;
00140
00141 } else {
00142
00143 ROS_ERROR("Failed to set SDH to %s mode, error: %s",mode.c_str(),srv.response.error_message.data.c_str());
00144 return false;
00145
00146 }
00147
00148 } else {
00149
00150 ROS_ERROR("Failed to call SDH mode service");
00151 return false;
00152
00153 }
00154
00155 }
00156
00157 int main(int argc, char** argv)
00158 {
00159
00160
00161 ROS_INFO("Starting manual grasping node");
00162 ros::init(argc, argv, "but_reactive_grasping_node");
00163
00164 ReactiveGrasping mg(string(ACT_GRASP));
00165
00166
00167 ROS_INFO("Spinning...");
00168
00169 ros::spin();
00170 ros::shutdown();
00171
00172 }