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 #include <string>
00032 #ifdef ROS
00033 #include "motoman_driver/simple_message/motoman_motion_ctrl.h"
00034 #include "motoman_driver/simple_message/motoman_motion_reply.h"
00035 #include "simple_message/shared_types.h"
00036 #include "simple_message/log_wrapper.h"
00037 #endif
00038
00039 #ifdef MOTOPLUS
00040 #include "motoman_motion_ctrl.h"
00041 #include "motoman_motion_reply.h"
00042 #include "shared_types.h"
00043 #include "log_wrapper.h"
00044 #endif
00045
00046 using industrial::shared_types::shared_int;
00047 using industrial::shared_types::shared_real;
00048 namespace MotionControlCmds = motoman::simple_message::motion_ctrl::MotionControlCmds;
00049
00050 namespace motoman
00051 {
00052 namespace simple_message
00053 {
00054 namespace motion_reply
00055 {
00056
00057 MotionReply::MotionReply(void)
00058 {
00059 this->init();
00060 }
00061 MotionReply::~MotionReply(void)
00062 {
00063 }
00064
00065 void MotionReply::init()
00066 {
00067 this->init(0, 0, MotionControlCmds::UNDEFINED, MotionReplyResults::SUCCESS, 0, 0);
00068 }
00069
00070 void MotionReply::init(shared_int robot_id, shared_int sequence,
00071 shared_int command, MotionReplyResult result,
00072 shared_int subcode, shared_real data)
00073 {
00074 this->setRobotID(robot_id);
00075 this->setSequence(sequence);
00076 this->setCommand(command);
00077 this->setResult(result);
00078 this->setSubcode(subcode);
00079 this->clearData();
00080 this->setData(0, data);
00081 }
00082
00083 std::string MotionReply::getResultString(shared_int code)
00084 {
00085 switch (code)
00086 {
00087 case MotionReplyResults::SUCCESS:
00088 return "Success";
00089 case MotionReplyResults::BUSY:
00090 return "Busy";
00091 case MotionReplyResults::FAILURE:
00092 return "Failed";
00093 case MotionReplyResults::INVALID:
00094 return "Invalid message";
00095 case MotionReplyResults::ALARM:
00096 return "Controller alarm";
00097 case MotionReplyResults::NOT_READY:
00098 return "Not Ready";
00099 case MotionReplyResults::MP_FAILURE:
00100 return "MotoPlus Error";
00101 default:
00102 return "Unknown";
00103 }
00104 }
00105
00106 std::string MotionReply::getSubcodeString(shared_int code)
00107 {
00108 switch (code)
00109 {
00110 case MotionReplySubcodes::Invalid::UNSPECIFIED:
00111 return "Unknown";
00112 case MotionReplySubcodes::Invalid::MSGSIZE:
00113 return "Invalid message size";
00114 case MotionReplySubcodes::Invalid::MSGHEADER:
00115 return "Invalid header";
00116 case MotionReplySubcodes::Invalid::MSGTYPE:
00117 return "Invalid message type";
00118 case MotionReplySubcodes::Invalid::GROUPNO:
00119 return "Invalid robot ID";
00120 case MotionReplySubcodes::Invalid::SEQUENCE:
00121 return "Invalid sequence ID";
00122 case MotionReplySubcodes::Invalid::COMMAND:
00123 return "Invalid command";
00124 case MotionReplySubcodes::Invalid::DATA:
00125 return "Invalid data";
00126 case MotionReplySubcodes::Invalid::DATA_START_POS:
00127 return "Trajectory start position doesn't match current robot position";
00128 case MotionReplySubcodes::Invalid::DATA_POSITION:
00129 return "Invalid position data";
00130 case MotionReplySubcodes::Invalid::DATA_SPEED:
00131 return "Invalid velocity data";
00132 case MotionReplySubcodes::Invalid::DATA_ACCEL:
00133 return "Invalid acceleration data";
00134 case MotionReplySubcodes::Invalid::DATA_INSUFFICIENT:
00135 return "Insufficient trajectory data. Must supply valid time, pos, and velocity fields.";
00136
00137 case MotionReplySubcodes::NotReady::UNSPECIFIED:
00138 return "Unknown";
00139 case MotionReplySubcodes::NotReady::ALARM:
00140 return "Controller alarm active";
00141 case MotionReplySubcodes::NotReady::ERROR:
00142 return "Controller error";
00143 case MotionReplySubcodes::NotReady::ESTOP:
00144 return "E-Stop active";
00145 case MotionReplySubcodes::NotReady::NOT_PLAY:
00146 return "Controller in TEACH mode";
00147 case MotionReplySubcodes::NotReady::NOT_REMOTE:
00148 return "Controller not in REMOTE mode";
00149 case MotionReplySubcodes::NotReady::SERVO_OFF:
00150 return "Unable to enable drive power";
00151 case MotionReplySubcodes::NotReady::HOLD:
00152 return "Controller in HOLD state";
00153 case MotionReplySubcodes::NotReady::NOT_STARTED:
00154 return "MotoRos not started";
00155 case MotionReplySubcodes::NotReady::WAITING_ROS:
00156 return "Waiting on ROS";
00157 case MotionReplySubcodes::NotReady::SKILLSEND:
00158 return "Waiting on SkillSend";
00159
00160 default:
00161 return "Unknown";
00162 }
00163 }
00164
00165 void MotionReply::copyFrom(MotionReply &src)
00166 {
00167 this->setRobotID(src.getRobotID());
00168 this->setSequence(src.getSequence());
00169 this->setCommand(src.getCommand());
00170 this->setResult(src.getResult());
00171 this->setSubcode(src.getSubcode());
00172 for (size_t i = 0; i < MAX_DATA_CNT; ++i)
00173 this->setData(i, src.getData(i));
00174 }
00175
00176 bool MotionReply::operator==(MotionReply &rhs)
00177 {
00178 bool rslt = this->robot_id_ == rhs.robot_id_ &&
00179 this->sequence_ == rhs.sequence_ &&
00180 this->command_ == rhs.command_ &&
00181 this->result_ == rhs.result_ &&
00182 this->subcode_ == rhs.subcode_;
00183
00184 for (size_t i = 0; i < MAX_DATA_CNT; ++i)
00185 rslt &= (this->data_[i] == rhs.data_[i]);
00186
00187 return rslt;
00188 }
00189
00190 bool MotionReply::load(industrial::byte_array::ByteArray *buffer)
00191 {
00192 LOG_COMM("Executing MotionReply command load");
00193
00194 if (!buffer->load(this->robot_id_))
00195 {
00196 LOG_ERROR("Failed to load MotionReply robot_id");
00197 return false;
00198 }
00199
00200 if (!buffer->load(this->sequence_))
00201 {
00202 LOG_ERROR("Failed to load MotionReply sequence");
00203 return false;
00204 }
00205
00206 if (!buffer->load(this->command_))
00207 {
00208 LOG_ERROR("Failed to load MotionReply command");
00209 return false;
00210 }
00211
00212 if (!buffer->load(this->result_))
00213 {
00214 LOG_ERROR("Failed to load MotionReply result");
00215 return false;
00216 }
00217
00218 if (!buffer->load(this->subcode_))
00219 {
00220 LOG_ERROR("Failed to load MotionReply subcode");
00221 return false;
00222 }
00223
00224 for (size_t i = 0; i < MAX_DATA_CNT; ++i)
00225 {
00226 shared_real value = this->getData(i);
00227 if (!buffer->load(value))
00228 {
00229 LOG_ERROR("Failed to load MotionReply data element %d from data[%d]", static_cast<int>(i), buffer->getBufferSize());
00230 return false;
00231 }
00232 }
00233
00234 LOG_COMM("MotionReply data successfully loaded");
00235 return true;
00236 }
00237
00238 bool MotionReply::unload(industrial::byte_array::ByteArray *buffer)
00239 {
00240 LOG_COMM("Executing MotionReply command unload");
00241
00242 for (int i = MAX_DATA_CNT - 1; i >= 0; --i)
00243 {
00244 shared_real value;
00245 if (!buffer->unload(value))
00246 {
00247 LOG_ERROR("Failed to unload message data element: %d from data[%d]", static_cast<int>(i), buffer->getBufferSize());
00248 return false;
00249 }
00250 this->setData(i, value);
00251 }
00252
00253 if (!buffer->unload(this->subcode_))
00254 {
00255 LOG_ERROR("Failed to unload MotionReply subcode");
00256 return false;
00257 }
00258
00259 if (!buffer->unload(this->result_))
00260 {
00261 LOG_ERROR("Failed to unload MotionReply result");
00262 return false;
00263 }
00264
00265 if (!buffer->unload(this->command_))
00266 {
00267 LOG_ERROR("Failed to unload MotionReply command");
00268 return false;
00269 }
00270
00271 if (!buffer->unload(this->sequence_))
00272 {
00273 LOG_ERROR("Failed to unload MotionReply sequence");
00274 return false;
00275 }
00276
00277 if (!buffer->unload(this->robot_id_))
00278 {
00279 LOG_ERROR("Failed to unload MotionReply robot_id");
00280 return false;
00281 }
00282
00283 LOG_COMM("MotionReply data successfully unloaded");
00284 return true;
00285 }
00286
00287 }
00288 }
00289 }