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
00032 #include "motoman_driver/motion_ctrl.h"
00033 #include "motoman_driver/simple_message/motoman_motion_ctrl_message.h"
00034 #include "motoman_driver/simple_message/motoman_motion_reply_message.h"
00035 #include "ros/ros.h"
00036 #include "simple_message/simple_message.h"
00037 #include <string>
00038
00039 namespace MotionControlCmds = motoman::simple_message::motion_ctrl::MotionControlCmds;
00040 namespace MotionReplyResults = motoman::simple_message::motion_reply::MotionReplyResults;
00041 using motoman::simple_message::motion_ctrl::MotionCtrl;
00042 using motoman::simple_message::motion_ctrl_message::MotionCtrlMessage;
00043 using motoman::simple_message::motion_reply_message::MotionReplyMessage;
00044 using industrial::simple_message::SimpleMessage;
00045
00046 namespace motoman
00047 {
00048 namespace motion_ctrl
00049 {
00050
00051 bool MotomanMotionCtrl::init(SmplMsgConnection* connection, int robot_id)
00052 {
00053 connection_ = connection;
00054 robot_id_ = robot_id;
00055 return true;
00056 }
00057
00058 bool MotomanMotionCtrl::controllerReady()
00059 {
00060 std::string err_str;
00061 MotionReply reply;
00062
00063 if (!sendAndReceive(MotionControlCmds::CHECK_MOTION_READY, reply))
00064 {
00065 ROS_ERROR("Failed to send CHECK_MOTION_READY command");
00066 return false;
00067 }
00068
00069 return (reply.getResult() == MotionReplyResults::TRUE);
00070 }
00071
00072
00073 bool MotomanMotionCtrl::setTrajMode(bool enable)
00074 {
00075 MotionReply reply;
00076 MotionControlCmd cmd = enable ? MotionControlCmds::START_TRAJ_MODE : MotionControlCmds::STOP_TRAJ_MODE;
00077
00078 if (!sendAndReceive(cmd, reply))
00079 {
00080 ROS_ERROR("Failed to send TRAJ_MODE command");
00081 return false;
00082 }
00083
00084 if (reply.getResult() != MotionReplyResults::SUCCESS)
00085 {
00086 ROS_ERROR_STREAM("Failed to set TrajectoryMode: " << getErrorString(reply));
00087 return false;
00088 }
00089
00090 return true;
00091 }
00092
00093 bool MotomanMotionCtrl::stopTrajectory()
00094 {
00095 MotionReply reply;
00096
00097 if (!sendAndReceive(MotionControlCmds::STOP_MOTION, reply))
00098 {
00099 ROS_ERROR("Failed to send STOP_MOTION command");
00100 return false;
00101 }
00102
00103 if (reply.getResult() != MotionReplyResults::SUCCESS)
00104 {
00105 ROS_ERROR_STREAM("Failed to Stop Motion: " << getErrorString(reply));
00106 return false;
00107 }
00108
00109 return true;
00110 }
00111
00112 bool MotomanMotionCtrl::sendAndReceive(MotionControlCmd command, MotionReply &reply)
00113 {
00114 SimpleMessage req, res;
00115 MotionCtrl data;
00116 MotionCtrlMessage ctrl_msg;
00117 MotionReplyMessage ctrl_reply;
00118
00119 data.init(robot_id_, 0, command, 0);
00120 ctrl_msg.init(data);
00121 ctrl_msg.toRequest(req);
00122
00123 if (!this->connection_->sendAndReceiveMsg(req, res))
00124 {
00125 ROS_ERROR("Failed to send MotionCtrl message");
00126 return false;
00127 }
00128
00129 ctrl_reply.init(res);
00130 reply.copyFrom(ctrl_reply.reply_);
00131
00132 return true;
00133 }
00134
00135 std::string MotomanMotionCtrl::getErrorString(const MotionReply &reply)
00136 {
00137 std::ostringstream ss;
00138 ss << reply.getResultString() << " (" << reply.getResult() << ")";
00139 ss << " : ";
00140 ss << reply.getSubcodeString() << " (" << reply.getSubcode() << ")";
00141 return ss.str();
00142 }
00143
00144
00145 }
00146 }
00147