Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
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
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
00090 sData.sCtrlGrp = 0;
00091
00092
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
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
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;
00155 dest.usIndex = posVarIndex;
00156 dest.ulValue[0] = 0;
00157
00158 for (SHORT i = 0; i < MOTOMAN_AXIS_SIZE; i++)
00159 {
00160 dest.ulValue[i+2] = pulse_coords[i];
00161 }
00162 }
00163
00164
00165
00166 }
00167 }
00168