-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathFieldInterface.cpp
More file actions
53 lines (41 loc) · 1.43 KB
/
FieldInterface.cpp
File metadata and controls
53 lines (41 loc) · 1.43 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
#include "io/FieldInterface.h"
#include <iostream>
#include "networktables/NetworkTableInstance.h"
void FieldInterface::initialize(const nt::NetworkTableInstance& nt_inst) {
subscribers.clear();
tagMap.clear();
const auto fieldTable = nt_inst.GetTable("field");
// Create subscribers for all tags
for (int i = 0; i < 22; i++) {
int tag_id = i + 1;
auto sub = fieldTable->GetDoubleArrayTopic("tag_" + std::to_string(tag_id))
.Subscribe({});
subscribers.emplace(tag_id, std::move(sub));
}
numTags = 22; // we know how many tags to expect
}
bool FieldInterface::update() {
tagMap.clear();
for (const auto& [tag_id, sub] : subscribers) {
if (std::vector<double> pose_data = sub.Get(); pose_data.size() == 7) {
const frc::Translation3d t{
units::meter_t{pose_data[0]},
units::meter_t{pose_data[1]},
units::meter_t{pose_data[2]}};
const frc::Rotation3d r{
frc::Quaternion{pose_data[3], pose_data[4],
pose_data[5], pose_data[6]}};
tagMap.emplace(tag_id, frc::Pose3d{t, r});
} else {
// std::cerr << "FieldInterface: Received pose data of unexpected size ("
// << pose_data.size() << ") for tag " << tag_id << std::endl;
}
}
return tagMap.size() == numTags;
}
std::map<int, frc::Pose3d> FieldInterface::getMap() {
return tagMap;
}
bool FieldInterface::isInitialized() {
return !subscribers.empty();
}