tf2  master
tf2 maintains the relationship between coordinate frames in a tree structure buffered in time, and lets the user transform points, vectors, etc between any two coordinate frames at any desired point in time.
convert.h
Go to the documentation of this file.
1 // Copyright 2008, Willow Garage, Inc. All rights reserved.
2 //
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 //
9 // * Redistributions in binary form must reproduce the above copyright
10 // notice, this list of conditions and the following disclaimer in the
11 // documentation and/or other materials provided with the distribution.
12 //
13 // * Neither the name of the Willow Garage nor the names of its
14 // contributors may be used to endorse or promote products derived from
15 // this software without specific 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 HOLDER 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 
31 #ifndef TF2__CONVERT_H_
32 #define TF2__CONVERT_H_
33 
34 #include <array>
35 #include <string>
36 
37 #include "builtin_interfaces/msg/time.hpp"
38 #include "geometry_msgs/msg/transform_stamped.hpp"
39 #include "rosidl_runtime_cpp/traits.hpp"
40 #include "tf2/exceptions.h"
41 #include "tf2/impl/convert.h"
43 #include "tf2/visibility_control.h"
44 
45 namespace tf2
46 {
47 
57 template<class T>
58 void doTransform(
59  const T & data_in, T & data_out,
60  const geometry_msgs::msg::TransformStamped & transform);
61 
66 template<class T>
67 tf2::TimePoint getTimestamp(const T & t);
68 
73 template<class T>
74 std::string getFrameId(const T & t);
75 
80 template<class T>
82 
90 template<class P>
92 {
93  return t.stamp_;
94 }
95 
103 template<class P>
105 {
106  return t.frame_id_;
107 }
108 
116 template<class P>
118 {
119  return t.cov_mat_;
120 }
121 
128 template<typename A, typename B>
129 B toMsg(const A & a);
130 
137 template<typename A, typename B>
138 void fromMsg(const A &, B & b);
139 
147 template<class A, class B>
148 void convert(const A & a, B & b)
149 {
151  rosidl_generator_traits::is_message<B>::value>::convert(a, b);
152 }
153 
154 template<class A>
155 void convert(const A & a1, A & a2)
156 {
157  if (&a1 != &a2) {
158  a2 = a1;
159  }
160 }
161 
167 inline
169 {
170  std::array<std::array<double, 6>, 6> nested_array = {};
171  size_t l1 = 0, l2 = 0;
172  for (const double & val : row_major) {
173  nested_array[l2][l1] = val;
174 
175  l1++;
176 
177  if (l1 == nested_array[0].size()) {
178  l1 = 0;
179  l2++;
180  }
181  }
182  return nested_array;
183 }
184 
190 inline
192 {
193  std::array<double, 36> row_major = {};
194  size_t counter = 0;
195  for (const auto & arr : nested_array) {
196  for (const double & val : arr) {
197  row_major[counter] = val;
198  counter++;
199  }
200  }
201  return row_major;
202 }
203 } // namespace tf2
204 
205 #endif // TF2__CONVERT_H_
tf2::convert
void convert(const A &a, B &b)
Function that converts any type to any type (messages or not). Matching toMsg and from Msg conversion...
Definition: convert.h:148
exceptions.h
std::string
tf2::Stamped::stamp_
TimePoint stamp_
The timestamp associated with this data.
Definition: transform_datatypes.h:49
tf2::fromMsg
void fromMsg(const A &, B &b)
Function that converts from a ROS message type to another type. It has to be implemented by each data...
tf2::Stamped
The data type which will be cross compatable with geometry_msgs This is the tf2 datatype equivilant o...
Definition: transform_datatypes.h:46
tf2::getFrameId
std::string getFrameId(const T &t)
Get the frame_id from data.
tf2::covarianceRowMajorToNested
std::array< std::array< double, 6 >, 6 > covarianceRowMajorToNested(const std::array< double, 36 > &row_major)
Function that converts from a row-major representation of a 6x6 covariance matrix to a nested array r...
Definition: convert.h:168
tf2::covarianceNestedToRowMajor
std::array< double, 36 > covarianceNestedToRowMajor(const std::array< std::array< double, 6 >, 6 > &nested_array)
Function that converts from a nested array representation of a 6x6 covariance matrix to a row-major r...
Definition: convert.h:191
tf2::Stamped::frame_id_
std::string frame_id_
The frame_id associated this data.
Definition: transform_datatypes.h:50
std::array
std::chrono::time_point< std::chrono::system_clock, Duration >
tf2::WithCovarianceStamped::cov_mat_
std::array< std::array< double, 6 >, 6 > cov_mat_
The covariance matrix associated with this data.
Definition: transform_datatypes.h:100
tf2::getCovarianceMatrix
std::array< std::array< double, 6 >, 6 > getCovarianceMatrix(const T &t)
Get the covariance matrix from data.
visibility_control.h
convert.h
tf2::WithCovarianceStamped
The data type which will be cross compatable with geometry_msgs This is the tf2 datatype equivalent o...
Definition: transform_datatypes.h:95
tf2::impl::Converter
Definition: convert.h:38
tf2
Definition: buffer_core.h:53
tf2::toMsg
B toMsg(const A &a)
Function that converts from one type to a ROS message type. It has to be implemented by each data typ...
tf2::doTransform
void doTransform(const T &data_in, T &data_out, const geometry_msgs::msg::TransformStamped &transform)
The templated function expected to be able to do a transform.
transform_datatypes.h
tf2::getTimestamp
tf2::TimePoint getTimestamp(const T &t)
Get the timestamp from data.