Carma-platform v4.2.0
CARMA Platform is built on robot operating system (ROS) and utilizes open source software (OSS) that enables Cooperative Driving Automation (CDA) features to allow Automated Driving Systems to interact and cooperate with infrastructure and other vehicles through communication.
covariance_helper.h
Go to the documentation of this file.
1#pragma once
2
3// Copyright 2008 Willow Garage, Inc.
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
9// notice, this list of conditions and the following disclaimer.
10//
11// * Redistributions in binary form must reproduce the above copyright
12// notice, this list of conditions and the following disclaimer in the
13// documentation and/or other materials provided with the distribution.
14//
15// * Neither the name of the Willow Garage, Inc. nor the names of its
16// contributors may be used to endorse or promote products derived from
17// this software without specific prior written permission.
18//
19// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29// POSSIBILITY OF SUCH DAMAGE.
30
39#include <tf2_geometry_msgs/tf2_geometry_msgs.h>
40
42
56inline
57geometry_msgs::msg::PoseWithCovariance::_covariance_type transformCovariance(
58 const geometry_msgs::msg::PoseWithCovariance::_covariance_type & cov_in,
59 const tf2::Transform & transform)
60{
78 // get rotation matrix (and transpose)
79 const tf2::Matrix3x3 R = transform.getBasis();
80 const tf2::Matrix3x3 R_transpose = R.transpose();
81
82 // convert covariance matrix into four 3x3 blocks
83 // *INDENT-OFF*
84 const tf2::Matrix3x3 cov_11(cov_in[0], cov_in[1], cov_in[2],
85 cov_in[6], cov_in[7], cov_in[8],
86 cov_in[12], cov_in[13], cov_in[14]);
87 const tf2::Matrix3x3 cov_12(cov_in[3], cov_in[4], cov_in[5],
88 cov_in[9], cov_in[10], cov_in[11],
89 cov_in[15], cov_in[16], cov_in[17]);
90 const tf2::Matrix3x3 cov_21(cov_in[18], cov_in[19], cov_in[20],
91 cov_in[24], cov_in[25], cov_in[26],
92 cov_in[30], cov_in[31], cov_in[32]);
93 const tf2::Matrix3x3 cov_22(cov_in[21], cov_in[22], cov_in[23],
94 cov_in[27], cov_in[28], cov_in[29],
95 cov_in[33], cov_in[34], cov_in[35]);
96 // *INDENT-ON*
97
98 // perform blockwise matrix multiplication
99 const tf2::Matrix3x3 result_11 = R * cov_11 * R_transpose;
100 const tf2::Matrix3x3 result_12 = R * cov_12 * R_transpose;
101 const tf2::Matrix3x3 result_21 = R * cov_21 * R_transpose;
102 const tf2::Matrix3x3 result_22 = R * cov_22 * R_transpose;
103
104 // form the output
105 geometry_msgs::msg::PoseWithCovariance::_covariance_type cov_out;
106 cov_out[0] = result_11[0][0];
107 cov_out[1] = result_11[0][1];
108 cov_out[2] = result_11[0][2];
109 cov_out[6] = result_11[1][0];
110 cov_out[7] = result_11[1][1];
111 cov_out[8] = result_11[1][2];
112 cov_out[12] = result_11[2][0];
113 cov_out[13] = result_11[2][1];
114 cov_out[14] = result_11[2][2];
115
116 cov_out[3] = result_12[0][0];
117 cov_out[4] = result_12[0][1];
118 cov_out[5] = result_12[0][2];
119 cov_out[9] = result_12[1][0];
120 cov_out[10] = result_12[1][1];
121 cov_out[11] = result_12[1][2];
122 cov_out[15] = result_12[2][0];
123 cov_out[16] = result_12[2][1];
124 cov_out[17] = result_12[2][2];
125
126 cov_out[18] = result_21[0][0];
127 cov_out[19] = result_21[0][1];
128 cov_out[20] = result_21[0][2];
129 cov_out[24] = result_21[1][0];
130 cov_out[25] = result_21[1][1];
131 cov_out[26] = result_21[1][2];
132 cov_out[30] = result_21[2][0];
133 cov_out[31] = result_21[2][1];
134 cov_out[32] = result_21[2][2];
135
136 cov_out[21] = result_22[0][0];
137 cov_out[22] = result_22[0][1];
138 cov_out[23] = result_22[0][2];
139 cov_out[27] = result_22[1][0];
140 cov_out[28] = result_22[1][1];
141 cov_out[29] = result_22[1][2];
142 cov_out[33] = result_22[2][0];
143 cov_out[34] = result_22[2][1];
144 cov_out[35] = result_22[2][2];
145
146 return cov_out;
147}
148
149} // covariance_helper
geometry_msgs::msg::PoseWithCovariance::_covariance_type transformCovariance(const geometry_msgs::msg::PoseWithCovariance::_covariance_type &cov_in, const tf2::Transform &transform)
Transform the covariance matrix of a PoseWithCovariance message to a new frame.