smooth
A C++ library for Lie theory
Loading...
Searching...
No Matches
ros.hpp
Go to the documentation of this file.
1// Copyright (C) 2022 Petter Nilsson. MIT License.
2
3#pragma once
4
10#include <geometry_msgs/msg/pose.hpp>
11#include <geometry_msgs/msg/transform.hpp>
12
13#include "smooth/se3.hpp"
14
15using namespace geometry_msgs::msg;
16
17// Statically check that messages are laid out as expected in memory
18
19// Vector3
20static_assert(std::is_same_v<decltype(Vector3::x), double>);
21static_assert(std::is_same_v<decltype(Vector3::y), double>);
22static_assert(std::is_same_v<decltype(Vector3::z), double>);
23
24static_assert(offsetof(Vector3, x) == 0);
25static_assert(offsetof(Vector3, y) == sizeof(double));
26static_assert(offsetof(Vector3, z) == 2 * sizeof(double));
27
28// Point
29static_assert(std::is_same_v<decltype(Point::x), double>);
30static_assert(std::is_same_v<decltype(Point::y), double>);
31static_assert(std::is_same_v<decltype(Point::z), double>);
32
33static_assert(offsetof(Point, x) == 0);
34static_assert(offsetof(Point, y) == sizeof(double));
35static_assert(offsetof(Point, z) == 2 * sizeof(double));
36
37// Quaternion
38static_assert(std::is_same_v<decltype(Quaternion::x), double>);
39static_assert(std::is_same_v<decltype(Quaternion::y), double>);
40static_assert(std::is_same_v<decltype(Quaternion::z), double>);
41static_assert(std::is_same_v<decltype(Quaternion::w), double>);
42
43static_assert(offsetof(Quaternion, x) == 0);
44static_assert(offsetof(Quaternion, y) == sizeof(double));
45static_assert(offsetof(Quaternion, z) == 2 * sizeof(double));
46static_assert(offsetof(Quaternion, w) == 3 * sizeof(double));
47
48// Pose
49static_assert(std::is_same_v<decltype(Pose::position), Point>);
50static_assert(std::is_same_v<decltype(Pose::orientation), Quaternion>);
51static_assert(offsetof(Pose, position) == 0);
52static_assert(offsetof(Pose, orientation) == sizeof(Point));
53
54// Tranform
55static_assert(std::is_same_v<decltype(Transform::translation), Vector3>);
56static_assert(std::is_same_v<decltype(Transform::rotation), Quaternion>);
57static_assert(offsetof(Transform, translation) == 0);
58static_assert(offsetof(Transform, rotation) == sizeof(Vector3));
59
60// generic
61
63#define CREATE_MAPS(DATATYPE, LIETYPE, BASETYPE) \
64 \
65 template<> \
66 struct smooth::liebase_info<smooth::Map<DATATYPE>> : public liebase_info<LIETYPE> \
67 {}; \
68 \
69 \
70 template<> \
71 class smooth::Map<DATATYPE> : public BASETYPE<smooth::Map<DATATYPE>> \
72 { \
73 using Base = BASETYPE<smooth::Map<DATATYPE>>; \
74 \
75 public: \
76 \
77 SMOOTH_INHERIT_TYPEDEFS; \
78 \
79 \
80 explicit Map(DATATYPE & msg) : m_coeffs(reinterpret_cast<double *>(&msg)) {} \
81 \
82 using Storage = Eigen::Map<Eigen::Matrix<double, RepSize, 1>>; \
83 \
84 Storage & coeffs() { return m_coeffs; } \
85 \
86 const Storage & coeffs() const { return m_coeffs; } \
87 \
88 Scalar * data() { return m_coeffs.data(); } \
89 \
90 const Scalar * data() const { return m_coeffs.data(); } \
91 \
92 private: \
93 Storage m_coeffs; \
94 }; \
95 \
96 \
97 template<> \
98 struct smooth::liebase_info<smooth::Map<const DATATYPE>> : public liebase_info<LIETYPE> \
99 { \
100 \
101 static constexpr bool is_mutable = false; \
102 }; \
103 \
104 \
105 template<> \
106 class smooth::Map<const DATATYPE> : public BASETYPE<smooth::Map<const DATATYPE>> \
107 { \
108 using Base = BASETYPE<smooth::Map<const DATATYPE>>; \
109 \
110 public: \
111 \
112 SMOOTH_INHERIT_TYPEDEFS; \
113 \
114 \
115 explicit Map(const DATATYPE & msg) : m_coeffs(reinterpret_cast<const double *>(&msg)) {} \
116 \
117 using Storage = Eigen::Map<const Eigen::Matrix<double, RepSize, 1>>; \
118 \
119 const Storage & coeffs() const { return m_coeffs; } \
120 \
121 const Scalar * data() const { return m_coeffs.data(); } \
122 \
123 private: \
124 Storage m_coeffs; \
125 }; \
126 \
127 static_assert(true, "")
128
129CREATE_MAPS(geometry_msgs::msg::Quaternion, smooth::SO3d, smooth::SO3Base);
130CREATE_MAPS(geometry_msgs::msg::Pose, smooth::SE3d, smooth::SE3Base);
131CREATE_MAPS(geometry_msgs::msg::Transform, smooth::SE3d, smooth::SE3Base);
#define CREATE_MAPS(DATATYPE, LIETYPE, BASETYPE)
Map message DATATYPE as implementation LIETYPE with CRTP base BASETYPE.
Definition ros.hpp:63