joint_traj_pt.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_traj_pt.h"
00033 #include "simple_message/shared_types.h"
00034 #include "simple_message/log_wrapper.h"
00035 #else
00036 #include "joint_traj_pt.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_traj_pt
00047 {
00048 
00049 JointTrajPt::JointTrajPt(void)
00050 {
00051   this->init();
00052 }
00053 JointTrajPt::~JointTrajPt(void)
00054 {
00055 
00056 }
00057 
00058 void JointTrajPt::init()
00059 {
00060   this->joint_position_.init();
00061   this->sequence_ = 0;
00062   this->velocity_ = 0.0;
00063   this->duration_ = 0.0;
00064 }
00065 
00066 void JointTrajPt::init(shared_int sequence, JointData & position, shared_real velocity, shared_real duration)
00067 {
00068   this->setJointPosition(position);
00069   this->setSequence(sequence);
00070   this->setVelocity(velocity);
00071   this->setDuration(duration);
00072 }
00073 
00074 void JointTrajPt::copyFrom(JointTrajPt &src)
00075 {
00076   this->setSequence(src.getSequence());
00077   src.getJointPosition(this->joint_position_);
00078   this->setVelocity(src.getVelocity());
00079   this->setDuration(src.getDuration());
00080 }
00081 
00082 bool JointTrajPt::operator==(JointTrajPt &rhs)
00083 {
00084   return this->joint_position_ == rhs.joint_position_ && this->sequence_ == rhs.sequence_
00085       && this->velocity_ == rhs.velocity_ && this->duration_ == rhs.duration_;
00086 
00087 }
00088 
00089 bool JointTrajPt::load(industrial::byte_array::ByteArray *buffer)
00090 {
00091   bool rtn = false;
00092 
00093   LOG_COMM("Executing joint trajectory point load");
00094 
00095   if (buffer->load(this->sequence_))
00096   {
00097     if (this->joint_position_.load(buffer))
00098     {
00099       if (buffer->load(this->velocity_))
00100       {
00101         if (buffer->load(this->duration_))
00102         {
00103           LOG_COMM("Trajectory point successfully loaded");
00104           rtn = true;
00105         }
00106         else
00107         {
00108           rtn = false;
00109           LOG_ERROR("Failed to load joint traj pt. duration");
00110         }
00111         rtn = true;
00112       }
00113       else
00114       {
00115         rtn = false;
00116         LOG_ERROR("Failed to load joint traj pt. velocity");
00117       }
00118 
00119     }
00120     else
00121     {
00122       rtn = false;
00123       LOG_ERROR("Failed to load joint traj. pt.  position data");
00124     }
00125   }
00126   else
00127   {
00128     rtn = false;
00129     LOG_ERROR("Failed to load joint traj. pt. sequence number");
00130   }
00131 
00132   return rtn;
00133 }
00134 
00135 bool JointTrajPt::unload(industrial::byte_array::ByteArray *buffer)
00136 {
00137   bool rtn = false;
00138 
00139   LOG_COMM("Executing joint traj. pt. unload");
00140   if (buffer->unload(this->duration_))
00141   {
00142     if (buffer->unload(this->velocity_))
00143     {
00144       if (this->joint_position_.unload(buffer))
00145       {
00146         if (buffer->unload(this->sequence_))
00147         {
00148           rtn = true;
00149           LOG_COMM("Joint traj. pt successfully unloaded");
00150         }
00151         else
00152         {
00153           LOG_ERROR("Failed to unload joint traj. pt. sequence number");
00154           rtn = false;
00155         }
00156       }
00157       else
00158       {
00159         LOG_ERROR("Failed to unload joint traj. pt.  position data");
00160         rtn = false;
00161       }
00162 
00163     }
00164     else
00165     {
00166       LOG_ERROR("Failed to unload joint traj. pt. velocity");
00167       rtn = false;
00168     }
00169   }
00170   else
00171   {
00172     LOG_ERROR("Failed to unload joint traj. pt. duration");
00173     rtn = false;
00174   }
00175 
00176   return rtn;
00177 }
00178 
00179 }
00180 }
00181 


simple_message
Author(s): Shaun Edwards
autogenerated on Tue Jan 17 2017 21:10:02