-
Notifications
You must be signed in to change notification settings - Fork 0
/
VisionData.hpp
77 lines (62 loc) · 1.54 KB
/
VisionData.hpp
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
#pragma once
#include "json.hpp"
#include "VisionStatus.hpp"
namespace Lightning
{
class VisionData
{
public:
// TODO define id better
VisionStatus status;
int targetId;
double x;
double y;
double z;
double roll;
double pitch;
double yaw;
double imageX;
double imageY;
double theta;
double dist;
};
inline void to_json(nlohmann::json& j, const VisionData& d) {
j = nlohmann::json{{"status", (int)d.status},
{"x_mm", d.x},
{"y_mm", d.y},
{"z_mm", d.z},
{"roll_deg", d.roll},
{"pitch_deg", d.pitch},
{"yaw_deg", d.yaw},
{"imageX_px", d.imageX},
{"imageY_px", d.imageY},
{"theta_deg", d.theta},
{"dist_mm", d.dist}};
}
inline void from_json(const nlohmann::json& j, VisionData& d) {
j.at("status").get_to(d.status);
j.at("x_mm").get_to(d.x);
j.at("y_mm").get_to(d.y);
j.at("z_mm").get_to(d.z);
j.at("roll_deg").get_to(d.roll);
j.at("pitch_deg").get_to(d.pitch);
j.at("yaw_deg").get_to(d.yaw);
j.at("imageX_px").get_to(d.imageX);
j.at("imageY_px").get_to(d.imageY);
j.at("theta_deg").get_to(d.theta);
j.at("dist_mm").get_to(d.dist);
}
class VisionMessage
{
public:
int cameraId;
std::vector<VisionData> packets;
};
inline void to_json(nlohmann::json& j, const VisionMessage& d) {
j = nlohmann::json{{"cameraId", (int)d.cameraId}, {"packets", d.packets}};
}
inline void from_json(const nlohmann::json& j, VisionMessage& d) {
j.at("cameraId").get_to(d.cameraId);
j.at("packets").get_to(d.packets);
}
}