joint_feedback.cpp
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  * Copyright (c) 2013, 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_feedback.h"
00033 #include "simple_message/shared_types.h"
00034 #include "simple_message/log_wrapper.h"
00035 #else
00036 #include "joint_feedback.h"
00037 #include "shared_types.h"
00038 #include "log_wrapper.h"
00039 #endif
00040 
00041 using namespace industrial::joint_data;
00042 using namespace industrial::shared_types;
00043 
00044 namespace industrial
00045 {
00046 namespace joint_feedback
00047 {
00048 
00049 JointFeedback::JointFeedback(void)
00050 {
00051   this->init();
00052 }
00053 JointFeedback::~JointFeedback(void)
00054 {
00055 
00056 }
00057 
00058 void JointFeedback::init()
00059 {
00060   this->robot_id_ = 0;
00061   this->valid_fields_ = 0;
00062   this->time_ = 0.0;
00063   this->positions_.init();
00064   this->velocities_.init();
00065   this->accelerations_.init();
00066 }
00067 
00068 void JointFeedback::init(industrial::shared_types::shared_int robot_id,
00069           industrial::shared_types::shared_int valid_fields,
00070           industrial::shared_types::shared_real time,
00071           industrial::joint_data::JointData & positions,
00072           industrial::joint_data::JointData & velocities,
00073           industrial::joint_data::JointData & accelerations)
00074 {
00075   this->setRobotID(robot_id);
00076   this->setTime(time);
00077   this->setPositions(positions);
00078   this->setVelocities(velocities);
00079   this->setAccelerations(accelerations);
00080   this->valid_fields_ = valid_fields;  // must happen after others are set
00081 }
00082 
00083 void JointFeedback::copyFrom(JointFeedback &src)
00084 {
00085   this->setRobotID(src.getRobotID());
00086   src.getTime(this->time_);
00087   src.getPositions(this->positions_);
00088   src.getVelocities(this->velocities_);
00089   src.getAccelerations(this->accelerations_);
00090   this->valid_fields_ = src.valid_fields_;
00091 }
00092 
00093 bool JointFeedback::operator==(JointFeedback &rhs)
00094 {
00095   return this->robot_id_ == rhs.robot_id_ &&
00096          this->valid_fields_ == rhs.valid_fields_ &&
00097          ( !is_valid(ValidFieldTypes::TIME) || (this->time_ == rhs.time_) ) &&
00098          ( !is_valid(ValidFieldTypes::POSITION) || (this->positions_ == rhs.positions_) ) &&
00099          ( !is_valid(ValidFieldTypes::VELOCITY) || (this->velocities_ == rhs.velocities_) ) &&
00100          ( !is_valid(ValidFieldTypes::ACCELERATION) || (this->accelerations_ == rhs.accelerations_) );
00101 }
00102 
00103 bool JointFeedback::load(industrial::byte_array::ByteArray *buffer)
00104 {
00105   LOG_COMM("Executing joint feedback load");
00106 
00107   if (!buffer->load(this->robot_id_))
00108   {
00109     LOG_ERROR("Failed to load joint feedback robot_id");
00110     return false;
00111   }
00112 
00113   if (!buffer->load(this->valid_fields_))
00114   {
00115     LOG_ERROR("Failed to load joint feedback valid fields");
00116     return false;
00117   }
00118 
00119   if (!buffer->load(this->time_))
00120   {
00121     LOG_ERROR("Failed to load joint feedback time");
00122     return false;
00123   }
00124 
00125   if (!this->positions_.load(buffer))
00126   {
00127     LOG_ERROR("Failed to load joint feedback positions");
00128     return false;
00129   }
00130 
00131   if (!this->velocities_.load(buffer))
00132   {
00133     LOG_ERROR("Failed to load joint feedback velocities");
00134     return false;
00135   }
00136 
00137   if (!this->accelerations_.load(buffer))
00138   {
00139     LOG_ERROR("Failed to load joint feedback accelerations");
00140     return false;
00141   }
00142 
00143   LOG_COMM("Joint feedback successfully loaded");
00144   return true;
00145 }
00146 
00147 bool JointFeedback::unload(industrial::byte_array::ByteArray *buffer)
00148 {
00149   LOG_COMM("Executing joint feedback unload");
00150 
00151   if (!this->accelerations_.unload(buffer))
00152   {
00153     LOG_ERROR("Failed to unload joint feedback accelerations");
00154     return false;
00155   }
00156 
00157   if (!this->velocities_.unload(buffer))
00158   {
00159     LOG_ERROR("Failed to unload joint feedback velocities");
00160     return false;
00161   }
00162 
00163   if (!this->positions_.unload(buffer))
00164   {
00165     LOG_ERROR("Failed to unload joint feedback positions");
00166     return false;
00167   }
00168 
00169   if (!buffer->unload(this->time_))
00170   {
00171     LOG_ERROR("Failed to unload joint feedback time");
00172     return false;
00173   }
00174 
00175   if (!buffer->unload(this->valid_fields_))
00176   {
00177     LOG_ERROR("Failed to unload joint feedback valid fields");
00178     return false;
00179   }
00180 
00181   if (!buffer->unload(this->robot_id_))
00182   {
00183     LOG_ERROR("Faild to unload joint feedback robot_id");
00184     return false;
00185   }
00186 
00187   LOG_COMM("Joint feedback successfully unloaded");
00188   return true;
00189 }
00190 
00191 }
00192 }
00193 


simple_message
Author(s): Shaun Edwards
autogenerated on Fri Aug 28 2015 11:11:56