robot_status.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/robot_status.h"
00033 #include "simple_message/shared_types.h"
00034 #include "simple_message/log_wrapper.h"
00035 #else
00036 #include "robot_status.h"
00037 #include "shared_types.h"
00038 #include "log_wrapper.h"
00039 #endif
00040 
00041 #ifdef ROS
00042 // Files below used to translate between ROS messages enums and
00043 // enums defined in this file
00044 #include "industrial_msgs/RobotMode.h"
00045 #include "industrial_msgs/TriState.h"
00046 #endif
00047 
00048 using namespace industrial::shared_types;
00049 
00050 namespace industrial
00051 {
00052 namespace robot_status
00053 {
00054 
00055 namespace RobotModes
00056 {
00057 
00058 #ifdef ROS
00059 
00060 int toROSMsgEnum(RobotModes::RobotMode mode)
00061 {
00062 
00063   switch (mode)
00064   {
00065     case RobotModes::AUTO:
00066       return industrial_msgs::RobotMode::AUTO;
00067       break;
00068     case RobotModes::MANUAL:
00069       return industrial_msgs::RobotMode::MANUAL;
00070       break;
00071     case RobotModes::UNKNOWN:
00072       return industrial_msgs::RobotMode::UNKNOWN;
00073   }
00074   return industrial_msgs::RobotMode::UNKNOWN;
00075 
00076 }
00077 ;
00078 
00079 #endif
00080 
00081 }
00082 
00083 namespace TriStates
00084 {
00085 
00086 #ifdef ROS
00087 
00088 int toROSMsgEnum(TriStates::TriState state)
00089 {
00090 
00091   switch (state)
00092   {
00093     case TriStates::TS_UNKNOWN:
00094       return industrial_msgs::TriState::UNKNOWN;
00095       break;
00096     case TriStates::TS_TRUE:
00097       return industrial_msgs::TriState::TRUE;
00098       break;
00099     case TriStates::TS_FALSE:
00100       return industrial_msgs::TriState::FALSE;
00101       break;
00102   }
00103   return industrial_msgs::TriState::UNKNOWN;
00104 
00105 }
00106 ;
00107 
00108 #endif
00109 
00110 }
00111 
00112 RobotStatus::RobotStatus(void)
00113 {
00114   this->init();
00115 }
00116 RobotStatus::~RobotStatus(void)
00117 {
00118 
00119 }
00120 
00121 void RobotStatus::init()
00122 {
00123   this->init(TriStates::TS_UNKNOWN, TriStates::TS_UNKNOWN, 0, TriStates::TS_UNKNOWN,
00124              TriStates::TS_UNKNOWN, RobotModes::UNKNOWN, TriStates::TS_UNKNOWN);
00125 }
00126 
00127 void RobotStatus::init(TriState drivesPowered, TriState eStopped, industrial::shared_types::shared_int errorCode,
00128                        TriState inError, TriState inMotion, RobotMode mode, TriState motionPossible)
00129 {
00130   this->setDrivesPowered(drivesPowered);
00131   this->setEStopped(eStopped);
00132   this->setErrorCode(errorCode);
00133   this->setInError(inError);
00134   this->setInMotion(inMotion);
00135   this->setMode(mode);
00136   this->setMotionPossible(motionPossible);
00137 }
00138 
00139 void RobotStatus::copyFrom(RobotStatus &src)
00140 {
00141   this->setDrivesPowered(src.getDrivesPowered());
00142   this->setEStopped(src.getEStopped());
00143   this->setErrorCode(src.getErrorCode());
00144   this->setInError(src.getInError());
00145   this->setInMotion(src.getInMotion());
00146   this->setMode(src.getMode());
00147   this->setMotionPossible(src.getMotionPossible());
00148 }
00149 
00150 bool RobotStatus::operator==(RobotStatus &rhs)
00151 {
00152   return this->drives_powered_ == rhs.drives_powered_ && this->e_stopped_ == rhs.e_stopped_
00153       && this->error_code_ == rhs.error_code_ && this->in_error_ == rhs.in_error_ && this->in_motion_ == rhs.in_motion_
00154       && this->mode_ == rhs.mode_ && this->motion_possible_ == rhs.motion_possible_;
00155 }
00156 
00157 bool RobotStatus::load(industrial::byte_array::ByteArray *buffer)
00158 {
00159   bool rtn = false;
00160 
00161   LOG_COMM("Executing robot status load");
00162 
00163   if (buffer->load(this->drives_powered_) && buffer->load(this->e_stopped_) && buffer->load(this->error_code_)
00164       && buffer->load(this->in_error_) && buffer->load(this->in_motion_) && buffer->load(this->mode_)
00165       && buffer->load(this->motion_possible_))
00166   {
00167 
00168     LOG_COMM("Robot status successfully loaded");
00169     rtn = true;
00170   }
00171   else
00172   {
00173     LOG_COMM("Robot status not loaded");
00174     rtn = false;
00175   }
00176 
00177   return rtn;
00178 }
00179 
00180 bool RobotStatus::unload(industrial::byte_array::ByteArray *buffer)
00181 {
00182   bool rtn = false;
00183 
00184   LOG_COMM("Executing robot status unload");
00185   if (buffer->unload(this->motion_possible_) && buffer->unload(this->mode_) && buffer->unload(this->in_motion_)
00186       && buffer->unload(this->in_error_) && buffer->unload(this->error_code_) && buffer->unload(this->e_stopped_)
00187       && buffer->unload(this->drives_powered_))
00188   {
00189 
00190     rtn = true;
00191     LOG_COMM("Robot status successfully unloaded");
00192   }
00193 
00194   else
00195   {
00196     LOG_ERROR("Failed to unload robot status");
00197     rtn = false;
00198   }
00199 
00200   return rtn;
00201 }
00202 
00203 }
00204 }
00205 


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