Fixposition SDK 0.0.0-heads/main-0-g97f6014
Collection of c++ libraries and apps for use with Fixposition products on Linux
Loading...
Searching...
No Matches
ros1.hpp
Go to the documentation of this file.
1/**
2 * \verbatim
3 * ___ ___
4 * \ \ / /
5 * \ \/ / Copyright (c) Fixposition AG (www.fixposition.com) and contributors
6 * / /\ \ License: see the LICENSE file
7 * /__/ \__\
8 * \endverbatim
9 *
10 * @file
11 * @brief Fixposition SDK: to_json() helpers for some ROS1 types
12 */
13#ifndef __FPSDK_COMMON_TO_JSON_ROS_HPP__
14#define __FPSDK_COMMON_TO_JSON_ROS_HPP__
15
16/* LIBC/STL */
17
18/* EXTERNAL */
19#include <nlohmann/json.hpp>
20
21/* PACKAGE */
22#include "../ros1.hpp"
23#include "../string.hpp"
24#include "../time.hpp"
25
26#ifndef _DOXYGEN_ // not documenting these
27/* ****************************************************************************************************************** */
28namespace ros {
29
30inline void to_json(nlohmann::json& j, const Time& m)
31{
32 j = nlohmann::json::object({ { "sec", m.sec }, { "nsec", m.nsec } });
33}
34
35} // namespace ros
36/* ****************************************************************************************************************** */
37namespace std_msgs {
38
39inline void to_json(nlohmann::json& j, const Header& m)
40{
41 j = nlohmann::json::object({ { "seq", m.seq }, { "stamp", m.stamp }, { "frame_id", m.frame_id } });
42}
43
44} // namespace std_msgs
45/* ****************************************************************************************************************** */
46namespace geometry_msgs {
47
48inline void to_json(nlohmann::json& j, const Vector3& m)
49{
50 j = nlohmann::json::object({ { "x", m.x }, { "y", m.y }, { "z", m.z } });
51}
52
53// ---------------------------------------------------------------------------------------------------------------------
54
55inline void to_json(nlohmann::json& j, const Point& m)
56{
57 j = nlohmann::json::object({ { "x", m.x }, { "y", m.y }, { "z", m.z } });
58}
59
60// ---------------------------------------------------------------------------------------------------------------------
61
62inline void to_json(nlohmann::json& j, const Quaternion& m)
63{
64 j = nlohmann::json::object({ { "x", m.x }, { "y", m.y }, { "z", m.z }, { "w", m.w } });
65}
66
67// ---------------------------------------------------------------------------------------------------------------------
68
69inline void to_json(nlohmann::json& j, const Transform& m)
70{
71 j = nlohmann::json::object({
72 { "translation", m.translation },
73 { "rotation", m.rotation },
74 });
75}
76
77// ---------------------------------------------------------------------------------------------------------------------
78
79inline void to_json(nlohmann::json& j, const TransformStamped& m)
80{
81 j = nlohmann::json::object({
82 { "header", m.header },
83 { "child_frame_id", m.child_frame_id },
84 { "transform", m.transform },
85 });
86}
87
88// ---------------------------------------------------------------------------------------------------------------------
89
90inline void to_json(nlohmann::json& j, const Pose& m)
91{
92 j = nlohmann::json::object({
93 { "position", m.position },
94 { "orientation", m.orientation },
95 });
96}
97
98// ---------------------------------------------------------------------------------------------------------------------
99
100inline void to_json(nlohmann::json& j, const PoseWithCovariance& m)
101{
102 j = nlohmann::json::object({
103 { "pose", m.pose },
104 { "covariance", m.covariance },
105 });
106}
107
108// ---------------------------------------------------------------------------------------------------------------------
109
110inline void to_json(nlohmann::json& j, const Twist& m)
111{
112 j = nlohmann::json::object({
113 { "linear", m.linear },
114 { "angular", m.angular },
115 });
116}
117
118// ---------------------------------------------------------------------------------------------------------------------
119
120inline void to_json(nlohmann::json& j, const TwistWithCovariance& m)
121{
122 j = nlohmann::json::object({
123 { "twist", m.twist },
124 { "covariance", m.covariance },
125 });
126}
127
128} // namespace geometry_msgs
129/* ****************************************************************************************************************** */
130namespace sensor_msgs {
131
132inline void to_json(nlohmann::json& j, const Imu& m)
133{
134 j = nlohmann::json::object({
135 { "header", m.header },
136 { "orientation", m.orientation },
137 { "orientation_covariance", m.orientation_covariance },
138 { "angular_velocity", m.angular_velocity },
139 { "linear_acceleration", m.linear_acceleration },
140 { "linear_acceleration_covariance", m.linear_acceleration_covariance },
141 });
142}
143
144// ---------------------------------------------------------------------------------------------------------------------
145
146inline void to_json(nlohmann::json& j, const Temperature& m)
147{
148 j = nlohmann::json::object({
149 { "header", m.header },
150 { "temperature", m.temperature },
151 { "variance", m.variance },
152 });
153}
154
155// ---------------------------------------------------------------------------------------------------------------------
156
157inline void to_json(nlohmann::json& j, const Image& m)
158{
159 j = nlohmann::json::object({
160 { "header", m.header },
161 { "height", m.height },
162 { "width", m.width },
163 { "encoding", m.encoding },
164 { "is_bigendian", m.is_bigendian },
165 { "step", m.step },
166 { "data_b64", fpsdk::common::string::Base64Enc(m.data) },
167 });
168}
169
170} // namespace sensor_msgs
171/* ****************************************************************************************************************** */
172namespace tf2_msgs {
173
174inline void to_json(nlohmann::json& j, const TFMessage& m)
175{
176 j = nlohmann::json::object({
177 { "transforms", m.transforms },
178 });
179}
180
181} // namespace tf2_msgs
182/* ****************************************************************************************************************** */
183namespace nav_msgs {
184
185inline void to_json(nlohmann::json& j, const Odometry& m)
186{
187 j = nlohmann::json::object({
188 { "header", m.header },
189 { "child_frame_id", m.child_frame_id },
190 { "pose", m.pose },
191 { "twist", m.twist },
192 });
193}
194
195} // namespace nav_msgs
196/* ****************************************************************************************************************** */
197#endif // !_DOXYGEN_
198#endif // __FPSDK_COMMON_TO_JSON_ROS_HPP__
Fixposition SDK: ROS1 types and utils.
std::string Base64Enc(const std::vector< uint8_t > &buf)
Encode to base64.
Fixposition SDK: String utilities.
Fixposition SDK: Time utilities.