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 using std::min;           // MotoPlus provides min(), but not std::min()
00036 #define MAX_PULSE_AXES 8  // since MotoPlus.h is not availble in ROS
00037 #endif
00038 
00039 #ifdef MOTOPLUS
00040 #include "ros_conversion.h"
00041 #include "log_wrapper.h"
00042 #endif
00043 
00044 using namespace industrial::joint_data;
00045 
00046 namespace motoman
00047 {
00048 
00049 namespace ros_conversion
00050 {
00051 
00052 void toRosJoint(float* mp_joints, JointData & ros_joints)
00053 {
00054     // convert from float-array to JointData
00055     JointData temp;
00056     int minJoints = min(MAX_PULSE_AXES, ros_joints.getMaxNumJoints());
00057     for (int i=0; i<minJoints; ++i)
00058         temp.setJoint(i, mp_joints[i]);
00059         
00060     // re-order joints to ROS ordering (for known joint-pairs)
00061     ros_joints.copyFrom(temp);  // initialize to motoman ordering
00062     ros_joints.setJoint(RosJointIndexes::S, temp.getJoint(MotomanJointIndexes::S));
00063     ros_joints.setJoint(RosJointIndexes::L, temp.getJoint(MotomanJointIndexes::L));
00064     ros_joints.setJoint(RosJointIndexes::U, temp.getJoint(MotomanJointIndexes::U));
00065     ros_joints.setJoint(RosJointIndexes::R, temp.getJoint(MotomanJointIndexes::R));
00066     ros_joints.setJoint(RosJointIndexes::B, temp.getJoint(MotomanJointIndexes::B));
00067     ros_joints.setJoint(RosJointIndexes::T, temp.getJoint(MotomanJointIndexes::T));
00068     ros_joints.setJoint(RosJointIndexes::E, temp.getJoint(MotomanJointIndexes::E));
00069 }
00070 
00071 void toMpJoint(industrial::joint_data::JointData & ros_joints,
00072                                 float* mp_joints)
00073 {
00074     // re-order joints to MotoPlus ordering (for known joint-pairs)
00075     JointData temp;
00076     temp.copyFrom(ros_joints);
00077     temp.setJoint(MotomanJointIndexes::S, ros_joints.getJoint(RosJointIndexes::S));
00078     temp.setJoint(MotomanJointIndexes::L, ros_joints.getJoint(RosJointIndexes::L));
00079     temp.setJoint(MotomanJointIndexes::U, ros_joints.getJoint(RosJointIndexes::U));
00080     temp.setJoint(MotomanJointIndexes::R, ros_joints.getJoint(RosJointIndexes::R));
00081     temp.setJoint(MotomanJointIndexes::B, ros_joints.getJoint(RosJointIndexes::B));
00082     temp.setJoint(MotomanJointIndexes::T, ros_joints.getJoint(RosJointIndexes::T));
00083     temp.setJoint(MotomanJointIndexes::E, ros_joints.getJoint(RosJointIndexes::E));
00084 
00085     // convert from JointData to float-array
00086     memset(mp_joints, 0, MAX_PULSE_AXES*sizeof(float));  // initialize to zero
00087     int minJoints = min(MAX_PULSE_AXES, ros_joints.getMaxNumJoints());
00088     for (int i=0; i<minJoints; ++i)
00089         mp_joints[i] = temp.getJoint(i);
00090 }
00091 
00092                         
00093 void toRosJointOrder(JointData & joints)
00094 {
00095     //LOG_DEBUG("Swapping to ROS joint order");
00096     JointData swap;
00097     swap.setJoint(RosJointIndexes::S, joints.getJoint(MotomanJointIndexes::S));
00098     swap.setJoint(RosJointIndexes::L, joints.getJoint(MotomanJointIndexes::L));
00099     swap.setJoint(RosJointIndexes::U, joints.getJoint(MotomanJointIndexes::U));
00100     swap.setJoint(RosJointIndexes::R, joints.getJoint(MotomanJointIndexes::R));
00101     swap.setJoint(RosJointIndexes::B, joints.getJoint(MotomanJointIndexes::B));
00102     swap.setJoint(RosJointIndexes::T, joints.getJoint(MotomanJointIndexes::T));
00103     swap.setJoint(RosJointIndexes::E, joints.getJoint(MotomanJointIndexes::E));
00104     joints.copyFrom(swap);
00105 }
00106 
00107 void toMotomanJointOrder(JointData & joints)
00108 {
00109     //LOG_DEBUG("Swapping to motoman joint order");
00110     JointData swap;
00111     swap.setJoint(MotomanJointIndexes::S, joints.getJoint(RosJointIndexes::S));
00112     swap.setJoint(MotomanJointIndexes::L, joints.getJoint(RosJointIndexes::L));
00113     swap.setJoint(MotomanJointIndexes::U, joints.getJoint(RosJointIndexes::U));
00114     swap.setJoint(MotomanJointIndexes::R, joints.getJoint(RosJointIndexes::R));
00115     swap.setJoint(MotomanJointIndexes::B, joints.getJoint(RosJointIndexes::B));
00116     swap.setJoint(MotomanJointIndexes::T, joints.getJoint(RosJointIndexes::T));
00117     swap.setJoint(MotomanJointIndexes::E, joints.getJoint(RosJointIndexes::E));
00118     joints.copyFrom(swap);
00119 }
00120 
00121 } //ros_conversion
00122 } //motoman


dx100
Author(s): Shaun Edwards (Southwest Research Institute)
autogenerated on Mon Oct 6 2014 02:25:34