advanced_chainfksolver_recursive.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9 
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 
18 #include <ros/ros.h>
20 
22  chain_(_chain)
23 {
24 }
25 
32 {
33  unsigned int segmentNr;
34  if (seg_nr < 0)
35  {
36  segmentNr = this->chain_.getNrOfSegments();
37  }
38  else
39  {
40  segmentNr = seg_nr;
41  }
42 
43  p_out = KDL::Frame::Identity();
44 
45  if (q_in.rows() != this->chain_.getNrOfJoints())
46  {
47  return -1;
48  }
49  else if (segmentNr > this->chain_.getNrOfSegments())
50  {
51  return -1;
52  }
53  else
54  {
55  this->segment_pos_.clear();
56  int j = 0;
57  for (unsigned int i = 0; i < segmentNr; i++)
58  {
60  {
61  p_out = p_out * this->chain_.getSegment(i).pose(q_in(j));
62  j++;
63  }
64  else
65  {
66  p_out = p_out * this->chain_.getSegment(i).pose(0.0);
67  }
68 
69  this->segment_pos_.push_back(KDL::Frame(p_out)); // store copies not references
70  }
71  return 0;
72  }
73 }
74 
79 {
81 
82  if (seg_idx < this->chain_.getNrOfSegments())
83  {
84  p_out = this->segment_pos_.at(seg_idx);
85  }
86 
87  return p_out;
88 }
89 
94 {
95  uint16_t id = 0;
96  ROS_INFO_STREAM("=== Dump all Jnt Postures ===");
97  for (FrameVector_t::const_iterator it = this->segment_pos_.begin(); it != this->segment_pos_.end(); ++it)
98  {
99  ROS_INFO_STREAM("Segment " << id++ << ". Position: " << std::endl <<
100  it->p.x() << std::endl <<
101  it->p.y() << std::endl <<
102  it->p.z());
103  ROS_INFO_STREAM("Rotation: " << std::endl <<
104  it->M.GetRot().x() << std::endl <<
105  it->M.GetRot().y() << std::endl <<
106  it->M.GetRot().z() << std::endl <<
107  "=================================");
108  }
109 }
110 
111 
113 {
114 }
115 
116 
118  chain_(_chain)
119 {
120 }
121 
128 {
129  unsigned int segmentNr;
130  if (seg_nr < 0)
131  {
132  segmentNr = this->chain_.getNrOfSegments();
133  }
134  else
135  {
136  segmentNr = seg_nr;
137  }
138 
139  out = KDL::FrameVel::Identity();
140 
141  if (!(q_in.q.rows() == this->chain_.getNrOfJoints() && q_in.qdot.rows() == this->chain_.getNrOfJoints()))
142  {
143  ROS_ERROR("Rows do not match!");
144  return -1;
145  }
146  else if (segmentNr > this->chain_.getNrOfSegments())
147  {
148  return -2;
149  }
150  else
151  {
152  this->segment_vel_.clear();
153  int j = 0;
154  for (unsigned int i = 0; i < segmentNr; ++i)
155  {
156  // Calculate new Frame_base_ee
157  if (this->chain_.getSegment(i).getJoint().getType() != KDL::Joint::None)
158  {
159  out = out * KDL::FrameVel(this->chain_.getSegment(i).pose(q_in.q(j)),
160  this->chain_.getSegment(i).twist(q_in.q(j), q_in.qdot(j)));
161  j++; // Only increase jointnr if the segment has a joint
162  }
163  else
164  {
165  out = out * KDL::FrameVel(this->chain_.getSegment(i).pose(0.0),
166  this->chain_.getSegment(i).twist(0.0, 0.0));
167  }
168 
169  this->segment_vel_.push_back(KDL::FrameVel(out));
170  }
171 
172  return 0;
173  }
174 }
175 
177  std::vector<KDL::FrameVel>& out,
178  int seg_nr)
179 {
180  unsigned int segmentNr;
181  if (seg_nr < 0)
182  segmentNr = chain_.getNrOfSegments();
183  else
184  segmentNr = seg_nr;
185 
186  if (!(in.q.rows() == chain_.getNrOfJoints() && in.qdot.rows() == chain_.getNrOfJoints()))
187  return -1;
188  else if (segmentNr > chain_.getNrOfSegments())
189  return -1;
190  else if (out.size() != segmentNr)
191  return -1;
192  else if (segmentNr == 0)
193  return -1;
194  else
195  {
196  int j = 0;
197  // Initialization
199  {
200  out[0] = KDL::FrameVel(chain_.getSegment(0).pose(in.q(0)), chain_.getSegment(0).twist(in.q(0), in.qdot(0)));
201  j++;
202  }
203  else
204  out[0] = KDL::FrameVel(chain_.getSegment(0).pose(0.0), chain_.getSegment(0).twist(0.0, 0.0));
205 
206  for (unsigned int i = 1; i < segmentNr; i++)
207  {
208  // Calculate new Frame_base_ee
210  {
211  out[i] =
212  out[i - 1] * KDL::FrameVel(chain_.getSegment(i).pose(in.q(j)), chain_.getSegment(i).twist(in.q(j), in.qdot(j)));
213  j++; // Only increase jointnr if the segment has a joint
214  }
215  else
216  {
217  out[i] = out[i - 1] * KDL::FrameVel(chain_.getSegment(i).pose(0.0), chain_.getSegment(i).twist(0.0, 0.0));
218  }
219  }
220  return 0;
221  }
222 }
223 
225 {
227 
228  if (seg_idx < this->chain_.getNrOfSegments())
229  {
230  vel_out = this->segment_vel_.at(seg_idx);
231  }
232 
233  return vel_out;
234 }
235 
236 
238 {
239 }
const Segment & getSegment(unsigned int nr) const
unsigned int rows() const
KDL::Frame getFrameAtSegment(uint16_t seg_idx) const
unsigned int getNrOfSegments() const
KDL::FrameVel getFrameVelAtSegment(uint16_t seg_idx) const
virtual int JntToCart(const KDL::JntArray &q_in, KDL::Frame &p_out, int seg_nr=-1)
Frame pose(const double &q) const
Twist twist(const double &q, const double &qdot) const
virtual int JntToCart(const KDL::JntArrayVel &q_in, KDL::FrameVel &out, int seg_nr=-1)
static IMETHOD FrameVel Identity()
const Joint & getJoint() const
unsigned int getNrOfJoints() const
#define ROS_INFO_STREAM(args)
static Frame Identity()
#define ROS_ERROR(...)
const JointType & getType() const


cob_obstacle_distance
Author(s): Marco Bezzon
autogenerated on Thu Apr 8 2021 02:39:47