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


simple_message
Author(s): Shaun Edwards
autogenerated on Mon Oct 6 2014 00:54:18