mp_wrapper.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 #include "mp_wrapper.h"
00033 #include "log_wrapper.h"
00034 #include "ros_conversion.h"
00035 #include "motoPlus.h"
00036 
00037 using namespace motoman::ros_conversion;
00038 
00039 namespace motoman
00040 {
00041 namespace mp_wrapper
00042 {
00043 
00044 
00045 //Writing mp data
00046 
00047 
00048 void setInteger(int index, int value)
00049 {
00050         MP_VAR_DATA data;
00051         
00052         data.usType = MP_RESTYPE_VAR_I;
00053         data.usIndex = index;
00054         data.ulValue = value;
00055         
00056         while (mpPutVarData ( &data, 1 ) == ERROR) 
00057         {
00058         LOG_ERROR("Failed to set integer varaible, index: %d, value: %d, retrying...", 
00059             data.usIndex, data.ulValue);
00060         mpTaskDelay(VAR_POLL_TICK_DELAY);
00061     }
00062 }
00063 
00064 int getInteger(int index)
00065 {
00066     
00067         MP_VAR_INFO info;
00068         LONG rtn;
00069         
00070         info.usType = MP_RESTYPE_VAR_I;
00071         info.usIndex = index;
00072         
00073         while (mpGetVarData ( &info, &rtn, 1 ) == ERROR) 
00074         {
00075         LOG_ERROR("Failed to retreive integer variable index: %d, retrying...", info.usIndex);
00076         mpTaskDelay(VAR_POLL_TICK_DELAY);
00077     }
00078     return rtn;
00079 }
00080 
00081 
00082 void getMotomanFbPos(JointData & pos)
00083 {
00084     LONG getPulseRtn = 0;
00085     
00086     MP_CTRL_GRP_SEND_DATA sData;
00087     MP_FB_PULSE_POS_RSP_DATA rData;
00088     
00089     // Get feedback for first robot
00090     sData.sCtrlGrp = 0;
00091         
00092     // Get pulse data from robot
00093     getPulseRtn = mpGetFBPulsePos (&sData,&rData);
00094     
00095     if (0 == getPulseRtn)
00096     {
00097         toJointData(rData, pos);
00098     }
00099     else
00100     {
00101         LOG_ERROR("Failed to get pulse feedback position: %u", getPulseRtn);
00102     }
00103 }
00104 
00105 
00106 void getRosFbPos(JointData & pos)
00107 {
00108     getMotomanFbPos(pos);
00109     toRosJointOrder(pos);
00110 }
00111 
00112 void toJointData(MP_FB_PULSE_POS_RSP_DATA & src, JointData & dest)
00113 {    
00114 
00115     int minJointSize = 0;
00116     int jointPosSize = dest.getMaxNumJoints();
00117     
00118     // Check for size constraints on Postion data
00119     if (MAX_PULSE_AXES >= jointPosSize)
00120     {
00121         LOG_WARN("Number of pulse axes: %u exceeds joint position size: %u",
00122             MAX_PULSE_AXES, dest.getMaxNumJoints());
00123     }
00124     
00125     // Determine which buffer is the smallest and only copy that many members
00126     if (jointPosSize > MAX_PULSE_AXES)
00127     {
00128         minJointSize = MAX_PULSE_AXES;
00129     }
00130     else
00131     {
00132         minJointSize = jointPosSize;
00133     }
00134     
00135     for(int i = 0; i < minJointSize; i++)
00136     {
00137           dest.setJoint(i, toRadians(src.lPos[i], (MotomanJointIndex)i));
00138     }
00139     
00140 }
00141 
00142 void toMpPosVarData(USHORT posVarIndex, JointData & src, MP_POSVAR_DATA & dest)
00143 {
00144   const int MOTOMAN_AXIS_SIZE = 8;
00145   LONG pulse_coords[MOTOMAN_AXIS_SIZE];
00146   
00147   motoman::ros_conversion::toMotomanJointOrder(src);
00148   for (int i = 0; i < MOTOMAN_AXIS_SIZE; i++)
00149   {
00150     pulse_coords[i] = motoman::ros_conversion::toPulses(src.getJoint(i), 
00151         (motoman::ros_conversion::MotomanJointIndex)i);
00152   }
00153   
00154   dest.usType = MP_RESTYPE_VAR_ROBOT;  // All joint positions are robot positions
00155   dest.usIndex = posVarIndex;          // Index within motoman position variable data table
00156   dest.ulValue[0] = 0;                 // Position is in pulse counts
00157   
00158   for (SHORT i = 0; i < MOTOMAN_AXIS_SIZE; i++)
00159   {
00160         dest.ulValue[i+2] = pulse_coords[i];  // First two values in ulValue reserved
00161   }
00162 }
00163 
00164 
00165 
00166 } //mp_wrapper
00167 } //motoman
00168 


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