motoman_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 
32 #ifdef ROS
36 #endif
37 
38 #ifdef MOTOPLUS
39 #include "motoman_motion_ctrl.h" // NOLINT(build/include)
40 #include "shared_types.h" // NOLINT(build/include)
41 #include "log_wrapper.h" // NOLINT(build/include)
42 #endif
43 
46 
47 namespace motoman
48 {
49 namespace simple_message
50 {
51 namespace motion_ctrl
52 {
54 {
55  this->init();
56 }
58 {
59 }
60 
62 {
63  this->init(0, 0, MotionControlCmds::UNDEFINED, 0);
64 }
65 
68 {
69  this->setRobotID(robot_id);
70  this->setSequence(sequence);
71  this->setCommand(command);
72  this->clearData();
73  this->setData(0, data);
74 }
75 
77 {
78  this->setRobotID(src.getRobotID());
79  this->setSequence(src.getSequence());
80  this->setCommand(src.getCommand());
81  for (size_t i = 0; i < MAX_DATA_CNT; ++i)
82  this->setData(i, src.getData(i));
83 }
84 
86 {
87  bool rslt = this->robot_id_ == rhs.robot_id_ &&
88  this->sequence_ == rhs.sequence_ &&
89  this->command_ == rhs.command_;
90 
91  for (size_t i = 0; i < MAX_DATA_CNT; ++i)
92  rslt &= (this->data_[i] == rhs.data_[i]);
93 
94  return rslt;
95 }
96 
98 {
99  LOG_COMM("Executing MotionCtrl command load");
100 
101  if (!buffer->load(this->robot_id_))
102  {
103  LOG_ERROR("Failed to load MotionCtrl robot_id");
104  return false;
105  }
106 
107  if (!buffer->load(this->sequence_))
108  {
109  LOG_ERROR("Failed to load MotionCtrl sequence");
110  return false;
111  }
112 
113  if (!buffer->load(this->command_))
114  {
115  LOG_ERROR("Failed to load MotionCtrl command");
116  return false;
117  }
118 
119  for (size_t i = 0; i < MAX_DATA_CNT; ++i)
120  {
121  shared_real value = this->getData(i);
122  if (!buffer->load(value))
123  {
124  LOG_ERROR("Failed to load MotionCtrl data element %d from data[%d]", static_cast<int>(i),
125  buffer->getBufferSize());
126  return false;
127  }
128  }
129 
130  LOG_COMM("MotionCtrl data successfully loaded");
131  return true;
132 }
133 
135 {
136  LOG_COMM("Executing MotionCtrl command unload");
137 
138  for (int i = MAX_DATA_CNT - 1; i >= 0; --i)
139  {
141  if (!buffer->unload(value))
142  {
143  LOG_ERROR("Failed to unload message data element: %d from data[%d]", static_cast<int>(i),
144  buffer->getBufferSize());
145  return false;
146  }
147  this->setData(i, value);
148  }
149 
150  if (!buffer->unload(this->command_))
151  {
152  LOG_ERROR("Failed to unload MotionCtrl command");
153  return false;
154  }
155 
156  if (!buffer->unload(this->sequence_))
157  {
158  LOG_ERROR("Failed to unload MotionCtrl sequence");
159  return false;
160  }
161 
162  if (!buffer->unload(this->robot_id_))
163  {
164  LOG_ERROR("Failed to unload MotionCtrl robot_id");
165  return false;
166  }
167 
168  LOG_COMM("MotionCtrl data successfully unloaded");
169  return true;
170 }
171 
172 } // namespace motion_ctrl
173 } // namespace simple_message
174 } // namespace motoman
industrial::shared_types::shared_int command_
Motion-control command.
void setCommand(MotionControlCmd command)
Sets motion control command.
void setSequence(industrial::shared_types::shared_int sequence)
Sets control command&#39;s sequence number.
industrial::shared_types::shared_int getRobotID()
Returns target robot/group # for this command.
SmCommandType command
int sequence
UINT32 value
#define LOG_COMM(format,...)
bool load(industrial::shared_types::shared_bool value)
#define LOG_ERROR(format,...)
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_real getData(size_t idx)
Returns command data.
bool unload(industrial::byte_array::ByteArray *buffer)
void setData(size_t idx, industrial::shared_types::shared_real val)
Sets command data.
MotionControlCmd getCommand()
Returns motion control command.
float data[ROS_MAX_JOINT]
bool operator==(MotionCtrl &rhs)
== operator implementation
industrial::shared_types::shared_int sequence_
Message-tracking number that will be echoed back in reply message.
void setRobotID(industrial::shared_types::shared_int robot_id)
Sets robot_id.
industrial::shared_types::shared_int robot_id_
Robot/group ID. 0 = 1st robot.
void init()
Initializes a empty motion control command.
bool unload(industrial::shared_types::shared_bool &value)
static const size_t MAX_DATA_CNT
Maximum length (# of float elements) of data buffer.
void copyFrom(MotionCtrl &src)
Copies the passed in value.
bool load(industrial::byte_array::ByteArray *buffer)
industrial::shared_types::shared_int getSequence()
Returns control command&#39;s sequence number.
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