Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
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
00043
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