motoman_motion_reply.cpp
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  * Copyright (c) 2013, 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 #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 }  // namespace motion_reply
00288 }  // namespace simple_message
00289 }  // namespace motoman


motoman_driver
Author(s): Jeremy Zoss (Southwest Research Institute)
autogenerated on Sat Jun 8 2019 19:06:58