ros_conversion.cpp
Go to the documentation of this file.
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 "dx100/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     case MotomanRobotModels::SIA_20D:
00081         LOG_INFO("SIA_20D: %d", model_number);
00082         S_PULSE_TO_RAD  = 58670.87822;      
00083         L_PULSE_TO_RAD  = 58670.87822;   
00084         U_PULSE_TO_RAD  = 58670.87822;      
00085         R_PULSE_TO_RAD  = 65841.76588;    
00086         B_PULSE_TO_RAD  = 65841.76588;    
00087         T_PULSE_TO_RAD  = 33246.8329;     
00088         E_PULSE_TO_RAD  = 58670.87822;  
00089         break;
00090     
00091     default:
00092         LOG_ERROR("Failed to initialize conversion factors for model: %d", model_number);
00093         break;
00094     }
00095 }
00096 
00097 
00098 
00099 float toPulses(float radians, MotomanJointIndex joint)
00100 {
00101     float rtn = 0.0;
00102     switch (joint)
00103     {
00104       case MotomanJointIndexes::S:
00105          rtn = radians * S_PULSE_TO_RAD;
00106          break;
00107          
00108       case MotomanJointIndexes::L:
00109          rtn = radians * L_PULSE_TO_RAD;
00110          break;
00111          
00112       case MotomanJointIndexes::U:
00113          rtn = radians * U_PULSE_TO_RAD;
00114          break;
00115          
00116       case MotomanJointIndexes::R:
00117          rtn = radians * R_PULSE_TO_RAD;
00118          break;
00119          
00120       case MotomanJointIndexes::B:
00121          rtn = radians * B_PULSE_TO_RAD;
00122          break;
00123          
00124       case MotomanJointIndexes::T:
00125          rtn = radians * T_PULSE_TO_RAD;
00126          break;
00127          
00128       case MotomanJointIndexes::E:
00129          rtn = radians * E_PULSE_TO_RAD;
00130          break;
00131          
00132       default:
00133         rtn = radians;
00134     }
00135         return rtn;
00136 }
00137 
00138 float toRadians(float pulses, MotomanJointIndex joint)
00139 {
00140     float rtn = 0.0;
00141     switch (joint)
00142     {
00143       case MotomanJointIndexes::S:
00144          rtn = pulses / S_PULSE_TO_RAD;
00145          break;
00146          
00147       case MotomanJointIndexes::L:
00148          rtn = pulses / L_PULSE_TO_RAD;
00149          break;
00150          
00151       case MotomanJointIndexes::U:
00152          rtn = pulses / U_PULSE_TO_RAD;
00153          break;
00154          
00155       case MotomanJointIndexes::R:
00156          rtn = pulses / R_PULSE_TO_RAD;
00157          break;
00158          
00159       case MotomanJointIndexes::B:
00160          rtn = pulses / B_PULSE_TO_RAD;
00161          break;
00162          
00163       case MotomanJointIndexes::T:
00164          rtn = pulses / T_PULSE_TO_RAD;
00165          break;
00166          
00167       case MotomanJointIndexes::E:
00168          rtn = pulses / E_PULSE_TO_RAD;
00169          break;
00170          
00171       default:
00172         rtn = pulses;
00173     }
00174         return rtn;
00175 }
00176 
00177 void toRosJoint(industrial::joint_data::JointData & mp_joints, 
00178                                 industrial::joint_data::JointData & ros_joints)
00179 {
00180 
00181         ros_joints.copyFrom(mp_joints);
00182         // joints still in motoplus order for conversion
00183         for (int i = 0; i < ros_joints.getMaxNumJoints() ; i++)
00184         {
00185                 ros_joints.setJoint(i, toRadians(ros_joints.getJoint(i), 
00186                                                         (MotomanJointIndex)i));
00187         }
00188         toRosJointOrder(ros_joints);
00189 }
00190 
00191 void toMpJoint(industrial::joint_data::JointData & ros_joints,
00192                                 industrial::joint_data::JointData & mp_joints)
00193 {
00194 
00195         mp_joints.copyFrom(ros_joints);
00196         toMotomanJointOrder(mp_joints);
00197         // joints in motoplus order for conversion
00198         for (int i = 0; i < mp_joints.getMaxNumJoints() ; i++)
00199         {
00200                 ros_joints.setJoint(i, toPulses(mp_joints.getJoint(i), 
00201                                                 (MotomanJointIndex)i));
00202         }
00203 }
00204 
00205                         
00206 void toRosJointOrder(JointData & joints)
00207 {
00208     //LOG_DEBUG("Swapping to ROS joint order");
00209     JointData swap;
00210     swap.setJoint(RosJointIndexes::S, joints.getJoint(MotomanJointIndexes::S));
00211     swap.setJoint(RosJointIndexes::L, joints.getJoint(MotomanJointIndexes::L));
00212     swap.setJoint(RosJointIndexes::U, joints.getJoint(MotomanJointIndexes::U));
00213     swap.setJoint(RosJointIndexes::R, joints.getJoint(MotomanJointIndexes::R));
00214     swap.setJoint(RosJointIndexes::B, joints.getJoint(MotomanJointIndexes::B));
00215     swap.setJoint(RosJointIndexes::T, joints.getJoint(MotomanJointIndexes::T));
00216     swap.setJoint(RosJointIndexes::E, joints.getJoint(MotomanJointIndexes::E));
00217     joints.copyFrom(swap);
00218 }
00219 
00220 void toMotomanJointOrder(JointData & joints)
00221 {
00222     //LOG_DEBUG("Swapping to motoman joint order");
00223     JointData swap;
00224     swap.setJoint(MotomanJointIndexes::S, joints.getJoint(RosJointIndexes::S));
00225     swap.setJoint(MotomanJointIndexes::L, joints.getJoint(RosJointIndexes::L));
00226     swap.setJoint(MotomanJointIndexes::U, joints.getJoint(RosJointIndexes::U));
00227     swap.setJoint(MotomanJointIndexes::R, joints.getJoint(RosJointIndexes::R));
00228     swap.setJoint(MotomanJointIndexes::B, joints.getJoint(RosJointIndexes::B));
00229     swap.setJoint(MotomanJointIndexes::T, joints.getJoint(RosJointIndexes::T));
00230     swap.setJoint(MotomanJointIndexes::E, joints.getJoint(RosJointIndexes::E));
00231     joints.copyFrom(swap);
00232 }
00233 
00234 } //ros_conversion
00235 } //motoman


dx100
Author(s): Shaun Edwards (Southwest Research Institute)
autogenerated on Thu Jan 2 2014 11:29:36