sr_hand_finder.cpp
Go to the documentation of this file.
00001 /*
00002 * File:  sf_hand_finder.cpp
00003 * Author: Vahid Aminzadeh <vahid@shadowrobot.com>
00004 * Copyright 2015 Shadow Robot Company Ltd.
00005 *
00006 * This program is free software: you can redistribute it and/or modify it
00007 * under the terms of the GNU General Public License as published by the Free
00008 * Software Foundation, either version 2 of the License, or (at your option)
00009 * any later version.
00010 *
00011 * This program is distributed in the hope that it will be useful, but WITHOUT
00012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00013 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
00014 * more details.
00015 *
00016 * You should have received a copy of the GNU General Public License along
00017 * with this program.  If not, see <http://www.gnu.org/licenses/>.
00018 *
00019 * @brief see README.md
00020 */
00021 
00022 #include "sr_utilities/sr_hand_finder.hpp"
00023 #include "ros/ros.h"
00024 #include <vector>
00025 #include <string>
00026 #include <iostream>
00027 #include <map>
00028 #include <ros/package.h>
00029 
00030 using std::string;
00031 using std::map;
00032 using std::vector;
00033 namespace shadow_robot
00034 {
00035 const size_t SrHandFinder::number_of_joints_ = 20;
00036 const char* SrHandFinder::joint_names_[] = {"FFJ1", "FFJ2", "FFJ3", "FFJ4", "MFJ1", "MFJ2", "MFJ3", "MFJ4",
00037                                             "RFJ1", "RFJ2", "RFJ3", "RFJ4", "LFJ1", "LFJ2", "LFJ3", "LFJ4",
00038                                             "LFJ5", "THJ1", "THJ2", "THJ3", "THJ4", "THJ5", "WRJ1", "WRJ2"};
00039 SrHandFinder::SrHandFinder()
00040 {
00041   map<string, string> mapping_map;
00042   ros::param::get("hand/mapping", hand_config_.mapping_);
00043   ros::param::get("hand/joint_prefix", hand_config_.joint_prefix_);
00044 
00045   for (map<string, string>::const_iterator iter = hand_config_.mapping_.begin();
00046       iter != hand_config_.mapping_.end(); ++iter)
00047   {
00048     ROS_INFO_STREAM("detected hands are \n" << "hand serial:" << iter->first << " hand_id:" << iter->second);
00049   }
00050   generate_joints_with_prefix();
00051   generate_calibration_path();
00052   generate_hand_controller_tuning_path();
00053 }
00054 void SrHandFinder::generate_joints_with_prefix()
00055 {
00056   for (map<string, string>::const_iterator prefix_iter = hand_config_.joint_prefix_.begin();
00057       prefix_iter != hand_config_.joint_prefix_.end(); ++prefix_iter)
00058   {
00059     joints_[prefix_iter->second].resize(number_of_joints_);
00060     for (size_t joint_counter = 0; joint_counter != number_of_joints_; ++joint_counter)
00061     {
00062       joints_[prefix_iter->second][joint_counter] = prefix_iter->second + joint_names_[joint_counter];
00063     }
00064   }
00065 }
00066 void SrHandFinder::generate_calibration_path()
00067 {
00068   string ethercat_path = ros::package::getPath("sr_ethercat_hand_config");
00069   for (map<string, string>::const_iterator mapping_iter = hand_config_.mapping_.begin();
00070       mapping_iter != hand_config_.mapping_.end(); ++mapping_iter)
00071   {
00072     calibration_path_[mapping_iter->second] = ethercat_path + "/calibrations/"
00073         + mapping_iter->second + "/" + "calibration.yaml";
00074   }
00075 }
00076 void SrHandFinder::generate_hand_controller_tuning_path()
00077 {
00078   string ethercat_path = ros::package::getPath("sr_ethercat_hand_config");
00079   for (map<string, string>::const_iterator mapping_iter = hand_config_.mapping_.begin();
00080         mapping_iter != hand_config_.mapping_.end(); ++mapping_iter)
00081   {
00082     hand_controller_tuning_.friction_compensation_[mapping_iter->second] =
00083         ethercat_path + "/controls/" + "friction_compensation.yaml";
00084     hand_controller_tuning_.motor_control_[mapping_iter->second] =
00085         ethercat_path + "/controls/motors/" + mapping_iter->second + "/motor_board_effort_controllers.yaml";
00086     string host_path(ethercat_path + "/controls/host/" + mapping_iter->second + "/");
00087     hand_controller_tuning_.host_control_[mapping_iter->second].push_back(
00088         host_path + "sr_edc_calibration_controllers.yaml");
00089     hand_controller_tuning_.host_control_[mapping_iter->second].push_back(
00090         host_path + "sr_edc_joint_velocity_controllers_PWM.yaml");
00091     hand_controller_tuning_.host_control_[mapping_iter->second].push_back(
00092         host_path + "sr_edc_effort_controllers_PWM.yaml");
00093     hand_controller_tuning_.host_control_[mapping_iter->second].push_back(
00094         host_path + "sr_edc_joint_velocity_controllers.yaml");
00095     hand_controller_tuning_.host_control_[mapping_iter->second].push_back(
00096         host_path + "sr_edc_effort_controllers.yaml");
00097 
00098     hand_controller_tuning_.host_control_[mapping_iter->second].push_back(
00099         host_path + "sr_edc_mixed_position_velocity_joint_controllers_PWM.yaml");
00100     hand_controller_tuning_.host_control_[mapping_iter->second].push_back(
00101         host_path + "sr_edc_joint_position_controllers_PWM.yaml");
00102     hand_controller_tuning_.host_control_[mapping_iter->second].push_back(
00103         host_path + "sr_edc_mixed_position_velocity_joint_controllers.yaml");
00104     hand_controller_tuning_.host_control_[mapping_iter->second].push_back(
00105         host_path + "sr_edc_joint_position_controllers.yaml");
00106   }
00107 }
00108 map<string, vector<string> > SrHandFinder::get_joints()
00109 {
00110   return joints_;
00111 }
00112 map<string, string> SrHandFinder::get_calibration_path()
00113 {
00114   return calibration_path_;
00115 }
00116 HandControllerTuning SrHandFinder::get_hand_controller_tuning()
00117 {
00118   return hand_controller_tuning_;
00119 }
00120 } /* namespace shadow_robot */


sr_utilities
Author(s): Ugo Cupcic
autogenerated on Fri Aug 21 2015 12:24:47