CARLA
 
载入中...
搜索中...
未找到
PoseWithCovariance.cpp
浏览该文件的文档.
1// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15/*!
16 * @file PoseWithCovariance.cpp
17 * This source file contains the definition of the described types in the IDL file.
18 *
19 * This file was generated by the tool gen.
20 */
21
22#ifdef _WIN32
23// Remove linker warning LNK4221 on Visual Studio
24namespace {
25char dummy;
26} // namespace
27#endif // _WIN32
28
29#include "PoseWithCovariance.h"
30#include <fastcdr/Cdr.h>
31
32#include <fastcdr/exceptions/BadParamException.h>
33using namespace eprosima::fastcdr::exception;
34
35#include <utility>
36
37#define geometry_msgs_msg_Pose_max_cdr_typesize 56ULL;
38#define geometry_msgs_msg_Point_max_cdr_typesize 24ULL;
39#define geometry_msgs_msg_PoseWithCovariance_max_cdr_typesize 344ULL;
40#define geometry_msgs_msg_Quaternion_max_cdr_typesize 32ULL;
41#define geometry_msgs_msg_Pose_max_key_cdr_typesize 0ULL;
42#define geometry_msgs_msg_Point_max_key_cdr_typesize 0ULL;
43#define geometry_msgs_msg_PoseWithCovariance_max_key_cdr_typesize 0ULL;
44#define geometry_msgs_msg_Quaternion_max_key_cdr_typesize 0ULL;
45
47{
48 // geometry_msgs::msg::Pose m_pose
49
50 // geometry_msgs::msg::geometry_msgs__PoseWithCovariance__double_array_36 m_covariance
51 memset(&m_covariance, 0, (36) * 8);
52}
53
57
64
66 PoseWithCovariance&& x) noexcept
67{
68 // 使用 std::move 迁移参数 x 的成员变量 m_pose 到当前对象的 m_pose
69 m_pose = std::move(x.m_pose);
70
71 // 使用 std::move 迁移参数 x 的成员变量 m_covariance 到当前对象的 m_covariance
72 m_covariance = std::move(x.m_covariance);
73}
74
83
85 PoseWithCovariance&& x) noexcept
86{
87 // 使用 std::move 迁移参数 x 的成员变量 m_pose 到当前对象的 m_pose
88 m_pose = std::move(x.m_pose);
89
90 // 使用 std::move 迁移参数 x 的成员变量 m_covariance 到当前对象的 m_covariance
91 m_covariance = std::move(x.m_covariance);
92
93 // 返回当前对象本身,以支持链式赋值
94 return *this;
95}
96
97
98bool ImuPubSubType::getKey(
99 void* data,
100 InstanceHandle_t* handle,
101 bool force_md5)
102{
103 // 检查是否定义了键,如果没有定义获取键的相关操作,就直接返回false
104 if (!m_isGetKeyDefined) // 检查是否定义了键
105 {
106 return false; // 如果没有定义,返回false
107 }
108
109 // 将传入的void*类型的数据指针转换为Imu类型指针,以便后续能正确操作Imu类型相关的数据
110 Imu* p_type = static_cast<Imu*>(data); // 将数据指针转换为Imu类型指针
111
112 // 管理原始缓冲区的对象
113 // 使用m_keyBuffer(应该是类成员缓冲区相关变量)和键的最大序列化大小来初始化FastBuffer,
114 // 这里的FastBuffer可能用于后续存储序列化数据等操作,reinterpret_cast用于进行类型的重新解释转换
115 eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast<char*>(m_keyBuffer),
116 Imu::getKeyMaxCdrSerializedSize()); // 使用m_keyBuffer和键的最大序列化大小初始化FastBuffer
117
118 // 负责序列化数据的对象
119 // 创建Cdr对象,指定使用大端序列化方式(BIG_ENDIANNESS),传入前面初始化好的FastBuffer,
120 // 这个Cdr对象后续将用于执行实际的序列化操作
121 eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS); // 创建Cdr对象,使用大端序列化
122
123 // 调用Imu类型对象的serializeKey方法,通过传入的Cdr对象ser来对键进行序列化操作,
124 // 具体的序列化逻辑应该在Imu类的serializeKey实现中定义
125 p_type->serializeKey(ser); // 序列化键
126
127 // 如果强制生成MD5或者键的最大序列化大小大于16,就需要进行MD5相关计算
128 if (force_md5 || Imu::getKeyMaxCdrSerializedSize() > 16)
129 {
130 // 初始化MD5计算相关操作,应该是准备好进行MD5哈希值计算的初始状态
131 m_md5.init(); // 初始化MD5计算
132 // 使用已经序列化好的数据(存储在m_keyBuffer中,长度通过ser.getSerializedDataLength获取)来更新MD5计算,
133 // 也就是逐步将数据纳入MD5的计算过程中
134 m_md5.update(m_keyBuffer, static_cast<unsigned int>(ser.getSerializedDataLength())); // 更新MD5
135 // 完成MD5计算,最终确定MD5的哈希值
136 m_md5.finalize(); // 完成MD5计算
137
138 // 将计算得到的MD5结果(存储在m_md5.digest中)逐个字节复制到实例句柄的value数组中,
139 // 以便后续通过实例句柄来标识这个特定的Imu相关的数据,这里只取前16个字节(可能是MD5结果固定长度相关要求)
140 for (uint8_t i = 0; i < 16; ++i) // 将MD5结果存储到实例句柄中
141 {
142 handle->value[i] = m_md5.digest[i];
143 }
144 }
145 else
146 {
147 // 如果不需要MD5计算,也就是不满足前面MD5计算的条件时,
148 // 直接将序列化后存储在m_keyBuffer中的键数据(前面已经序列化过了)逐个字节复制到实例句柄的value数组中
149 for (uint8_t i = 0; i < 16; ++i)
150 {
151 handle->value[i] = m_keyBuffer[i];
152 }
153 }
154 return true; // 成功获取键,返回true
155}
156{
157 // 保存当前的对齐位置
159
160 // 计算 Pose 部分序列化后的大小
161 // 获取 Pose 类型的对象(data.pose())序列化后的大小,并更新 current_alignment
163
164 // 计算协方差(covariance)数组的序列化大小
165 // 协方差是一个 6x6 的矩阵,共 36 个元素,每个元素 8 字节(double 类型)
166 current_alignment += ((36) * 8) + eprosima::fastcdr::Cdr::alignment(current_alignment, 8);
167
168 // 返回序列化数据的总大小(当前对齐位置与初始对齐位置之差)
170}
171
172
174 eprosima::fastcdr::Cdr& scdr) const
175{
176 scdr << m_pose;
177 scdr << m_covariance;
178}
179
181 eprosima::fastcdr::Cdr& dcdr)
182{
183 dcdr >> m_pose;
184 dcdr >> m_covariance;
185}
186
187/*!
188 * @brief This function copies the value in member pose
189 * @param _pose New value to be copied in member pose
190 */
192 const geometry_msgs::msg::Pose& _pose)
193{
194 m_pose = _pose;
195}
196
197/*!
198 * @brief This function moves the value in member pose
199 * @param _pose New value to be moved in member pose
200 */
203{
204 m_pose = std::move(_pose);
205}
206
207/*!
208 * @brief This function returns a constant reference to member pose
209 * @return Constant reference to member pose
210 */
215
216/*!
217 * @brief This function returns a reference to member pose
218 * @return Reference to member pose
219 */
224/*!
225 * @brief This function copies the value in member covariance
226 * @param _covariance New value to be copied in member covariance
227 */
233
234/*!
235 * @brief This function moves the value in member covariance
236 * @param _covariance New value to be moved in member covariance
237 */
243
244/*!
245 * @brief This function returns a constant reference to member covariance
246 * @return Constant reference to member covariance
247 */
252
253/*!
254 * @brief This function returns a reference to member covariance
255 * @return Reference to member covariance
256 */
261
262
263// 函数用于获取PoseWithCovariance类型在CDR(Common Data Representation)序列化时键的最大尺寸。
264// 这里的参数current_alignment可能与内存对齐等相关,但在函数内部目前只是做了类型转换,没实际使用它来参与计算。
265// 返回值是geometry_msgs_msg_PoseWithCovariance_max_key_cdr_typesize,应该是预定义好的表示最大序列化键尺寸的常量。
267 size_t current_alignment)
268{
269 // 将current_alignment参数进行类型转换,但不做实际操作,目的可能是为了消除编译器对于未使用参数的警告。
270 static_cast<void>(current_alignment);
272}
273
274// 函数用于判断PoseWithCovariance类型是否定义了键,目前直接返回false,表示没有定义键。
279
280// 函数用于对PoseWithCovariance类型的键进行序列化操作,传入的参数scdr是一个Cdr对象,用于执行具体的序列化任务。
281// 不过在当前函数实现中,只是将传入的scdr参数做了类型转换(void转换),并没有实际进行有效的序列化逻辑,
282// 可能需要后续进一步完善该函数内部的实现来真正执行键的序列化工作。
284 eprosima::fastcdr::Cdr& scdr) const
285{
286 // 将传入的scdr参数进行类型转换(转换为void类型,相当于忽略它),这里可能是由于暂时还没编写具体序列化逻辑导致的。
287 (void) scdr;
288}
eprosima::fastrtps::rtps::InstanceHandle_t InstanceHandle_t
#define geometry_msgs_msg_PoseWithCovariance_max_key_cdr_typesize
Definition Odometry.cpp:54
return current_alignment initial_alignment
This class represents the structure PoseWithCovariance defined by the user in the IDL file.
geometry_msgs::msg::geometry_msgs__PoseWithCovariance__double_array_36 m_covariance
eProsima_user_DllExport void serialize(eprosima::fastcdr::Cdr &cdr) const
This function serializes an object using CDR serialization.
eProsima_user_DllExport const geometry_msgs::msg::Pose & pose() const
This function returns a constant reference to member pose
static eProsima_user_DllExport size_t getKeyMaxCdrSerializedSize(size_t current_alignment=0)
This function returns the maximum serialized size of the Key of an object depending on the buffer ali...
eProsima_user_DllExport void serializeKey(eprosima::fastcdr::Cdr &cdr) const
This function serializes the key members of an object using CDR serialization.
eProsima_user_DllExport ~PoseWithCovariance()
Default destructor.
eProsima_user_DllExport const geometry_msgs::msg::geometry_msgs__PoseWithCovariance__double_array_36 & covariance() const
This function returns a constant reference to member covariance
static eProsima_user_DllExport bool isKeyDefined()
This function tells you if the Key has been defined for this type
eProsima_user_DllExport PoseWithCovariance()
Default constructor.
eProsima_user_DllExport PoseWithCovariance & operator=(const PoseWithCovariance &x)
Copy assignment.
eProsima_user_DllExport void deserialize(eprosima::fastcdr::Cdr &cdr)
This function deserializes an object using CDR serialization.
此类表示IDL文件中定义的Pose结构。 <>
Definition Pose.h:75
static eProsima_user_DllExport size_t getCdrSerializedSize(const geometry_msgs::msg::Pose &data, size_t current_alignment=0)
返回数据的序列化大小,取决于缓冲区对齐。
Definition Pose.cpp:118
std::array< double, 36 > geometry_msgs__PoseWithCovariance__double_array_36