Go to the documentation of this file.00001 #include "wam_driver.h"
00002
00003
00004 using namespace std;
00005 using namespace XmlRpc;
00006
00007 WamDriver::WamDriver() :
00008 force_request_(new ForceRequest)
00009 {
00010 ros::NodeHandle nh("~");
00011
00012 XmlRpc::XmlRpcValue r_name;
00013
00014
00015
00016
00017
00018
00019
00020 if(!nh.hasParam("robot_name"))
00021 {
00022 ROS_WARN_STREAM("Robot name not defined. Default: " << "iri_wam");
00023 robot_name_="iri_wam";
00024 }
00025 else
00026 {
00027 nh.getParam("robot_name", r_name);
00028 robot_name_=(std::string)r_name;
00029 }
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055 }
00056
00057 bool WamDriver::openDriver(void)
00058 {
00059
00060 string input;
00061
00062 try{
00063 if(this->state_ != OPENED){
00064
00065 this->wam_ = new wamDriver();
00066 wam_->open();
00067 this->state_ = OPENED;
00068 ROS_INFO("Wam opened, press shift+idle and enter.");
00069 getchar();
00070
00071 wam_->create();
00072 ROS_INFO("Wam created, press shift+activate and press enter.");
00073 getchar();
00074 wam_->activate();
00075 return true;
00076 }else{
00077 ROS_ERROR("WAM was already opened!");
00078 return false;
00079 }
00080 }catch(const std::exception &e){
00081
00082 ROS_ERROR("Exception in openDriver");
00083 return false;
00084 }
00085 }
00086
00087 bool WamDriver::closeDriver(void)
00088 {
00089 wam_->close();
00090 ROS_INFO("[APP] Wait until wam gets home, idle the wam and press enter.");
00091 getchar();
00092 this->state_ = CLOSED;
00093 return true;
00094 }
00095
00096 bool WamDriver::startDriver(void)
00097 {
00098 try{
00099 wam_->setGravityCompensation(1.1);
00100 ROS_INFO("Switching to Running and going to default position.");
00101 wam_->goToDefaultPosition();
00102 ROS_INFO("Waiting final position reach");
00103 wam_->waitTillMotionDone();
00104 ROS_INFO("All is ready to work now!");
00105 wam_->setGravityCompensation(1.1);
00106 this->state_ = RUNNING;
00107 return true;
00108 }catch(const std::exception &e){
00109
00110 ROS_ERROR("Exception in startDriver");
00111 return false;
00112 }
00113 return true;
00114 }
00115
00116 bool WamDriver::stopDriver(void)
00117 {
00118
00119 wam_->home();
00120 wam_->waitTillMotionDone();
00121 this->state_ = OPENED;
00122 return true;
00123 }
00124
00125 void WamDriver::config_update(const Config& new_cfg, uint32_t level)
00126 {
00127 this->lock();
00128
00129 if(isRunning()){
00130
00131 this->config_=new_cfg;
00132 }else{
00133 ROS_ERROR("[WAM_DRIVER] config update while driver is not running yet");
00134 }
00135 this->unlock();
00136 }
00137
00138 WamDriver::~WamDriver()
00139 {
00140 std::cout << "WamDriver destructor" << std::endl;
00141 }
00142
00143 std::string WamDriver::get_robot_name() {
00144
00145 return this->robot_name_;
00146 }
00147
00148 int WamDriver::get_num_joints() {
00149 if(this->wam_!=NULL) {
00150 return NJOINTS;
00151 }
00152 return 0;
00153 }
00154
00155 bool WamDriver::is_moving() {
00156 if (this->wam_ != NULL) {
00157
00158 }
00159 return false;
00160 }
00161
00162 bool WamDriver::is_joint_trajectory_result_succeeded(){
00163 if (this->wam_ != NULL){
00164
00165
00166 ROS_INFO("joint_trajectory_result_succeeded: TRUE hardcoded");
00167 return true;
00168 }
00169 return false;
00170 }
00171
00172 void WamDriver::wait_move_end() {
00173 if(this->wam_!=NULL) {
00174 this->wam_->waitTillMotionDone();
00175 }
00176 }
00177
00178 void WamDriver::get_pose(std::vector<double> *pose) {
00179 if(this->wam_!=NULL) {
00180 this->wam_->getCartesianPose(pose);
00181 }
00182 }
00183
00184 void WamDriver::get_joint_angles(std::vector<double> *angles) {
00185 if(this->wam_!=NULL) {
00186 this->wam_->getJointAngles(angles);
00187 }
00188 }
00189
00190 bool WamDriver::is_joints_move_request_valid(const std::vector<double> & angles){
00191
00192 if (static_cast<signed int>(angles.size()) != get_num_joints()) {
00193 ROS_ERROR("Invalid request to move. Joint vector size is %i while the robot has %i joints",
00194 (int) angles.size(), get_num_joints());
00195 return false;
00196 }
00197
00198
00199 for (std::vector<double>::const_iterator it = angles.begin(); it != angles.end(); it++) {
00200
00201
00202 if (* it != * it) {
00203 ROS_ERROR("Invalid request to move. Joint vector contain a Nan value.");
00204 return false;
00205 }
00206 }
00207
00208 return true;
00209 }
00210
00211 void WamDriver::move_in_joints(std::vector<double> *angles, std::vector<double>* vels, std::vector<double>* accs){
00212 uint16_t errormask = 0x00;
00213
00214 if (this->wam_!=NULL) {
00215 if (! is_joints_move_request_valid(* angles)) {
00216 ROS_ERROR("Joints angles were not valid. Refuse to move.");
00217 return;
00218 }
00219
00220
00221 if ((vels == NULL) || (accs == NULL)) {
00222 wam_->moveInJoints(&errormask, angles);
00223 }
00224 else {
00225 wam_->moveInJoints(&errormask, angles, vels, accs);
00226 }
00227 if(errormask > 0x00){
00228
00229
00230 errormask = 0x00;
00231 }
00232 }
00233 }
00234
00235 void
00236 WamDriver::move_in_cartesian_pose(const geometry_msgs::Pose pose,const double vel,const double acc)
00237 {
00238 if (this->wam_ == NULL)
00239 return;
00240
00241 std::vector<double> low_level_pose;
00242 low_level_pose.push_back(pose.position.x);
00243 low_level_pose.push_back(pose.position.y);
00244 low_level_pose.push_back(pose.position.z);
00245 low_level_pose.push_back(pose.orientation.x);
00246 low_level_pose.push_back(pose.orientation.y);
00247 low_level_pose.push_back(pose.orientation.z);
00248 low_level_pose.push_back(pose.orientation.w);
00249
00250
00251 }
00252
00253 void
00254 WamDriver::hold_current_position(bool on)
00255 {
00256 if(this->wam_!=NULL){
00257 this->wam_->holdCurrentPosition(on);
00258 }
00259 }
00260
00261 trajectory_msgs::JointTrajectoryPoint WamDriver::get_desired_joint_trajectory_point()
00262 {
00263
00264 return desired_joint_trajectory_point_;
00265 }
00266
00267 void
00268 WamDriver::move_trajectory_in_joints(const trajectory_msgs::JointTrajectory & trajectory)
00269 {
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302 uint16_t errormask = 0x00;
00303 WAMPositionsJointTrajectory low_level_trajectory;
00304 std::vector<double> point_trajectory;
00305 ROS_INFO("Trajectory has no velocity data, %d", trajectory.points.begin()->velocities.size());
00306 if (trajectory.points.begin()->velocities.size()!=7)
00307 {
00308
00309 for (std::vector<trajectory_msgs::JointTrajectoryPoint>::const_iterator it = trajectory.points.begin();
00310 it != trajectory.points.end(); it++)
00311 {
00312 if (! is_joints_move_request_valid(it->positions)) {
00313 ROS_ERROR("Joints angles were not valid. Refuse to move.");
00314 return;
00315 }
00316 point_trajectory.clear();
00317 point_trajectory.insert(point_trajectory.end(),it->positions.begin(), it->positions.end());
00318 low_level_trajectory.push_back(point_trajectory);
00319 }
00320 this->wam_->moveTrajectoryInJoints(&errormask, &low_level_trajectory);
00321 }
00322 }
00323
00324 void
00325 WamDriver::stop_trajectory_in_joints()
00326 {
00327
00328 }
00329
00330 void
00331 WamDriver::move_trajectory_learnt_and_estimate_force(const std::string model_filename,
00332 const std::string points_filename)
00333 {
00334
00335
00336
00337
00338
00339 return;
00340 }
00341
00342 void
00343 WamDriver::start_dmp_tracker(const std::vector<double> * initial, const std::vector<double> * goal)
00344 {
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381 }
00382
00383 void
00384 WamDriver::dmp_tracker_new_goal(const std::vector<double> * new_goal)
00385 {
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405 }
00406
00407 void
00408 WamDriver::jnt_pos_cmd_callback(const std::vector<float> * joints,
00409 const std::vector<float> * rate_limits)
00410 {
00411
00412
00413
00414
00415
00416 }