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 "p_var_q.h"
00033 #include "joint_data.h"
00034 #include "joint_motion_handler.h"
00035 #include "ros_conversion.h"
00036 #include "log_wrapper.h"
00037 #include "mp_wrapper.h"
00038
00039 using motoman::joint_motion_handler;
00040 using motoman::ros_conversion;
00041 using industrial::joint_data;
00042
00043
00044 namespace motoman
00045 {
00046 namespace p_var_q
00047 {
00048
00049
00050 PVarQ::PVarQ()
00051 {
00052
00053
00054 pointData_.usType = MP_RESTYPE_VAR_ROBOT;
00055
00056
00057
00058
00059
00060 STATIC_ASSERT(QSIZE_ > PT_LOOK_AHEAD_, QSIZE_NOT_GREATER_THAN_LOOK_AHEAD);
00061 STATIC_ASSERT(MOTION_POINTER_ > QSIZE_, MOTION_PONTER_NOT_GREATER_THAN_QSIZE);
00062 STATIC_ASSERT(BUFFER_POINTER_ > QSIZE_, BUFFER_PONTER_NOT_GREATER_THAN_QSIZE);
00063 STATIC_ASSERT(MIN_BUF_START_POINTER_ > QSIZE_, MIN_BUFF_START_PONTER_NOT_GREATER_THAN_QSIZE);
00064
00065 }
00066
00067 PVarQ::~PVarQ(void)
00068 {
00069 }
00070
00071
00072 void PVarQ::init(industrial::joint_data::JointData & point, double velocity_percent)
00073 {
00074
00075
00076 industrial::joint_data::JointData empty;
00077 for(int i = 0; i < this->posVarQueueSize(); i++)
00078 {
00079 this->setPosition(i, empty, 0);
00080 }
00081
00082
00083
00084 setPosition(0, point, this->TEMP_getVelocityPercent());
00085
00086
00087 motoman::mp_wrapper::setInteger(MIN_BUF_START_POINTER_, PT_LOOK_AHEAD_);
00088 }
00089
00090 void PVarQ::addPoint(industrial::joint_data::JointData & joints, double velocity_percent)
00091 {
00092
00093
00094
00095 LOG_DEBUG("Checking for buffer full");
00096 while(this->bufferFull()) {
00097 mpTaskDelay(this->BUFFER_POLL_TICK_DELAY_);
00098 };
00099 LOG_DEBUG("Buffer ready to accept new points");
00100
00101 setNextPosition(joints, this->TEMP_getVelocityPercent());
00102 incBufferIndex();
00103
00104 }
00105
00106 int PVarQ::bufferSize()
00107 {
00108 int motionIdx = this->getMotionIndex();
00109 int bufferIdx = this->getBufferIndex();
00110 int rtn = 0;
00111
00112 if (motionIdx > bufferIdx)
00113 {
00114 LOG_ERROR("Motion index: %d is greater than Buffer index: %d, returning empty buffer size", motionIdx, bufferIdx);
00115 rtn = 0;
00116 }
00117 else
00118 {
00119 rtn = bufferIdx - motionIdx;
00120 }
00121
00122 return rtn;
00123 }
00124
00125
00126
00127 int PVarQ::getMotionPosIndex()
00128 {
00129 return (this->getMotionIndex() % this->posVarQueueSize());
00130 }
00131
00132 int PVarQ::getBufferPosIndex()
00133 {
00134 return (this->getBufferIndex() % this->posVarQueueSize());
00135 }
00136
00137 int PVarQ::getNextBufferPosIndex()
00138 {
00139 return ((this->getBufferIndex() + 1) % this->posVarQueueSize());
00140 }
00141
00142 bool PVarQ::bufferFull()
00143 {
00144 bool rtn = false;
00145 int bufferSize = this->bufferSize();
00146 int maxBufferSize = this->maxBufferSize();
00147 if (bufferSize >= maxBufferSize)
00148 {
00149 rtn = true;
00150 }
00151 return rtn;
00152 }
00153
00154 bool PVarQ::bufferEmpty()
00155 {
00156 bool rtn = false;
00157 if (this->bufferSize() <= 0)
00158 {
00159 LOG_DEBUG("Buffer is empty");
00160 rtn = true;
00161 }
00162 return rtn;
00163 }
00164
00165 void PVarQ::incBufferIndex()
00166 {
00167 int bufferIdx = this->getBufferIndex();
00168
00169 LOG_DEBUG("Incrementing buffer index from %d to %d", bufferIdx, bufferIdx + 1);
00170 motoman::mp_wrapper::setInteger(BUFFER_POINTER_, bufferIdx + 1);
00171 }
00172
00173
00174 void PVarQ::setNextPosition(industrial::joint_data::JointData & point, double velocity_percent)
00175 {
00176 setPosition(this->getNextBufferPosIndex(), point, velocity_percent);
00177 }
00178
00179
00180 void PVarQ::setPosition(int index, industrial::joint_data::JointData & point,
00181 double velocity_percent)
00182 {
00183 const double VELOCITY_CONVERSION = 100.0;
00184 int convertedVelocity = 0;
00185
00186 LOG_DEBUG("Setting joint position, index: %d", index);
00187 motoman::mp_wrapper::toMpPosVarData(index, point, this->pointData_);
00188
00189 while (mpPutPosVarData ( &(this->pointData_), 1 ) == ERROR) {
00190 LOG_ERROR("Failed set position variable, index: %d, retrying...", index);
00191 mpTaskDelay(this->VAR_POLL_TICK_DELAY_);
00192 };
00193
00194 convertedVelocity = (int)(velocity_percent * VELOCITY_CONVERSION);
00195 LOG_DEBUG("Converting percent velocity: %g to motoman integer value: %d",
00196 velocity_percent, convertedVelocity);
00197 LOG_DEBUG("Setting velocity, index: %d, value: %d", index, convertedVelocity);
00198 motoman::mp_wrapper::setInteger(index, convertedVelocity);
00199 }
00200
00201
00202
00203 }
00204 }