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 #ifndef FLATHEADERS
00032 #include "simple_message/joint_data.h"
00033 #include "simple_message/shared_types.h"
00034 #include "simple_message/log_wrapper.h"
00035 #else
00036 #include "joint_data.h"
00037 #include "shared_types.h"
00038 #include "log_wrapper.h"
00039 #endif
00040
00041 using namespace industrial::shared_types;
00042
00043 namespace industrial
00044 {
00045 namespace joint_data
00046 {
00047
00048 JointData::JointData(void)
00049 {
00050 this->init();
00051 }
00052 JointData::~JointData(void)
00053 {
00054
00055 }
00056
00057 void JointData::init()
00058 {
00059 for (int i = 0; i < this->getMaxNumJoints(); i++)
00060 {
00061 this->setJoint(i, 0.0);
00062 }
00063 }
00064
00065 bool JointData::setJoint(shared_int index, shared_real value)
00066 {
00067 bool rtn = false;
00068
00069 if (index < this->getMaxNumJoints())
00070 {
00071 this->joints_[index] = value;
00072 rtn = true;
00073 }
00074 else
00075 {
00076 LOG_ERROR("Joint index: %d, is greater than size: %d", index, this->getMaxNumJoints());
00077 rtn = false;
00078 }
00079 return rtn;
00080 }
00081
00082 bool JointData::getJoint(shared_int index, shared_real & value) const
00083 {
00084 bool rtn = false;
00085
00086 if (index < this->getMaxNumJoints())
00087 {
00088 value = this->joints_[index];
00089 rtn = true;
00090 }
00091 else
00092 {
00093 LOG_ERROR("Joint index: %d, is greater than size: %d", index, this->getMaxNumJoints());
00094 rtn = false;
00095 }
00096 return rtn;
00097 }
00098
00099 shared_real JointData::getJoint(shared_int index) const
00100 {
00101 shared_real rtn = 0.0;
00102 this->getJoint(index, rtn);
00103 return rtn;
00104 }
00105
00106
00107 void JointData::copyFrom(JointData &src)
00108 {
00109 shared_real value = 0.0;
00110
00111 for (int i = 0; i < this->getMaxNumJoints(); i++)
00112 {
00113 src.getJoint(i, value);
00114 this->setJoint(i, value);
00115 }
00116 }
00117
00118 bool JointData::operator==(JointData &rhs)
00119 {
00120 bool rtn = true;
00121
00122 shared_real lhsvalue, rhsvalue;
00123
00124 for (int i = 0; i < this->getMaxNumJoints(); i++)
00125 {
00126 this->getJoint(i, lhsvalue);
00127 rhs.getJoint(i, rhsvalue);
00128 if (lhsvalue != rhsvalue)
00129 {
00130 rtn = false;
00131 break;
00132 }
00133 }
00134 return rtn;
00135
00136 }
00137
00138 bool JointData::load(industrial::byte_array::ByteArray *buffer)
00139 {
00140 bool rtn = false;
00141 shared_real value = 0.0;
00142
00143 LOG_COMM("Executing joint position load");
00144 for (int i = 0; i < this->getMaxNumJoints(); i++)
00145 {
00146 this->getJoint(i, value);
00147 rtn = buffer->load(value);
00148 if (!rtn)
00149 {
00150 LOG_ERROR("Failed to load joint position data");
00151 break;
00152 }
00153 }
00154 return rtn;
00155 }
00156
00157 bool JointData::unload(industrial::byte_array::ByteArray *buffer)
00158 {
00159 bool rtn = false;
00160 shared_real value = 0.0;
00161
00162 LOG_COMM("Executing joint position unload");
00163 for (int i = this->getMaxNumJoints() - 1; i >= 0; i--)
00164 {
00165 rtn = buffer->unload(value);
00166 if (!rtn)
00167 {
00168 LOG_ERROR("Failed to unload message joint: %d from data[%d]", i, buffer->getBufferSize());
00169 break;
00170 }
00171 this->setJoint(i, value);
00172 }
00173 return rtn;
00174 }
00175
00176 }
00177 }
00178