joint_feedback_ex.cpp
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2014, Fraunhofer IPA
5  * Author: Thiago de Freitas
6  *
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions are met:
11  *
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above copyright
15  * notice, this list of conditions and the following disclaimer in the
16  * documentation and/or other materials provided with the distribution.
17  * * Neither the name of the Fraunhofer IPA, nor the names
18  * of its contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 #include <vector>
35 
36 #ifndef FLATHEADERS
40 #else
41 #include "joint_feedback_ex.h" // NOLINT(build/include)
42 #include "shared_types.h" // NOLINT(build/include)
43 #include "log_wrapper.h" // NOLINT(build/include)
44 #endif
45 
48 
49 namespace industrial
50 {
51 namespace joint_feedback_ex
52 {
53 
55 {
56  this->init();
57 }
59 {
60 }
61 
63 {
64  this->groups_number_ = 0;
65 }
66 
68  std::vector<joint_feedback_message::JointFeedbackMessage> joints_feedback_points)
69 {
70  this->setGroupsNumber(groups_number);
71  this->joint_feedback_messages_ = joints_feedback_points;
72 }
73 
75 {
76  this->setGroupsNumber(src.getGroupsNumber());
78 }
79 
81 {
82  return this->groups_number_ == rhs.groups_number_;
83 }
84 
86 {
87  LOG_COMM("Executing joint feedback load");
88 
89 
90  for (int i = 0; i < this->groups_number_; i++)
91  {
92  if (!buffer->load(this->joint_feedback_messages_[i]))
93  {
94  LOG_ERROR("Failed to load the Joint Feedback messages");
95  return false;
96  }
97  }
98 
99  if (!buffer->load(this->groups_number_))
100  {
101  LOG_ERROR("Failed to load joint feedback groups_number");
102  return false;
103  }
104 
105 
106  LOG_COMM("Joint feedback successfully loaded");
107  return true;
108 }
109 
111 {
112  LOG_COMM("Executing joint feedback unload");
113 
114  if (!buffer->unloadFront(this->groups_number_))
115  {
116  LOG_ERROR("Failed to unload joint feedback groups_number");
117  return false;
118  }
119 
120  // deserialise all JointFeedback submsgs contained in the buffer, going from
121  // back to front (ie: start with the last and end with the first). But only
122  // retain deserialised msgs that actually contain valid data.
123  //
124  // Note: we cannot assume that there is a 1-to-1 mapping between the order of
125  // JointFeedback msgs in the buffer and motion groups on the controller.
126  // Because of that we have to deserialise all submsgs and check validity
127  // of each individually (ie: we cannot skip submsgs 3 & 4 if there are only
128  // two motion groups, as the data for grp1 could be in submsg 3 fi).
129  for (std::size_t i = 0; i < MAX_NUM_GROUPS; ++i)
130  {
131  JointFeedbackMessage tmp_msg;
132  JointFeedback j_feedback;
133 
134  if (!buffer->unload(j_feedback))
135  {
136  LOG_ERROR("Failed to unload joint feedback groups_number");
137  return false;
138  }
139 
140  // every msg gets deserialised, but we only keep those with valid data.
141  //
142  // TODO( ): is a message with just 'TIME' also valid? For now it is not (not
143  // sure how that would work anyway, as Jointfeedback msgs are assumed to
144  // contain joint feedback. Time alone would not seem to fit in that
145  // category).
149  {
150  tmp_msg.init(j_feedback);
151  this->joint_feedback_messages_.push_back(tmp_msg);
152  }
153  }
154 
155  LOG_COMM("Joint feedback successfully unloaded");
156  return true;
157 }
158 
159 } // namespace joint_feedback_ex
160 } // namespace industrial
161 
162 
void init()
Initializes a empty joint feedback ex.
bool init(industrial::simple_message::SimpleMessage &msg)
#define LOG_COMM(format,...)
bool unloadFront(industrial::shared_types::shared_real &value)
bool load(industrial::shared_types::shared_bool value)
bool unload(industrial::byte_array::ByteArray *buffer)
#define LOG_ERROR(format,...)
bool load(industrial::byte_array::ByteArray *buffer)
check the validity state for a given field
void setGroupsNumber(industrial::shared_types::shared_int groups_number)
Sets groups_number_ Numbers of group, this sets the amount of control groups connected to the control...
industrial::shared_types::shared_int groups_number_
Number of groups attached to the controller.
static const industrial::shared_types::shared_int MAX_NUM_GROUPS
void copyFrom(JointFeedbackEx &src)
Copies the passed in value.
bool is_valid(ValidFieldType field)
industrial::shared_types::shared_int getGroupsNumber()
Gets groups_number Gets the number of groups currently running on the controller. ...
std::vector< industrial::joint_feedback_message::JointFeedbackMessage > joint_feedback_messages_
bool unload(industrial::shared_types::shared_bool &value)
bool operator==(JointFeedbackEx &rhs)
== operator implementation


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