joint_feedback.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 #ifndef FLATHEADERS
35 #else
36 #include "joint_feedback.h"
37 #include "shared_types.h"
38 #include "log_wrapper.h"
39 #endif
40 
41 using namespace industrial::joint_data;
42 using namespace industrial::shared_types;
43 
44 namespace industrial
45 {
46 namespace joint_feedback
47 {
48 
49 JointFeedback::JointFeedback(void)
50 {
51  this->init();
52 }
53 JointFeedback::~JointFeedback(void)
54 {
55 
56 }
57 
58 void JointFeedback::init()
59 {
60  this->robot_id_ = 0;
61  this->valid_fields_ = 0;
62  this->time_ = 0.0;
63  this->positions_.init();
64  this->velocities_.init();
65  this->accelerations_.init();
66 }
67 
68 void JointFeedback::init(industrial::shared_types::shared_int robot_id,
73  industrial::joint_data::JointData & accelerations)
74 {
75  this->setRobotID(robot_id);
76  this->setTime(time);
77  this->setPositions(positions);
78  this->setVelocities(velocities);
79  this->setAccelerations(accelerations);
80  this->valid_fields_ = valid_fields; // must happen after others are set
81 }
82 
83 void JointFeedback::copyFrom(JointFeedback &src)
84 {
85  this->setRobotID(src.getRobotID());
86  src.getTime(this->time_);
87  src.getPositions(this->positions_);
88  src.getVelocities(this->velocities_);
89  src.getAccelerations(this->accelerations_);
90  this->valid_fields_ = src.valid_fields_;
91 }
92 
93 bool JointFeedback::operator==(JointFeedback &rhs)
94 {
95  return this->robot_id_ == rhs.robot_id_ &&
96  this->valid_fields_ == rhs.valid_fields_ &&
97  ( !is_valid(ValidFieldTypes::TIME) || (this->time_ == rhs.time_) ) &&
98  ( !is_valid(ValidFieldTypes::POSITION) || (this->positions_ == rhs.positions_) ) &&
99  ( !is_valid(ValidFieldTypes::VELOCITY) || (this->velocities_ == rhs.velocities_) ) &&
100  ( !is_valid(ValidFieldTypes::ACCELERATION) || (this->accelerations_ == rhs.accelerations_) );
101 }
102 
103 bool JointFeedback::load(industrial::byte_array::ByteArray *buffer)
104 {
105  LOG_COMM("Executing joint feedback load");
106 
107  if (!buffer->load(this->robot_id_))
108  {
109  LOG_ERROR("Failed to load joint feedback robot_id");
110  return false;
111  }
112 
113  if (!buffer->load(this->valid_fields_))
114  {
115  LOG_ERROR("Failed to load joint feedback valid fields");
116  return false;
117  }
118 
119  if (!buffer->load(this->time_))
120  {
121  LOG_ERROR("Failed to load joint feedback time");
122  return false;
123  }
124 
125  if (!this->positions_.load(buffer))
126  {
127  LOG_ERROR("Failed to load joint feedback positions");
128  return false;
129  }
130 
131  if (!this->velocities_.load(buffer))
132  {
133  LOG_ERROR("Failed to load joint feedback velocities");
134  return false;
135  }
136 
137  if (!this->accelerations_.load(buffer))
138  {
139  LOG_ERROR("Failed to load joint feedback accelerations");
140  return false;
141  }
142 
143  LOG_COMM("Joint feedback successfully loaded");
144  return true;
145 }
146 
147 bool JointFeedback::unload(industrial::byte_array::ByteArray *buffer)
148 {
149  LOG_COMM("Executing joint feedback unload");
150 
151  if (!this->accelerations_.unload(buffer))
152  {
153  LOG_ERROR("Failed to unload joint feedback accelerations");
154  return false;
155  }
156 
157  if (!this->velocities_.unload(buffer))
158  {
159  LOG_ERROR("Failed to unload joint feedback velocities");
160  return false;
161  }
162 
163  if (!this->positions_.unload(buffer))
164  {
165  LOG_ERROR("Failed to unload joint feedback positions");
166  return false;
167  }
168 
169  if (!buffer->unload(this->time_))
170  {
171  LOG_ERROR("Failed to unload joint feedback time");
172  return false;
173  }
174 
175  if (!buffer->unload(this->valid_fields_))
176  {
177  LOG_ERROR("Failed to unload joint feedback valid fields");
178  return false;
179  }
180 
181  if (!buffer->unload(this->robot_id_))
182  {
183  LOG_ERROR("Faild to unload joint feedback robot_id");
184  return false;
185  }
186 
187  LOG_COMM("Joint feedback successfully unloaded");
188  return true;
189 }
190 
191 }
192 }
193 
bool getTime(industrial::shared_types::shared_real &time)
Returns joint feedback timestamp.
bool getPositions(industrial::joint_data::JointData &dest)
Returns a copy of the position data.
void init(const M_string &remappings)
Contains platform specific type definitions that guarantee the size of primitive data types...
Definition: shared_types.h:52
industrial::shared_types::shared_int robot_id_
robot group # (0-based) for controllers that support multiple axis-groups
industrial::joint_data::JointData positions_
joint feedback positional data
industrial::joint_data::JointData accelerations_
joint feedback acceleration data
#define LOG_COMM(format,...)
Definition: log_wrapper.h:104
industrial::joint_data::JointData velocities_
joint feedback velocity data
bool load(industrial::shared_types::shared_bool value)
loads a boolean into the byte array
Definition: byte_array.cpp:142
#define LOG_ERROR(format,...)
Definition: log_wrapper.h:108
bool getAccelerations(industrial::joint_data::JointData &dest)
Returns a copy of the acceleration data.
The byte array wraps a dynamic array of bytes (i.e. char).
Definition: byte_array.h:80
Class encapsulated joint data (positions, accelerations, velocity, torque, and/or effort)...
Definition: joint_data.h:68
industrial::shared_types::shared_int valid_fields_
bit-mask of (optional) fields that have been initialized with valid data
bool getVelocities(industrial::joint_data::JointData &dest)
Returns a copy of the velocity data.
Class encapsulated joint feedback data. This data represents the current state of each robot joint...
bool unload(industrial::shared_types::shared_bool &value)
unloads a boolean value from the byte array
Definition: byte_array.cpp:233
industrial::shared_types::shared_int getRobotID()
Gets robot_id. Robot group # (0-based), for controllers with multiple axis-groups.
industrial::shared_types::shared_real time_
joint data timestamp Typically, time since controller booted (in seconds)


simple_message
Author(s): Shaun Edwards
autogenerated on Sat Sep 21 2019 03:30:09