$search
00001 /* 00002 * Software License Agreement (BSD License) 00003 * 00004 * Copyright (c) 2011, Southwest Research Institute 00005 * All rights reserved. 00006 * 00007 * Redistribution and use in source and binary forms, with or without 00008 * modification, are permitted provided that the following conditions are met: 00009 * 00010 * * Redistributions of source code must retain the above copyright 00011 * notice, this list of conditions and the following disclaimer. 00012 * * Redistributions in binary form must reproduce the above copyright 00013 * notice, this list of conditions and the following disclaimer in the 00014 * documentation and/or other materials provided with the distribution. 00015 * * Neither the name of the Southwest Research Institute, nor the names 00016 * of its contributors may be used to endorse or promote products derived 00017 * from this software without specific prior written permission. 00018 * 00019 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00020 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00021 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00022 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 00023 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00024 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00025 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00026 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00027 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00028 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00029 * POSSIBILITY OF SUCH DAMAGE. 00030 */ 00031 00032 #ifdef ROS 00033 #include "ros_conversion.h" 00034 #include "simple_message/log_wrapper.h" 00035 #endif 00036 00037 #ifdef MOTOPLUS 00038 #include "ros_conversion.h" 00039 #include "log_wrapper.h" 00040 #endif 00041 00042 using namespace industrial::joint_data; 00043 00044 namespace motoman 00045 { 00046 00047 namespace ros_conversion 00048 { 00049 00050 00051 // Pulse to radian conversion factors (initialized on startup) 00052 float S_PULSE_TO_RAD = 0; // pulses/rad 00053 float L_PULSE_TO_RAD = 0; // pulses/rad 00054 float U_PULSE_TO_RAD = 0; // pulses/rad 00055 float R_PULSE_TO_RAD = 0; // pulses/rad 00056 float B_PULSE_TO_RAD = 0; // pulses/rad 00057 float T_PULSE_TO_RAD = 0; // pulses/rad 00058 float E_PULSE_TO_RAD = 0; // pulses/rad 00059 00060 00061 00062 00063 void initJointConversion(MotomanRobotModel model_number) 00064 { 00065 00066 LOG_INFO("Initializing joint conversion factors for: "); 00067 switch (model_number) 00068 { 00069 case MotomanRobotModels::SIA_10D: 00070 LOG_INFO("SIA_10D: %d", model_number); 00071 S_PULSE_TO_RAD = 58670.87822; 00072 L_PULSE_TO_RAD = 58670.87822; 00073 U_PULSE_TO_RAD = 65841.76588; 00074 R_PULSE_TO_RAD = 65841.76588; 00075 B_PULSE_TO_RAD = 65841.76588; 00076 T_PULSE_TO_RAD = 33246.8329; 00077 E_PULSE_TO_RAD = 65841.76588; 00078 break; 00079 00080 default: 00081 LOG_ERROR("Failed to initialize conversion factors for model: %d", model_number); 00082 break; 00083 } 00084 } 00085 00086 00087 00088 float toPulses(float radians, MotomanJointIndex joint) 00089 { 00090 float rtn = 0.0; 00091 switch (joint) 00092 { 00093 case MotomanJointIndexes::S: 00094 rtn = radians * S_PULSE_TO_RAD; 00095 break; 00096 00097 case MotomanJointIndexes::L: 00098 rtn = radians * L_PULSE_TO_RAD; 00099 break; 00100 00101 case MotomanJointIndexes::U: 00102 rtn = radians * U_PULSE_TO_RAD; 00103 break; 00104 00105 case MotomanJointIndexes::R: 00106 rtn = radians * R_PULSE_TO_RAD; 00107 break; 00108 00109 case MotomanJointIndexes::B: 00110 rtn = radians * B_PULSE_TO_RAD; 00111 break; 00112 00113 case MotomanJointIndexes::T: 00114 rtn = radians * T_PULSE_TO_RAD; 00115 break; 00116 00117 case MotomanJointIndexes::E: 00118 rtn = radians * E_PULSE_TO_RAD; 00119 break; 00120 00121 default: 00122 rtn = radians; 00123 } 00124 return rtn; 00125 } 00126 00127 float toRadians(float pulses, MotomanJointIndex joint) 00128 { 00129 float rtn = 0.0; 00130 switch (joint) 00131 { 00132 case MotomanJointIndexes::S: 00133 rtn = pulses / S_PULSE_TO_RAD; 00134 break; 00135 00136 case MotomanJointIndexes::L: 00137 rtn = pulses / L_PULSE_TO_RAD; 00138 break; 00139 00140 case MotomanJointIndexes::U: 00141 rtn = pulses / U_PULSE_TO_RAD; 00142 break; 00143 00144 case MotomanJointIndexes::R: 00145 rtn = pulses / R_PULSE_TO_RAD; 00146 break; 00147 00148 case MotomanJointIndexes::B: 00149 rtn = pulses / B_PULSE_TO_RAD; 00150 break; 00151 00152 case MotomanJointIndexes::T: 00153 rtn = pulses / T_PULSE_TO_RAD; 00154 break; 00155 00156 case MotomanJointIndexes::E: 00157 rtn = pulses / E_PULSE_TO_RAD; 00158 break; 00159 00160 default: 00161 rtn = pulses; 00162 } 00163 return rtn; 00164 } 00165 00166 void toRosJoint(industrial::joint_data::JointData & mp_joints, 00167 industrial::joint_data::JointData & ros_joints) 00168 { 00169 00170 ros_joints.copyFrom(mp_joints); 00171 // joints still in motoplus order for conversion 00172 for (int i = 0; i < ros_joints.getMaxNumJoints() ; i++) 00173 { 00174 ros_joints.setJoint(i, toRadians(ros_joints.getJoint(i), 00175 (MotomanJointIndex)i)); 00176 } 00177 toRosJointOrder(ros_joints); 00178 } 00179 00180 void toMpJoint(industrial::joint_data::JointData & ros_joints, 00181 industrial::joint_data::JointData & mp_joints) 00182 { 00183 00184 mp_joints.copyFrom(ros_joints); 00185 toMotomanJointOrder(mp_joints); 00186 // joints in motoplus order for conversion 00187 for (int i = 0; i < mp_joints.getMaxNumJoints() ; i++) 00188 { 00189 ros_joints.setJoint(i, toPulses(mp_joints.getJoint(i), 00190 (MotomanJointIndex)i)); 00191 } 00192 } 00193 00194 00195 void toRosJointOrder(JointData & joints) 00196 { 00197 //LOG_DEBUG("Swapping to ROS joint order"); 00198 JointData swap; 00199 swap.setJoint(RosJointIndexes::S, joints.getJoint(MotomanJointIndexes::S)); 00200 swap.setJoint(RosJointIndexes::L, joints.getJoint(MotomanJointIndexes::L)); 00201 swap.setJoint(RosJointIndexes::U, joints.getJoint(MotomanJointIndexes::U)); 00202 swap.setJoint(RosJointIndexes::R, joints.getJoint(MotomanJointIndexes::R)); 00203 swap.setJoint(RosJointIndexes::B, joints.getJoint(MotomanJointIndexes::B)); 00204 swap.setJoint(RosJointIndexes::T, joints.getJoint(MotomanJointIndexes::T)); 00205 swap.setJoint(RosJointIndexes::E, joints.getJoint(MotomanJointIndexes::E)); 00206 joints.copyFrom(swap); 00207 } 00208 00209 void toMotomanJointOrder(JointData & joints) 00210 { 00211 //LOG_DEBUG("Swapping to motoman joint order"); 00212 JointData swap; 00213 swap.setJoint(MotomanJointIndexes::S, joints.getJoint(RosJointIndexes::S)); 00214 swap.setJoint(MotomanJointIndexes::L, joints.getJoint(RosJointIndexes::L)); 00215 swap.setJoint(MotomanJointIndexes::U, joints.getJoint(RosJointIndexes::U)); 00216 swap.setJoint(MotomanJointIndexes::R, joints.getJoint(RosJointIndexes::R)); 00217 swap.setJoint(MotomanJointIndexes::B, joints.getJoint(RosJointIndexes::B)); 00218 swap.setJoint(MotomanJointIndexes::T, joints.getJoint(RosJointIndexes::T)); 00219 swap.setJoint(MotomanJointIndexes::E, joints.getJoint(RosJointIndexes::E)); 00220 joints.copyFrom(swap); 00221 } 00222 00223 } //ros_conversion 00224 } //motoman