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 #ifdef ROS
00032 #include "simple_message/joint_traj.h"
00033 #include "simple_message/shared_types.h"
00034 #include "simple_message/log_wrapper.h"
00035 #endif
00036
00037 #ifdef MOTOPLUS
00038 #include "joint_traj.h"
00039 #include "shared_types.h"
00040 #include "log_wrapper.h"
00041 #endif
00042
00043 using namespace industrial::shared_types;
00044 using namespace industrial::joint_traj_pt;
00045
00046 namespace industrial
00047 {
00048 namespace joint_traj
00049 {
00050
00051 JointTraj::JointTraj(void)
00052 {
00053 this->init();
00054 }
00055 JointTraj::~JointTraj(void)
00056 {
00057
00058 }
00059
00060 void JointTraj::init()
00061 {
00062 JointTrajPt empty;
00063
00064 this->size_ = 0;
00065 for (shared_int i = 0; i < this->getMaxNumPoints(); i++)
00066 {
00067 this->points_[i].copyFrom(empty);
00068 }
00069 }
00070
00071 bool JointTraj::addPoint(JointTrajPt & point)
00072 {
00073 bool rtn = false;
00074
00075 if (!this->isFull())
00076 {
00077 this->points_[this->size()].copyFrom(point);
00078 this->size_++;
00079 rtn = true;
00080 }
00081 else
00082 {
00083 rtn = false;
00084 LOG_ERROR("Failed to add point, buffer is full");
00085 }
00086
00087 return rtn;
00088 }
00089
00090 bool JointTraj::getPoint(shared_int index, JointTrajPt & point)
00091 {
00092 bool rtn = false;
00093
00094 if (index < this->size())
00095 {
00096 point.copyFrom(this->points_[index]);
00097 rtn = true;
00098 }
00099 else
00100 {
00101 LOG_ERROR("Point index: %d, is greater than size: %d", index, this->size());
00102 rtn = false;
00103 }
00104 return rtn;
00105 }
00106
00107 void JointTraj::copyFrom(JointTraj &src)
00108 {
00109 JointTrajPt value;
00110
00111 this->size_ = src.size();
00112 for (shared_int i = 0; i < this->size(); i++)
00113 {
00114 src.getPoint(i, value);
00115 this->points_[i].copyFrom(value);
00116 }
00117 }
00118
00119 bool JointTraj::operator==(JointTraj &rhs)
00120 {
00121 bool rtn = true;
00122
00123 if(this->size() == rhs.size())
00124 {
00125 for(shared_int i = 0; i < this->size(); i++)
00126 {
00127 JointTrajPt value;
00128 rhs.getPoint(i, value);
00129 if(!(this->points_[i] == value))
00130 {
00131 LOG_DEBUG("Joint trajectory point different");
00132 rtn = false;
00133 break;
00134 }
00135 else
00136 {
00137 rtn = true;
00138 }
00139 }
00140 }
00141 else
00142 {
00143 LOG_DEBUG("Joint trajectory compare failed, size mismatch");
00144 rtn = false;
00145 }
00146
00147 return rtn;
00148 }
00149
00150
00151 bool JointTraj::load(industrial::byte_array::ByteArray *buffer)
00152 {
00153 bool rtn = false;
00154 JointTrajPt value;
00155
00156 LOG_COMM("Executing joint trajectory load");
00157 for (shared_int i = 0; i < this->size(); i++)
00158 {
00159 this->getPoint(i, value);
00160 rtn = buffer->load(value);
00161 if (!rtn)
00162 {
00163 LOG_ERROR("Failed to load joint traj.pt. data");
00164 rtn = false;
00165 break;
00166 }
00167 rtn = true;
00168 }
00169
00170 if (rtn)
00171 {
00172 rtn = buffer->load(this->size());
00173 }
00174 return rtn;
00175 }
00176
00177 bool JointTraj::unload(industrial::byte_array::ByteArray *buffer)
00178 {
00179 bool rtn = false;
00180 JointTrajPt value;
00181
00182 LOG_COMM("Executing joint trajectory unload");
00183
00184 rtn = buffer->unload(this->size_);
00185
00186 if(rtn)
00187 {
00188 for (int i = this->size() - 1; i >= 0; i--)
00189 {
00190 rtn = buffer->unload(value);
00191 if (!rtn)
00192 {
00193 LOG_ERROR("Failed to unload message point: %d from data[%d]", i, buffer->getBufferSize());
00194 break;
00195 }
00196 this->points_[i].copyFrom(value);
00197 }
00198 }
00199 else
00200 {
00201 LOG_ERROR("Failed to unload trajectory size");
00202 }
00203 return rtn;
00204 }
00205
00206 }
00207 }
00208