task_space_vector.cpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2018, University of Edinburgh
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are met:
7 //
8 // * Redistributions of source code must retain the above copyright notice,
9 // this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of nor the names of its contributors may be used to
14 // endorse or promote products derived from this software without specific
15 // prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 // POSSIBILITY OF SUCH DAMAGE.
28 //
29 
31 
32 namespace exotica
33 {
34 TaskVectorEntry::TaskVectorEntry(int _id, RotationType _type) : id(_id), type(_type)
35 {
36 }
37 
39 
42 
43 TaskSpaceVector& TaskSpaceVector::operator=(std::initializer_list<double> other)
44 {
45  if (other.size() != data.rows()) ThrowPretty("Wrong initializer size: " << other.size() << " expecting " << data.rows());
46  int i = 0;
47  for (const double& val : other)
48  {
49  data(i++) = val;
50  }
51  return *this;
52 }
53 
54 void TaskSpaceVector::SetZero(const int n)
55 {
56  data = Eigen::VectorXd::Zero(n);
57  for (const TaskVectorEntry& entry : map)
58  {
59  const int len = GetRotationTypeLength(entry.type);
60  data.segment(entry.id, len) = SetRotation(KDL::Rotation(), entry.type);
61  }
62 }
63 
64 Eigen::VectorXd TaskSpaceVector::operator-(const TaskSpaceVector& other)
65 {
66  if (data.rows() != other.data.rows()) ThrowPretty("Task space vector sizes do not match!");
67  int entry_size = 0;
68  for (const TaskVectorEntry& entry : map) entry_size += GetRotationTypeLength(entry.type);
69  Eigen::VectorXd ret(data.rows() + map.size() * 3 - entry_size);
70  int i_in = 0;
71  int i_out = 0;
72  for (const TaskVectorEntry& entry : map)
73  {
74  if (i_in < entry.id) ret.segment(i_out, entry.id - i_in) = data.segment(i_in, entry.id - i_in) - other.data.segment(i_in, entry.id - i_in);
75  i_out += entry.id - i_in;
76  i_in += entry.id - i_in;
77  const int len = GetRotationTypeLength(entry.type);
78 
79  KDL::Rotation M1 = GetRotation(data.segment(entry.id, len), entry.type);
80  KDL::Rotation M2 = GetRotation(other.data.segment(entry.id, len), entry.type);
81  KDL::Rotation M = M2.Inverse() * M1;
82  KDL::Vector rotvec = M1 * (M.GetRot());
83  ret(i_out) = rotvec[0];
84  ret(i_out + 1) = rotvec[1];
85  ret(i_out + 2) = rotvec[2];
86  i_out += 3;
87  i_in += len;
88  }
89  if (i_in < data.rows()) ret.segment(i_out, data.rows() - i_in) = data.segment(i_in, data.rows() - i_in) - other.data.segment(i_in, data.rows() - i_in);
90  return ret;
91 }
92 
93 std::vector<TaskVectorEntry> TaskVectorEntry::reindex(const std::vector<TaskVectorEntry>& _map, int _old_start, int _new_start)
94 {
95  std::vector<TaskVectorEntry> ret = _map;
96  for (TaskVectorEntry& entry : ret)
97  {
98  entry.id = entry.id - _old_start + _new_start;
99  }
100  return ret;
101 }
102 } // namespace exotica
Rotation Inverse() const
#define ThrowPretty(m)
Definition: exception.h:36
TaskSpaceVector & operator=(std::initializer_list< double > other)
KDL::Rotation GetRotation(Eigen::VectorXdRefConst data, RotationType type)
static std::vector< TaskVectorEntry > reindex(const std::vector< TaskVectorEntry > &_map, int _old_start, int _new_start)
Eigen::VectorXd operator-(const TaskSpaceVector &other)
Eigen::VectorXd SetRotation(const KDL::Rotation &data, RotationType type)
int GetRotationTypeLength(const RotationType &type)
Definition: conversions.h:93


exotica_core
Author(s): Yiming Yang, Michael Camilleri
autogenerated on Sat Apr 10 2021 02:34:49