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