motoman_motion_reply.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 
32 #include <string>
33 #ifdef ROS
38 #endif
39 
40 #ifdef MOTOPLUS
41 #include "motoman_motion_ctrl.h" // NOLINT(build/include)
42 #include "motoman_motion_reply.h" // NOLINT(build/include)
43 #include "shared_types.h" // NOLINT(build/include)
44 #include "log_wrapper.h" // NOLINT(build/include)
45 #endif
46 
50 
51 namespace motoman
52 {
53 namespace simple_message
54 {
55 namespace motion_reply
56 {
57 
59 {
60  this->init();
61 }
63 {
64 }
65 
67 {
69 }
70 
74 {
75  this->setRobotID(robot_id);
76  this->setSequence(sequence);
77  this->setCommand(command);
78  this->setResult(result);
79  this->setSubcode(subcode);
80  this->clearData();
81  this->setData(0, data);
82 }
83 
85 {
86  switch (code)
87  {
89  return "Success";
91  return "Busy";
93  return "Failed";
95  return "Invalid message";
97  return "Controller alarm";
99  return "Not Ready";
101  return "MotoPlus Error";
102  default:
103  return "Unknown";
104  }
105 }
106 
108 {
109  switch (code)
110  {
112  return "Unknown";
114  return "Invalid message size";
116  return "Invalid header";
118  return "Invalid message type";
120  return "Invalid robot ID";
122  return "Invalid sequence ID";
124  return "Invalid command";
126  return "Invalid data";
128  return "Trajectory start position doesn't match current robot position";
130  return "Invalid position data";
132  return "Invalid velocity data";
134  return "Invalid acceleration data";
136  return "Insufficient trajectory data. Must supply valid time, pos, and velocity fields.";
137 
139  return "Unknown";
141  return "Controller alarm active";
143  return "Controller error";
145  return "E-Stop active";
147  return "Controller in TEACH mode";
149  return "Controller not in REMOTE mode";
151  return "Unable to enable drive power";
153  return "Controller in HOLD state";
155  return "MotoRos not started";
157  return "Waiting on ROS";
159  return "Waiting on SkillSend";
160 
161  default:
162  return "Unknown";
163  }
164 }
165 
167 {
168  this->setRobotID(src.getRobotID());
169  this->setSequence(src.getSequence());
170  this->setCommand(src.getCommand());
171  this->setResult(src.getResult());
172  this->setSubcode(src.getSubcode());
173  for (size_t i = 0; i < MAX_DATA_CNT; ++i)
174  this->setData(i, src.getData(i));
175 }
176 
178 {
179  bool rslt = this->robot_id_ == rhs.robot_id_ &&
180  this->sequence_ == rhs.sequence_ &&
181  this->command_ == rhs.command_ &&
182  this->result_ == rhs.result_ &&
183  this->subcode_ == rhs.subcode_;
184 
185  for (size_t i = 0; i < MAX_DATA_CNT; ++i)
186  rslt &= (this->data_[i] == rhs.data_[i]);
187 
188  return rslt;
189 }
190 
192 {
193  LOG_COMM("Executing MotionReply command load");
194 
195  if (!buffer->load(this->robot_id_))
196  {
197  LOG_ERROR("Failed to load MotionReply robot_id");
198  return false;
199  }
200 
201  if (!buffer->load(this->sequence_))
202  {
203  LOG_ERROR("Failed to load MotionReply sequence");
204  return false;
205  }
206 
207  if (!buffer->load(this->command_))
208  {
209  LOG_ERROR("Failed to load MotionReply command");
210  return false;
211  }
212 
213  if (!buffer->load(this->result_))
214  {
215  LOG_ERROR("Failed to load MotionReply result");
216  return false;
217  }
218 
219  if (!buffer->load(this->subcode_))
220  {
221  LOG_ERROR("Failed to load MotionReply subcode");
222  return false;
223  }
224 
225  for (size_t i = 0; i < MAX_DATA_CNT; ++i)
226  {
227  shared_real value = this->getData(i);
228  if (!buffer->load(value))
229  {
230  LOG_ERROR("Failed to load MotionReply data element %d from data[%d]", static_cast<int>(i),
231  buffer->getBufferSize());
232  return false;
233  }
234  }
235 
236  LOG_COMM("MotionReply data successfully loaded");
237  return true;
238 }
239 
241 {
242  LOG_COMM("Executing MotionReply command unload");
243 
244  for (int i = MAX_DATA_CNT - 1; i >= 0; --i)
245  {
247  if (!buffer->unload(value))
248  {
249  LOG_ERROR("Failed to unload message data element: %d from data[%d]", static_cast<int>(i),
250  buffer->getBufferSize());
251  return false;
252  }
253  this->setData(i, value);
254  }
255 
256  if (!buffer->unload(this->subcode_))
257  {
258  LOG_ERROR("Failed to unload MotionReply subcode");
259  return false;
260  }
261 
262  if (!buffer->unload(this->result_))
263  {
264  LOG_ERROR("Failed to unload MotionReply result");
265  return false;
266  }
267 
268  if (!buffer->unload(this->command_))
269  {
270  LOG_ERROR("Failed to unload MotionReply command");
271  return false;
272  }
273 
274  if (!buffer->unload(this->sequence_))
275  {
276  LOG_ERROR("Failed to unload MotionReply sequence");
277  return false;
278  }
279 
280  if (!buffer->unload(this->robot_id_))
281  {
282  LOG_ERROR("Failed to unload MotionReply robot_id");
283  return false;
284  }
285 
286  LOG_COMM("MotionReply data successfully unloaded");
287  return true;
288 }
289 
290 } // namespace motion_reply
291 } // namespace simple_message
292 } // namespace motoman
industrial::shared_types::shared_int command_
Motion-control command (from corresponding MotionCtrl command)
bool unload(industrial::byte_array::ByteArray *buffer)
industrial::shared_types::shared_int robot_id_
Robot/group ID. 0 = 1st robot.
industrial::shared_types::shared_real getData(size_t idx) const
Returns reply data.
industrial::shared_types::shared_int getSubcode() const
Returns motion-control result sub-code.
SmCommandType command
void init()
Initializes a empty motion control reply.
int sequence
void setResult(industrial::shared_types::shared_int result)
Sets motion-control result code.
UINT32 value
#define LOG_COMM(format,...)
void setRobotID(industrial::shared_types::shared_int robot_id)
Sets robot_id.
int subcode
bool load(industrial::shared_types::shared_bool value)
#define LOG_ERROR(format,...)
void copyFrom(MotionReply &src)
Copies the passed in value.
bool operator==(MotionReply &rhs)
== operator implementation
float data[ROS_MAX_JOINT]
void setSequence(industrial::shared_types::shared_int sequence)
Sets motion-control reply&#39;s sequence number.
industrial::shared_types::shared_int getResult() const
Returns motion-control result code.
industrial::shared_types::shared_int sequence_
Message-tracking number (from corresponding MotionCtrl command)
void setData(size_t idx, industrial::shared_types::shared_real val)
Sets reply data.
industrial::shared_types::shared_int getSequence() const
Returns motion-control reply&#39;s sequence number.
void setCommand(industrial::shared_types::shared_int command)
Sets motion-control command (for reference)
Enumeration of motion control command codes.
SmResultType result
Class encapsulated motion control reply data. These messages are sent by the FS100 controller in resp...
industrial::shared_types::shared_int result_
Command result.
bool unload(industrial::shared_types::shared_bool &value)
void setSubcode(industrial::shared_types::shared_int subcode)
Sets motion-control result sub-code.
static const size_t MAX_DATA_CNT
Maximum length (# of float elements) of data buffer.
industrial::shared_types::shared_int subcode_
Command result sub-code (more detailed status)
industrial::shared_types::shared_real data_[MAX_DATA_CNT]
Motion-control command data Contents of data-buffer are specific to each command. ...
industrial::shared_types::shared_int getRobotID() const
Returns target robot/group # for this reply.
bool load(industrial::byte_array::ByteArray *buffer)
industrial::shared_types::shared_int getCommand() const
Returns motion-control command.


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