motion_ctrl.cpp
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2013, Southwest Research Institute
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  *
10  * * Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  * * Neither the name of the Southwest Research Institute, nor the names
16  * of its contributors may be used to endorse or promote products derived
17  * from this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
35 #include "ros/ros.h"
37 #include <string>
38 
45 
46 namespace motoman
47 {
48 namespace motion_ctrl
49 {
50 
51 bool MotomanMotionCtrl::init(SmplMsgConnection* connection, int robot_id)
52 {
53  connection_ = connection;
54  robot_id_ = robot_id;
55  return true;
56 }
57 
59 {
60  std::string err_str;
61  MotionReply reply;
62 
64  {
65  ROS_ERROR("Failed to send CHECK_MOTION_READY command");
66  return false;
67  }
68 
69  return (reply.getResult() == MotionReplyResults::TRUE);
70 }
71 
72 
74 {
75  MotionReply reply;
77 
78  if (!sendAndReceive(cmd, reply))
79  {
80  ROS_ERROR("Failed to send TRAJ_MODE command");
81  return false;
82  }
83 
84  if (reply.getResult() != MotionReplyResults::SUCCESS)
85  {
86  ROS_ERROR_STREAM("Failed to set TrajectoryMode: " << getErrorString(reply));
87  return false;
88  }
89 
90  return true;
91 }
92 
94 {
95  MotionReply reply;
96 
98  {
99  ROS_ERROR("Failed to send STOP_MOTION command");
100  return false;
101  }
102 
103  if (reply.getResult() != MotionReplyResults::SUCCESS)
104  {
105  ROS_ERROR_STREAM("Failed to Stop Motion: " << getErrorString(reply));
106  return false;
107  }
108 
109  return true;
110 }
111 
113 {
114  SimpleMessage req, res;
116  MotionCtrlMessage ctrl_msg;
117  MotionReplyMessage ctrl_reply;
118 
119  data.init(robot_id_, 0, command, 0);
120  ctrl_msg.init(data);
121  ctrl_msg.toRequest(req);
122 
123  if (!this->connection_->sendAndReceiveMsg(req, res))
124  {
125  ROS_ERROR("Failed to send MotionCtrl message");
126  return false;
127  }
128 
129  ctrl_reply.init(res);
130  reply.copyFrom(ctrl_reply.reply_);
131 
132  return true;
133 }
134 
136 {
137  std::ostringstream ss;
138  ss << reply.getResultString() << " (" << reply.getResult() << ")";
139  ss << " : ";
140  ss << reply.getSubcodeString() << " (" << reply.getSubcode() << ")";
141  return ss.str();
142 }
143 
144 
145 } // namespace motion_ctrl
146 } // namespace motoman
147 
bool init(industrial::simple_message::SimpleMessage &msg)
Initializes message from a simple message.
string cmd
industrial::shared_types::shared_int getSubcode() const
Returns motion-control result sub-code.
SmCommandType command
bool sendAndReceive(MotionControlCmd command, MotionReply &reply)
virtual bool toRequest(industrial::simple_message::SimpleMessage &msg)
bool sendAndReceiveMsg(industrial::simple_message::SimpleMessage &send, industrial::simple_message::SimpleMessage &recv, bool verbose=false)
void copyFrom(MotionReply &src)
Copies the passed in value.
bool init(SmplMsgConnection *connection, int robot_id)
Definition: motion_ctrl.cpp:51
float data[ROS_MAX_JOINT]
industrial::shared_types::shared_int getResult() const
Returns motion-control result code.
static std::string getErrorString(const MotionReply &reply)
Enumeration of motion control command codes.
Class encapsulated motoman motion control message generation methods (either to or from a industrial:...
Class encapsulated motion control reply data. These messages are sent by the FS100 controller in resp...
static std::string getSubcodeString(industrial::shared_types::shared_int code)
Class encapsulated motoman motion reply message generation methods (either to or from a industrial::s...
void init()
Initializes a empty motion control command.
#define ROS_ERROR_STREAM(args)
bool init(industrial::simple_message::SimpleMessage &msg)
Initializes message from a simple message.
static std::string getResultString(industrial::shared_types::shared_int code)
#define ROS_ERROR(...)
Class encapsulated motion control data. These control messages are required to download command-traje...


motoman_driver
Author(s): Jeremy Zoss (Southwest Research Institute), Ted Miller (MotoROS) (Yaskawa Motoman), Eric Marcil (MotoROS) (Yaskawa Motoman)
autogenerated on Sat May 8 2021 02:27:43