joint_feedback_ex.cpp
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  * Copyright (c) 2014, Fraunhofer IPA
00005  * Author: Thiago de Freitas
00006  *
00007  * All rights reserved.
00008  *
00009  * Redistribution and use in source and binary forms, with or without
00010  * modification, are permitted provided that the following conditions are met:
00011  *
00012  *  * Redistributions of source code must retain the above copyright
00013  *  notice, this list of conditions and the following disclaimer.
00014  *  * Redistributions in binary form must reproduce the above copyright
00015  *  notice, this list of conditions and the following disclaimer in the
00016  *  documentation and/or other materials provided with the distribution.
00017  *  * Neither the name of the Fraunhofer IPA, nor the names
00018  *  of its contributors may be used to endorse or promote products derived
00019  *  from this software without specific prior written permission.
00020  *
00021  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00022  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00023  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00024  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00025  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00026  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00027  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00028  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00029  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00030  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00031  * POSSIBILITY OF SUCH DAMAGE.
00032  */
00033 
00034 #include <vector>
00035 
00036 #ifndef FLATHEADERS
00037 #include "motoman_driver/simple_message/joint_feedback_ex.h"
00038 #include "simple_message/shared_types.h"
00039 #include "simple_message/log_wrapper.h"
00040 #else
00041 #include "joint_feedback_ex.h"
00042 #include "shared_types.h"
00043 #include "log_wrapper.h"
00044 #endif
00045 
00046 using industrial::joint_feedback_message::JointFeedbackMessage;
00047 using industrial::joint_feedback::JointFeedback;
00048 
00049 namespace industrial
00050 {
00051 namespace joint_feedback_ex
00052 {
00053 
00054 JointFeedbackEx::JointFeedbackEx(void)
00055 {
00056   this->init();
00057 }
00058 JointFeedbackEx::~JointFeedbackEx(void)
00059 {
00060 }
00061 
00062 void JointFeedbackEx::init()
00063 {
00064   this->groups_number_ = 0;
00065 }
00066 
00067 void JointFeedbackEx::init(industrial::shared_types::shared_int groups_number,
00068                            std::vector<joint_feedback_message::JointFeedbackMessage> joints_feedback_points)
00069 {
00070   this->setGroupsNumber(groups_number);
00071   this->joint_feedback_messages_ = joints_feedback_points;
00072 }
00073 
00074 void JointFeedbackEx::copyFrom(JointFeedbackEx &src)
00075 {
00076   this->setGroupsNumber(src.getGroupsNumber());
00077   this->joint_feedback_messages_ = src.joint_feedback_messages_;
00078 }
00079 
00080 bool JointFeedbackEx::operator==(JointFeedbackEx &rhs)
00081 {
00082   return this->groups_number_ == rhs.groups_number_;
00083 }
00084 
00085 bool JointFeedbackEx::load(industrial::byte_array::ByteArray *buffer)
00086 {
00087   LOG_COMM("Executing joint feedback load");
00088 
00089 
00090   for (int i = 0; i < this->groups_number_; i++)
00091   {
00092     if (!buffer->load(this->joint_feedback_messages_[i]))
00093     {
00094       LOG_ERROR("Failed to load the Joint Feedback messages");
00095       return false;
00096     }
00097   }
00098 
00099   if (!buffer->load(this->groups_number_))
00100   {
00101     LOG_ERROR("Failed to load joint feedback groups_number");
00102     return false;
00103   }
00104 
00105 
00106   LOG_COMM("Joint feedback successfully loaded");
00107   return true;
00108 }
00109 
00110 bool JointFeedbackEx::unload(industrial::byte_array::ByteArray *buffer)
00111 {
00112   LOG_COMM("Executing joint feedback unload");
00113 
00114   if (!buffer->unloadFront(this->groups_number_))
00115   {
00116     LOG_ERROR("Failed to unload joint feedback groups_number");
00117     return false;
00118   }
00119 
00120   for (int i = 0; i < this->groups_number_; i++)
00121   {
00122     JointFeedbackMessage tmp_msg;
00123     JointFeedback j_feedback;
00124 
00125 
00126 
00127     if (!buffer->unload(j_feedback))
00128     {
00129       LOG_ERROR("Failed to unload joint feedback groups_number");
00130       return false;
00131     }
00132     tmp_msg.init(j_feedback);
00133 
00134     this->joint_feedback_messages_.push_back(tmp_msg);
00135   }
00136 
00137 
00138   LOG_COMM("Joint feedback successfully unloaded");
00139   return true;
00140 }
00141 
00142 }  // namespace joint_feedback_ex
00143 }  // namespace industrial
00144 
00145 


motoman_driver
Author(s): Jeremy Zoss (Southwest Research Institute)
autogenerated on Sat Jun 8 2019 19:06:57