hand_description.cpp
Go to the documentation of this file.
00001 /*
00002  * hand_description.cpp
00003  *
00004  *  Created on: 2 Aug 2012
00005  *      Author: andreas
00006  */
00007 
00008 #include "tidyup_utils/hand_description.h"
00009 using std::string;
00010 using std::map;
00011 
00012 map<string, HandDescription> HandDescription::descriptions;
00013 
00014 const HandDescription& HandDescription::get(const std::string& arm_name)
00015 {
00016     map<string, HandDescription>::iterator it = descriptions.find(arm_name);
00017     if (it == descriptions.end())
00018     {
00019         descriptions.insert(make_pair(arm_name, HandDescription(arm_name)));
00020         it = descriptions.find(arm_name);
00021     }
00022     return it->second;
00023 }
00024 
00025 
00026 HandDescription::HandDescription(const std::string& arm) : armName(arm)
00027 {
00028     string prefix = armName.substr(0, 1);
00029     if( ! ros::param::get("/hand_description/"+armName+"/hand_group_name", handGroup))
00030     {
00031         handGroup = prefix + "_end_effector";
00032     }
00033 
00034     if( ! ros::param::get("/hand_description/"+armName+"/attach_link", attachLink))
00035     {
00036         attachLink = prefix + "_gripper_r_finger_tip_link";
00037     }
00038 
00039     if( ! ros::param::get("/hand_description/"+armName+"/hand_frame", handFrame))
00040     {
00041         handFrame = prefix + "_wrist_roll_link";
00042     }
00043 
00044     if( ! ros::param::get("/hand_description/"+armName+"/gripper_joint", gripperJoint))
00045     {
00046         gripperJoint = prefix + "_gripper_joint";
00047     }
00048 
00049     if( ! ros::param::get("/hand_description/"+armName+"/end_effector_length", endEffectorLength))
00050     {
00051         endEffectorLength = 0.18;
00052     }
00053 
00054     string paramPath = "/hand_description/"+armName+"/hand_links";
00055     if (ros::param::has(paramPath))
00056     {
00057         XmlRpc::XmlRpcValue paramList;
00058         ros::param::get(paramPath, paramList);
00059         ROS_ASSERT(paramList.getType() == XmlRpc::XmlRpcValue::TypeArray);
00060         for (int32_t i = 0; i < paramList.size(); ++i)
00061         {
00062             ROS_ASSERT(paramList[i].getType() == XmlRpc::XmlRpcValue::TypeString);
00063             handLinks.push_back(static_cast<string>(paramList[i]));
00064         }
00065     }
00066     else
00067     {
00068         handLinks.push_back(prefix+"_gripper_palm_link");
00069         handLinks.push_back(prefix+"_gripper_r_finger_tip_link");
00070         handLinks.push_back(prefix+"_gripper_l_finger_tip_link");
00071         handLinks.push_back(prefix+"_gripper_l_finger_link");
00072         handLinks.push_back(prefix+"_gripper_r_finger_link");
00073     }
00074 
00075     paramPath = "/hand_description/"+armName+"/hand_touch_links";
00076     if (ros::param::has(paramPath))
00077     {
00078         XmlRpc::XmlRpcValue paramList;
00079         ros::param::get(paramPath, paramList);
00080         ROS_ASSERT(paramList.getType() == XmlRpc::XmlRpcValue::TypeArray);
00081         for (int32_t i = 0; i < paramList.size(); ++i)
00082         {
00083             ROS_ASSERT(paramList[i].getType() == XmlRpc::XmlRpcValue::TypeString);
00084             touchLinks.push_back(static_cast<string>(paramList[i]));
00085         }
00086     }
00087     else
00088     {
00089         touchLinks = handLinks;
00090     }
00091 
00092     paramPath = "/hand_description/"+armName+"/hand_fingertip_links";
00093     if (ros::param::has(paramPath))
00094     {
00095         XmlRpc::XmlRpcValue paramList;
00096         ros::param::get(paramPath, paramList);
00097         ROS_ASSERT(paramList.getType() == XmlRpc::XmlRpcValue::TypeArray);
00098         for (int32_t i = 0; i < paramList.size(); ++i)
00099         {
00100             ROS_ASSERT(paramList[i].getType() == XmlRpc::XmlRpcValue::TypeString);
00101             fingerTipLinks.push_back(static_cast<string>(paramList[i]));
00102         }
00103     }
00104     else
00105     {
00106         fingerTipLinks.push_back(prefix+"_gripper_r_finger_tip_link");
00107         fingerTipLinks.push_back(prefix+"_gripper_l_finger_tip_link");
00108     }
00109 
00110     paramPath = "/hand_description/"+armName+"/hand_finger_links";
00111     if (ros::param::has(paramPath))
00112     {
00113         XmlRpc::XmlRpcValue paramList;
00114         ros::param::get(paramPath, paramList);
00115         ROS_ASSERT(paramList.getType() == XmlRpc::XmlRpcValue::TypeArray);
00116         for (int32_t i = 0; i < paramList.size(); ++i)
00117         {
00118             ROS_ASSERT(paramList[i].getType() == XmlRpc::XmlRpcValue::TypeString);
00119             fingerLinks.push_back(static_cast<string>(paramList[i]));
00120         }
00121     }
00122     else
00123     {
00124         fingerLinks.push_back(prefix+"_gripper_r_finger_tip_link");
00125         fingerLinks.push_back(prefix+"_gripper_l_finger_tip_link");
00126         fingerLinks.push_back(prefix+"_gripper_r_finger_link");
00127         fingerLinks.push_back(prefix+"_gripper_l_finger_link");
00128     }
00129 
00130     paramPath = "/hand_description/"+armName+"/hand_approach_direction";
00131     if (ros::param::has(paramPath))
00132     {
00133         XmlRpc::XmlRpcValue paramList;
00134         ros::param::get(paramPath, paramList);
00135         ROS_ASSERT(paramList.getType() == XmlRpc::XmlRpcValue::TypeArray);
00136         ROS_ASSERT(paramList.size() == 3);
00137         ROS_ASSERT(paramList[0].getType() == XmlRpc::XmlRpcValue::TypeDouble);
00138         approachDirection.x = static_cast<double>(paramList[0]);
00139         ROS_ASSERT(paramList[1].getType() == XmlRpc::XmlRpcValue::TypeDouble);
00140         approachDirection.y = static_cast<double>(paramList[1]);
00141         ROS_ASSERT(paramList[2].getType() == XmlRpc::XmlRpcValue::TypeDouble);
00142         approachDirection.z = static_cast<double>(paramList[2]);
00143     }
00144     else
00145     {
00146         approachDirection.x = 1.0;
00147         approachDirection.y = 0.0;
00148         approachDirection.z = 0.0;
00149     }
00150 }
00151 
00152 HandDescription::~HandDescription()
00153 {
00154 }
00155 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Friends


tidyup_utils
Author(s): Andreas Hertle
autogenerated on Wed Dec 26 2012 15:27:25