joint_data.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 #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 


simple_message
Author(s): Shaun Edwards
autogenerated on Sat Jun 8 2019 20:43:23