$search
00001 /* 00002 * Gazebo - Outdoor Multi-Robot Simulator 00003 * Copyright (C) 2003 00004 * Nate Koenig & Andrew Howard 00005 * 00006 * This program is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation; either version 2 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00019 * 00020 */ 00021 /* 00022 * Desc: 3D position interface for ground truth. 00023 * Author: Sachin Chitta and John Hsu 00024 * Date: 1 June 2008 00025 * SVN info: $Id$ 00026 */ 00027 00028 #include <gazebo_plugins/gazebo_ros_grasp_hack.h> 00029 00030 #include <gazebo/Global.hh> 00031 #include <gazebo/XMLConfig.hh> 00032 #include <gazebo/HingeJoint.hh> 00033 #include <gazebo/SliderJoint.hh> 00034 #include <gazebo/Simulator.hh> 00035 #include <gazebo/gazebo.h> 00036 #include <gazebo/GazeboError.hh> 00037 #include <gazebo/ControllerFactory.hh> 00038 #include <gazebo/World.hh> 00039 00040 using namespace gazebo; 00041 00042 GZ_REGISTER_DYNAMIC_CONTROLLER("gazebo_ros_grasp_hack", GazeboRosGraspHack); 00043 00045 // Constructor 00046 GazeboRosGraspHack::GazeboRosGraspHack(Entity *parent ) 00047 : Controller(parent) 00048 { 00049 // check for contact with [lr]_gripper_*_finger_tip_link 00050 // if contacts exist, grab relative pose between this body and the [lr]_gripper_palm_link 00051 // fix object to the relative pose until we lose contact 00052 00053 this->myParentBody = dynamic_cast<Body*>(this->parent); 00054 00055 if (!this->myParentBody) 00056 gzthrow("GazeboRosGraspHack controller requires a Body as its parent"); 00057 00058 this->myParentModel = myParentBody->GetModel(); 00059 00060 Param::Begin(&this->parameters); 00061 this->robotNamespaceP = new ParamT<std::string>("robotNamespace", "/", 0); 00062 this->topicNameP = new ParamT<std::string>("topicName", "", 0); 00063 this->graspCheckRateP = new ParamT<double>("graspCheckRate", 10, 0); 00064 Param::End(); 00065 00066 // danger: assume start up without grasp 00067 this->l_grasp = false; 00068 this->r_grasp = false; 00069 00070 this->last_time = Simulator::Instance()->GetSimTime(); 00071 this->last_grasp_check_time = Simulator::Instance()->GetSimTime(); 00072 this->found_gripper_links = false; 00073 this->topicName.clear(); 00074 00075 00076 // all the link names in the gripper 00077 this->gripper_bodies.clear(); 00078 this->gripper_bodies.insert(std::make_pair("l_gripper_l_finger_tip_link", GripperPose())); 00079 this->gripper_bodies.insert(std::make_pair("l_gripper_r_finger_tip_link", GripperPose())); 00080 this->gripper_bodies.insert(std::make_pair("l_gripper_l_finger_link" , GripperPose())); 00081 this->gripper_bodies.insert(std::make_pair("l_gripper_r_finger_link" , GripperPose())); 00082 this->gripper_bodies.insert(std::make_pair("l_gripper_motor_slider_link", GripperPose())); 00083 this->gripper_bodies.insert(std::make_pair("l_gripper_motor_screw_link" , GripperPose())); 00084 this->gripper_bodies.insert(std::make_pair("l_gripper_l_parallel_link" , GripperPose())); 00085 this->gripper_bodies.insert(std::make_pair("l_gripper_r_parallel_link" , GripperPose())); 00086 this->gripper_bodies.insert(std::make_pair("r_gripper_l_finger_tip_link", GripperPose())); 00087 this->gripper_bodies.insert(std::make_pair("r_gripper_r_finger_tip_link", GripperPose())); 00088 this->gripper_bodies.insert(std::make_pair("r_gripper_l_finger_link" , GripperPose())); 00089 this->gripper_bodies.insert(std::make_pair("r_gripper_r_finger_link" , GripperPose())); 00090 this->gripper_bodies.insert(std::make_pair("r_gripper_motor_slider_link", GripperPose())); 00091 this->gripper_bodies.insert(std::make_pair("r_gripper_motor_screw_link" , GripperPose())); 00092 this->gripper_bodies.insert(std::make_pair("r_gripper_l_parallel_link" , GripperPose())); 00093 this->gripper_bodies.insert(std::make_pair("r_gripper_r_parallel_link" , GripperPose())); 00094 } 00095 00097 // Destructor 00098 GazeboRosGraspHack::~GazeboRosGraspHack() 00099 { 00100 delete this->robotNamespaceP; 00101 delete this->topicNameP; 00102 delete this->graspCheckRateP; 00103 delete this->rosnode_; 00104 } 00105 00107 // Load the controller 00108 void GazeboRosGraspHack::LoadChild(XMLConfigNode *node) 00109 { 00110 this->robotNamespaceP->Load(node); 00111 this->robotNamespace = this->robotNamespaceP->GetValue(); 00112 if (!ros::isInitialized()) 00113 { 00114 int argc = 0; 00115 char** argv = NULL; 00116 ros::init(argc,argv,"gazebo",ros::init_options::NoSigintHandler|ros::init_options::AnonymousName); 00117 } 00118 00119 this->rosnode_ = new ros::NodeHandle(this->robotNamespace); 00120 00121 this->topicNameP->Load(node); 00122 00123 if (this->topicNameP->GetValue() != "") 00124 { 00125 this->topicName = this->robotNamespace+"/"+this->topicNameP->GetValue()+"/"+this->GetName(); 00126 ros::AdvertiseOptions grasp_hack_ao = ros::AdvertiseOptions::create<std_msgs::String>( 00127 this->topicName,1, 00128 boost::bind( &GazeboRosGraspHack::GraspHackConnect,this), 00129 boost::bind( &GazeboRosGraspHack::GraspHackDisconnect,this), ros::VoidPtr(), &this->grasp_hack_queue_); 00130 this->pub_ = this->rosnode_->advertise(grasp_hack_ao); 00131 } 00132 00133 this->graspCheckRateP->Load(node); 00134 this->graspCheckRate = this->graspCheckRateP->GetValue(); 00135 00136 } 00137 00139 // Increment count 00140 void GazeboRosGraspHack::GraspHackConnect() 00141 { 00142 this->graspHackConnectCount++; 00143 } 00145 // Decrement count 00146 void GazeboRosGraspHack::GraspHackDisconnect() 00147 { 00148 this->graspHackConnectCount--; 00149 } 00150 00152 // Initialize the controller 00153 void GazeboRosGraspHack::InitChild() 00154 { 00155 // start custom queue for grasp_hack 00156 this->callback_queue_thread_ = boost::thread( boost::bind( &GazeboRosGraspHack::GraspHackQueueThread,this ) ); 00157 this->get_gripper_links_thread_ = boost::thread( boost::bind( &GazeboRosGraspHack::GetGripperLinks,this ) ); 00158 } 00159 00161 // Look for Gripper Links 00162 void GazeboRosGraspHack::GetGripperLinks() 00163 { 00164 this->last_time = Simulator::Instance()->GetSimTime(); 00165 00166 this->l_wrist_roll_body = NULL; 00167 this->r_wrist_roll_body = NULL; 00168 00169 // at least one arm is captured 00170 bool found_gripper_bodies = false; 00171 while (!found_gripper_bodies) 00172 { 00173 std::vector<Model*> all_models = World::Instance()->GetModels(); 00174 for (std::vector<Model*>::iterator iter = all_models.begin(); iter != all_models.end(); iter++) 00175 { 00176 if (*iter) // search all models, maybe better to check only for pr2? 00177 { 00178 boost::recursive_mutex::scoped_lock lock( *Simulator::Instance()->GetMRMutex());// wait for ProcessEntitiesToLoad() to finish 00179 00180 // get gripper parent bodies (wrist_roll_link) 00181 if (!this->l_wrist_roll_body) this->l_wrist_roll_body = dynamic_cast<Body*>((*iter)->GetBody("l_wrist_roll_link")); 00182 if (!this->r_wrist_roll_body) this->r_wrist_roll_body = dynamic_cast<Body*>((*iter)->GetBody("r_wrist_roll_link")); 00183 00184 // get all the children links of wrist_roll_body 00185 for (std::map<std::string, GripperPose>::iterator biter = this->gripper_bodies.begin(); biter != this->gripper_bodies.end(); biter++) 00186 if (!biter->second.body) biter->second.body = dynamic_cast<Body*>((*iter)->GetBody(biter->first)); 00187 } 00188 } 00189 00190 // check if all gripper bodies are found 00191 found_gripper_bodies = true; 00192 if (!this->l_wrist_roll_body || !this->r_wrist_roll_body) found_gripper_bodies = false; 00193 for (std::map<std::string, GripperPose>::iterator biter = this->gripper_bodies.begin(); biter != this->gripper_bodies.end(); biter++) 00194 if (!biter->second.body) found_gripper_bodies = false; 00195 usleep(100000); 00196 } 00197 this->found_gripper_links = true; 00198 } 00199 00201 // check contacts to determine grasps 00202 void GazeboRosGraspHack::CheckForGrasps() 00203 { 00204 this->last_grasp_check_time = Simulator::Instance()->GetSimTime(); 00205 00206 //check for contact with left gripper finger tips 00207 { 00208 bool l_gripper_l_finger = false; 00209 bool l_gripper_r_finger = false; 00210 00211 int jointCount = gazebo::World::Instance()->GetContactJointCount(); 00212 for (int i = 0; i < jointCount ; i++) 00213 { 00214 World::ContactJoint j = gazebo::World::Instance()->GetContactJoint(i); 00215 if ((j.b1 == this->myParentBody) || (j.b2 == this->myParentBody)) 00216 { 00217 if ((j.b1 == this->gripper_bodies["l_gripper_l_finger_tip_link"].body) || (j.b2 == this->gripper_bodies["l_gripper_l_finger_tip_link"].body)) 00218 l_gripper_l_finger = true; 00219 if ((j.b1 == this->gripper_bodies["l_gripper_r_finger_tip_link"].body) || (j.b2 == this->gripper_bodies["l_gripper_r_finger_tip_link"].body)) 00220 l_gripper_r_finger = true; 00221 } 00222 } 00223 00224 if (l_gripper_l_finger && l_gripper_r_finger) 00225 { 00226 if (!this->l_grasp) 00227 { 00228 this->l_grasp = true; 00229 this->l_grasp_relative_pose = this->myParentModel->GetWorldPose() - this->l_wrist_roll_body->GetWorldPose(); 00230 this->gripper_bodies["l_gripper_l_finger_tip_link"].relative_pose = this->gripper_bodies["l_gripper_l_finger_tip_link"].body->GetWorldPose() - this->l_wrist_roll_body->GetWorldPose(); 00231 this->gripper_bodies["l_gripper_r_finger_tip_link"].relative_pose = this->gripper_bodies["l_gripper_r_finger_tip_link"].body->GetWorldPose() - this->l_wrist_roll_body->GetWorldPose(); 00232 this->gripper_bodies["l_gripper_l_finger_link" ].relative_pose = this->gripper_bodies["l_gripper_l_finger_link" ].body->GetWorldPose() - this->l_wrist_roll_body->GetWorldPose(); 00233 this->gripper_bodies["l_gripper_r_finger_link" ].relative_pose = this->gripper_bodies["l_gripper_r_finger_link" ].body->GetWorldPose() - this->l_wrist_roll_body->GetWorldPose(); 00234 this->gripper_bodies["l_gripper_motor_slider_link"].relative_pose = this->gripper_bodies["l_gripper_motor_slider_link"].body->GetWorldPose() - this->l_wrist_roll_body->GetWorldPose(); 00235 this->gripper_bodies["l_gripper_motor_screw_link" ].relative_pose = this->gripper_bodies["l_gripper_motor_screw_link" ].body->GetWorldPose() - this->l_wrist_roll_body->GetWorldPose(); 00236 this->gripper_bodies["l_gripper_l_parallel_link" ].relative_pose = this->gripper_bodies["l_gripper_l_parallel_link" ].body->GetWorldPose() - this->l_wrist_roll_body->GetWorldPose(); 00237 this->gripper_bodies["l_gripper_r_parallel_link" ].relative_pose = this->gripper_bodies["l_gripper_r_parallel_link" ].body->GetWorldPose() - this->l_wrist_roll_body->GetWorldPose(); 00238 00239 } 00240 } 00241 else 00242 this->l_grasp = false; 00243 } 00244 //check for contact with right gripper finger tips 00245 { 00246 bool r_gripper_l_finger = false; 00247 bool r_gripper_r_finger = false; 00248 00249 int jointCount = gazebo::World::Instance()->GetContactJointCount(); 00250 for (int i = 0; i < jointCount ; i++) 00251 { 00252 World::ContactJoint j = gazebo::World::Instance()->GetContactJoint(i); 00253 //ROS_ERROR("b %s b1 %s b2 %s",this->myParentBody->GetName().c_str(),j.b1->GetName().c_str(),j.b2->GetName().c_str()); 00254 if ((j.b1 == this->myParentBody) || (j.b2 == this->myParentBody)) 00255 { 00256 if ((j.b1 == this->gripper_bodies["r_gripper_l_finger_tip_link"].body) || (j.b2 == this->gripper_bodies["r_gripper_l_finger_tip_link"].body)) 00257 r_gripper_l_finger = true; 00258 if ((j.b1 == this->gripper_bodies["r_gripper_r_finger_tip_link"].body) || (j.b2 == this->gripper_bodies["r_gripper_r_finger_tip_link"].body)) 00259 r_gripper_r_finger = true; 00260 //ROS_ERROR("%d %d b %ld b1 %ld b2 %ld rtip %ld ltip %ld", 00261 // (int)r_gripper_l_finger,(int)r_gripper_r_finger,(long)this->myParentBody,(long)j.b1,(long)j.b2, 00262 // (long)this->r_gripper_r_finger_tip_body,(long)this->r_gripper_l_finger_tip_body); 00263 } 00264 } 00265 00266 if (r_gripper_l_finger && r_gripper_r_finger) 00267 { 00268 if (!r_grasp) 00269 { 00270 this->r_grasp = true; 00271 this->r_grasp_relative_pose = this->myParentModel->GetWorldPose() - this->r_wrist_roll_body->GetWorldPose(); 00272 this->gripper_bodies["r_gripper_l_finger_link" ].relative_pose = this->gripper_bodies["r_gripper_l_finger_link" ].body->GetWorldPose() - this->r_wrist_roll_body->GetWorldPose(); 00273 this->gripper_bodies["r_gripper_l_finger_tip_link"].relative_pose = this->gripper_bodies["r_gripper_l_finger_tip_link"].body->GetWorldPose() - this->r_wrist_roll_body->GetWorldPose(); 00274 this->gripper_bodies["r_gripper_r_finger_tip_link"].relative_pose = this->gripper_bodies["r_gripper_r_finger_tip_link"].body->GetWorldPose() - this->r_wrist_roll_body->GetWorldPose(); 00275 this->gripper_bodies["r_gripper_r_finger_link" ].relative_pose = this->gripper_bodies["r_gripper_r_finger_link" ].body->GetWorldPose() - this->r_wrist_roll_body->GetWorldPose(); 00276 this->gripper_bodies["r_gripper_motor_slider_link"].relative_pose = this->gripper_bodies["r_gripper_motor_slider_link"].body->GetWorldPose() - this->r_wrist_roll_body->GetWorldPose(); 00277 this->gripper_bodies["r_gripper_motor_screw_link" ].relative_pose = this->gripper_bodies["r_gripper_motor_screw_link" ].body->GetWorldPose() - this->r_wrist_roll_body->GetWorldPose(); 00278 this->gripper_bodies["r_gripper_l_parallel_link" ].relative_pose = this->gripper_bodies["r_gripper_l_parallel_link" ].body->GetWorldPose() - this->r_wrist_roll_body->GetWorldPose(); 00279 this->gripper_bodies["r_gripper_r_parallel_link" ].relative_pose = this->gripper_bodies["r_gripper_r_parallel_link" ].body->GetWorldPose() - this->r_wrist_roll_body->GetWorldPose(); 00280 } 00281 } 00282 if (!r_gripper_l_finger || !r_gripper_r_finger) 00283 r_grasp = false; 00284 } 00285 } 00286 00288 // Update the controller 00289 void GazeboRosGraspHack::UpdateChild() 00290 { 00291 if (!this->found_gripper_links) return; 00292 00293 gazebo::Time cur_time = Simulator::Instance()->GetSimTime(); 00294 // throttled check for grasp (computationally expensive) 00295 if ((this->graspCheckRate > 0) && (cur_time - this->last_grasp_check_time) > 1.0/this->graspCheckRate) 00296 this->CheckForGrasps(); 00297 00298 // apply pose update if grasp is made 00299 if (this->l_grasp) 00300 { 00301 // fix myParentBody relative to l_wrist_roll_body 00302 gazebo::Pose3d pose = this->l_grasp_relative_pose + this->l_wrist_roll_body->GetWorldPose(); 00303 this->myParentModel->SetWorldPose(pose); 00304 /* this does not allow gripper to open once a grasp is made :( 00305 this->gripper_bodies["l_gripper_l_finger_tip_link"].body->SetWorldPose( this->gripper_bodies["l_gripper_l_finger_tip_link"].relative_pose + this->l_wrist_roll_body->GetWorldPose() ); 00306 this->gripper_bodies["l_gripper_r_finger_tip_link"].body->SetWorldPose( this->gripper_bodies["l_gripper_r_finger_tip_link"].relative_pose + this->l_wrist_roll_body->GetWorldPose() ); 00307 this->gripper_bodies["l_gripper_l_finger_link" ].body->SetWorldPose( this->gripper_bodies["l_gripper_l_finger_link" ].relative_pose + this->l_wrist_roll_body->GetWorldPose() ); 00308 this->gripper_bodies["l_gripper_r_finger_link" ].body->SetWorldPose( this->gripper_bodies["l_gripper_r_finger_link" ].relative_pose + this->l_wrist_roll_body->GetWorldPose() ); 00309 this->gripper_bodies["l_gripper_motor_slider_link"].body->SetWorldPose( this->gripper_bodies["l_gripper_motor_slider_link"].relative_pose + this->l_wrist_roll_body->GetWorldPose() ); 00310 this->gripper_bodies["l_gripper_motor_screw_link" ].body->SetWorldPose( this->gripper_bodies["l_gripper_motor_screw_link" ].relative_pose + this->l_wrist_roll_body->GetWorldPose() ); 00311 this->gripper_bodies["l_gripper_l_parallel_link" ].body->SetWorldPose( this->gripper_bodies["l_gripper_l_parallel_link" ].relative_pose + this->l_wrist_roll_body->GetWorldPose() ); 00312 this->gripper_bodies["l_gripper_r_parallel_link" ].body->SetWorldPose( this->gripper_bodies["l_gripper_r_parallel_link" ].relative_pose + this->l_wrist_roll_body->GetWorldPose() ); 00313 this->gripper_bodies["l_gripper_l_finger_tip_link"].body->SetAngularVel( Vector3(0,0,0) ); 00314 this->gripper_bodies["l_gripper_r_finger_tip_link"].body->SetAngularVel( Vector3(0,0,0) ); 00315 this->gripper_bodies["l_gripper_l_finger_link" ].body->SetAngularVel( Vector3(0,0,0) ); 00316 this->gripper_bodies["l_gripper_r_finger_link" ].body->SetAngularVel( Vector3(0,0,0) ); 00317 this->gripper_bodies["l_gripper_motor_slider_link"].body->SetAngularVel( Vector3(0,0,0) ); 00318 this->gripper_bodies["l_gripper_motor_screw_link" ].body->SetAngularVel( Vector3(0,0,0) ); 00319 this->gripper_bodies["l_gripper_l_parallel_link" ].body->SetAngularVel( Vector3(0,0,0) ); 00320 this->gripper_bodies["l_gripper_r_parallel_link" ].body->SetAngularVel( Vector3(0,0,0) ); 00321 this->gripper_bodies["l_gripper_l_finger_tip_link"].body->SetLinearVel( Vector3(0,0,0) ); 00322 this->gripper_bodies["l_gripper_r_finger_tip_link"].body->SetLinearVel( Vector3(0,0,0) ); 00323 this->gripper_bodies["l_gripper_l_finger_link" ].body->SetLinearVel( Vector3(0,0,0) ); 00324 this->gripper_bodies["l_gripper_r_finger_link" ].body->SetLinearVel( Vector3(0,0,0) ); 00325 this->gripper_bodies["l_gripper_motor_slider_link"].body->SetLinearVel( Vector3(0,0,0) ); 00326 this->gripper_bodies["l_gripper_motor_screw_link" ].body->SetLinearVel( Vector3(0,0,0) ); 00327 this->gripper_bodies["l_gripper_l_parallel_link" ].body->SetLinearVel( Vector3(0,0,0) ); 00328 this->gripper_bodies["l_gripper_r_parallel_link" ].body->SetLinearVel( Vector3(0,0,0) );*/ 00329 } 00330 00331 00332 // apply pose update if grasp is made 00333 if (r_grasp) 00334 { 00335 // fix myParentBody relative to r_wrist_roll_body 00336 gazebo::Pose3d pose = this->r_grasp_relative_pose + this->r_wrist_roll_body->GetWorldPose(); 00337 this->myParentModel->SetWorldPose(pose); 00338 /* this does not allow gripper to open once a grasp is made :( 00339 this->gripper_bodies["r_gripper_l_finger_tip_link"].body->SetWorldPose( this->gripper_bodies["r_gripper_l_finger_tip_link"].relative_pose + this->r_wrist_roll_body->GetWorldPose() ); 00340 this->gripper_bodies["r_gripper_r_finger_tip_link"].body->SetWorldPose( this->gripper_bodies["r_gripper_r_finger_tip_link"].relative_pose + this->r_wrist_roll_body->GetWorldPose() ); 00341 this->gripper_bodies["r_gripper_l_finger_link" ].body->SetWorldPose( this->gripper_bodies["r_gripper_l_finger_link" ].relative_pose + this->r_wrist_roll_body->GetWorldPose() ); 00342 this->gripper_bodies["r_gripper_r_finger_link" ].body->SetWorldPose( this->gripper_bodies["r_gripper_r_finger_link" ].relative_pose + this->r_wrist_roll_body->GetWorldPose() ); 00343 this->gripper_bodies["r_gripper_motor_slider_link"].body->SetWorldPose( this->gripper_bodies["r_gripper_motor_slider_link"].relative_pose + this->r_wrist_roll_body->GetWorldPose() ); 00344 this->gripper_bodies["r_gripper_motor_screw_link" ].body->SetWorldPose( this->gripper_bodies["r_gripper_motor_screw_link" ].relative_pose + this->r_wrist_roll_body->GetWorldPose() ); 00345 this->gripper_bodies["r_gripper_l_parallel_link" ].body->SetWorldPose( this->gripper_bodies["r_gripper_l_parallel_link" ].relative_pose + this->r_wrist_roll_body->GetWorldPose() ); 00346 this->gripper_bodies["r_gripper_r_parallel_link" ].body->SetWorldPose( this->gripper_bodies["r_gripper_r_parallel_link" ].relative_pose + this->r_wrist_roll_body->GetWorldPose() ); 00347 this->gripper_bodies["r_gripper_l_finger_tip_link"].body->SetAngularVel( Vector3(0,0,0) ); 00348 this->gripper_bodies["r_gripper_r_finger_tip_link"].body->SetAngularVel( Vector3(0,0,0) ); 00349 this->gripper_bodies["r_gripper_l_finger_link" ].body->SetAngularVel( Vector3(0,0,0) ); 00350 this->gripper_bodies["r_gripper_r_finger_link" ].body->SetAngularVel( Vector3(0,0,0) ); 00351 this->gripper_bodies["r_gripper_motor_slider_link"].body->SetAngularVel( Vector3(0,0,0) ); 00352 this->gripper_bodies["r_gripper_motor_screw_link" ].body->SetAngularVel( Vector3(0,0,0) ); 00353 this->gripper_bodies["r_gripper_l_parallel_link" ].body->SetAngularVel( Vector3(0,0,0) ); 00354 this->gripper_bodies["r_gripper_r_parallel_link" ].body->SetAngularVel( Vector3(0,0,0) ); 00355 this->gripper_bodies["r_gripper_l_finger_tip_link"].body->SetLinearVel( Vector3(0,0,0) ); 00356 this->gripper_bodies["r_gripper_r_finger_tip_link"].body->SetLinearVel( Vector3(0,0,0) ); 00357 this->gripper_bodies["r_gripper_l_finger_link" ].body->SetLinearVel( Vector3(0,0,0) ); 00358 this->gripper_bodies["r_gripper_r_finger_link" ].body->SetLinearVel( Vector3(0,0,0) ); 00359 this->gripper_bodies["r_gripper_motor_slider_link"].body->SetLinearVel( Vector3(0,0,0) ); 00360 this->gripper_bodies["r_gripper_motor_screw_link" ].body->SetLinearVel( Vector3(0,0,0) ); 00361 this->gripper_bodies["r_gripper_l_parallel_link" ].body->SetLinearVel( Vector3(0,0,0) ); 00362 this->gripper_bodies["r_gripper_r_parallel_link" ].body->SetLinearVel( Vector3(0,0,0) );*/ 00363 } 00364 00365 00366 00367 00368 // misc debugging 00369 if (!this->topicName.empty()) 00370 { 00371 // get inertial Rates 00372 // differentiate to get accelerations 00373 if(cur_time.Double() > this->last_time.Double()) 00374 { 00375 this->lock.lock(); 00376 std_msgs::String pubStr; 00377 00378 std::ostringstream stream; 00379 stream << "grasp hack [" << this->GetName() 00380 << "] links_found [" << this->found_gripper_links 00381 << "] l_touch [" << this->l_grasp 00382 << "] r_touch [" << this->r_grasp 00383 << "] time[" << cur_time 00384 << "]\n"; 00385 pubStr.data = stream.str(); 00386 // publish to ros 00387 this->pub_.publish(pubStr); 00388 this->lock.unlock(); 00389 00390 // save last time stamp 00391 this->last_time = cur_time; 00392 } 00393 } 00394 00395 } 00396 00398 // Finalize the controller 00399 void GazeboRosGraspHack::FiniChild() 00400 { 00401 this->rosnode_->shutdown(); 00402 this->grasp_hack_queue_.clear(); 00403 this->grasp_hack_queue_.disable(); 00404 this->callback_queue_thread_.join(); 00405 this->get_gripper_links_thread_.join(); 00406 } 00407 00409 // Put laser data to the interface 00410 void GazeboRosGraspHack::GraspHackQueueThread() 00411 { 00412 static const double timeout = 0.01; 00413 00414 while (this->rosnode_->ok()) 00415 { 00416 this->grasp_hack_queue_.callAvailable(ros::WallDuration(timeout)); 00417 } 00418 } 00419