-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathros_message_factory.h
More file actions
88 lines (72 loc) · 2.64 KB
/
ros_message_factory.h
File metadata and controls
88 lines (72 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#pragma once
#include "rapidjson/document.h"
using json = rapidjson::Document;
/*
* This class creates json variables
* that contain the structure of
* popular ROS Messages.
*/
namespace rosbridge2cpp {
class ROSMessageFactory {
public:
ROSMessageFactory() = default;
~ROSMessageFactory() = default;
static json std_msgs_header(json::AllocatorType& allocator)
{
json header(rapidjson::kObjectType);
header.AddMember("seq", (uint32_t)0, allocator);
rapidjson::Value stamp(rapidjson::kObjectType);
stamp.AddMember("secs", (uint64_t)0, allocator);
stamp.AddMember("nsecs", (uint64_t)0, allocator);
header.AddMember("stamp", stamp, allocator);
header.AddMember("frame_id", std::string(""), allocator);
return header;
}
static json geometry_msgs_vector3(json::AllocatorType& allocator)
{
json msg(rapidjson::kObjectType);
msg.AddMember("x", (double)0, allocator);
msg.AddMember("y", (double)0, allocator);
msg.AddMember("z", (double)0, allocator);
return msg;
}
static json geometry_msgs_quaternion(json::AllocatorType& allocator)
{
json msg(rapidjson::kObjectType);
msg.AddMember("x", (double)0, allocator);
msg.AddMember("y", (double)0, allocator);
msg.AddMember("z", (double)0, allocator);
msg.AddMember("w", (double)1, allocator);
return msg;
}
static json geometry_msgs_transform(json::AllocatorType& allocator)
{
json msg(rapidjson::kObjectType);
msg.AddMember("translation", geometry_msgs_vector3(allocator), allocator);
msg.AddMember("rotation", geometry_msgs_quaternion(allocator), allocator);
return msg;
}
static json geometry_msgs_transformstamped(json::AllocatorType& allocator)
{
json msg(rapidjson::kObjectType);
msg.AddMember("header", std_msgs_header(allocator), allocator);
msg.AddMember("child_frame_id", std::string(""), allocator);
msg.AddMember("transform", geometry_msgs_transform(allocator), allocator);
return msg;
}
static json sensor_msgs_image(json::AllocatorType& allocator)
{
json msg(rapidjson::kObjectType);
msg.AddMember("header", std_msgs_header(allocator), allocator);
msg.AddMember("height", (uint32_t)0, allocator);
msg.AddMember("width", (uint32_t)0, allocator);
msg.AddMember("encoding", std::string(""), allocator);
msg.AddMember("is_bigendian", (uint32_t)0, allocator);
msg.AddMember("step", (uint32_t)0, allocator);
msg.AddMember("data", std::string(""), allocator); // uint8[] will be represented as a base64 string in rosbridge
//msg.AddMember("child_frame_id", std::string(""), allocator);
//msg.AddMember("transform", geometry_msgs_transform(allocator), allocator);
return msg;
}
};
}