tf2 rolling
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.
Loading...
Searching...
No Matches
convert.hpp
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
33#ifndef TF2__CONVERT_HPP_
34#define TF2__CONVERT_HPP_
35
36#include <algorithm>
37#include <array>
38#include <string>
39
40#include "geometry_msgs/msg/transform_stamped.hpp"
41#include "rosidl_runtime_cpp/traits.hpp"
42#include "tf2/exceptions.hpp"
43#include "tf2/impl/convert.hpp"
46
47namespace tf2
48{
49
59template<class T>
61 const T & data_in, T & data_out,
62 const geometry_msgs::msg::TransformStamped & transform);
63
68template<class T>
70
75template<class T>
76std::string getFrameId(const T & t);
77
82template<class T>
83std::array<std::array<double, 6>, 6> getCovarianceMatrix(const T & t);
84
92template<class P>
94{
95 return t.stamp_;
96}
97
105template<class P>
106std::string getFrameId(const tf2::Stamped<P> & t)
107{
108 return t.frame_id_;
109}
110
118template<class P>
119std::array<std::array<double, 6>, 6> getCovarianceMatrix(const tf2::WithCovarianceStamped<P> & t)
120{
121 return t.cov_mat_;
122}
123
130template<typename A, typename B>
131B toMsg(const A & a);
132
139template<typename A, typename B>
140void fromMsg(const A & a, B & b);
141
149template<class A, class B>
150void convert(const A & a, B & b)
151{
153 rosidl_generator_traits::is_message<B>::value>::convert(a, b);
154}
155
156template<class A>
157void convert(const A & a1, A & a2)
158{
159 if (&a1 != &a2) {
160 a2 = a1;
161 }
162}
163
169inline
170std::array<std::array<double, 6>, 6> covarianceRowMajorToNested(
171 const std::array<double, 36> & row_major)
172{
173 std::array<std::array<double, 6>, 6> nested_array;
174 std::array<double, 36>::const_iterator ss = row_major.begin();
175 for (std::array<double, 6> & dd : nested_array) {
176 std::copy_n(ss, dd.size(), dd.begin());
177 ss += dd.size();
178 }
179 return nested_array;
180}
181
187inline
188std::array<double, 36> covarianceNestedToRowMajor(
189 const std::array<std::array<double, 6>, 6> & nested_array)
190{
191 std::array<double, 36> row_major = {};
192 size_t counter = 0;
193 for (const auto & arr : nested_array) {
194 for (const double & val : arr) {
195 row_major[counter] = val;
196 counter++;
197 }
198 }
199 return row_major;
200}
201} // namespace tf2
202
203#endif // TF2__CONVERT_HPP_
The data type which will be cross compatable with geometry_msgs This is the tf2 datatype equivilant o...
Definition transform_datatypes.hpp:49
TimePoint stamp_
The timestamp associated with this data.
Definition transform_datatypes.hpp:51
std::string frame_id_
The frame_id associated this data.
Definition transform_datatypes.hpp:52
The data type which will be cross compatable with geometry_msgs This is the tf2 datatype equivalent o...
Definition transform_datatypes.hpp:98
std::array< std::array< double, 6 >, 6 > cov_mat_
The covariance matrix associated with this data // NOLINT.
Definition transform_datatypes.hpp:102
Definition convert.hpp:39
Author: Tully Foote.
Definition buffer_core.hpp:58
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.hpp:170
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.hpp:188
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.
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...
std::string getFrameId(const T &t)
Get the frame_id from data.
tf2::TimePoint getTimestamp(const T &t)
Get the timestamp from data.
std::chrono::time_point< std::chrono::system_clock, Duration > TimePoint
Definition time.hpp:41
void fromMsg(const A &a, B &b)
Function that converts from a ROS message type to another type. It has to be implemented by each data...
std::array< std::array< double, 6 >, 6 > getCovarianceMatrix(const T &t)
Get the covariance matrix from data.
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.hpp:150
Author: Tully Foote.