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 #ifdef ROS
00032 #include "simple_message/robot_status.h"
00033 #include "simple_message/shared_types.h"
00034 #include "simple_message/log_wrapper.h"
00035
00036
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