2024-12-28 23:24:32 -05:00
|
|
|
// Copyright (c) FIRST and other WPILib contributors.
|
|
|
|
|
// Open Source Software; you can modify and/or share it under the terms of
|
|
|
|
|
// the WPILib BSD license file in the root directory of this project.
|
|
|
|
|
|
2025-11-07 19:56:21 -05:00
|
|
|
#include "fmap.hpp"
|
2024-12-28 23:24:32 -05:00
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
wpi::util::json fmap::singleTag(int tag, const tag::Pose& tagpose) {
|
2024-12-28 23:24:32 -05:00
|
|
|
std::vector<double> transform = {};
|
|
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
|
for (int j = 0; j < 4; j++) {
|
|
|
|
|
transform.push_back(tagpose.transformMatrixFmap(i, j));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return {{"family", "apriltag3_36h11_classic"},
|
|
|
|
|
{"id", tag},
|
|
|
|
|
{"size", 165.1},
|
|
|
|
|
{"transform", transform},
|
|
|
|
|
{"unique", true}};
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
wpi::util::json fmap::convertfmap(const wpi::util::json& json) {
|
2024-12-28 23:24:32 -05:00
|
|
|
std::string fmapstart = "{\"fiducials\":[";
|
|
|
|
|
|
|
|
|
|
std::string fmapend = "],\"type\":\"frc\"}";
|
|
|
|
|
|
|
|
|
|
Fieldmap fieldmap(json);
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < fieldmap.getNumTags(); i++) {
|
|
|
|
|
fmapstart += singleTag(i + 1, fieldmap.getTag(i + 1)).dump();
|
|
|
|
|
if (i != fieldmap.getNumTags() - 1) {
|
|
|
|
|
fmapstart += ",";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
return wpi::util::json::parse(fmapstart.append(fmapend));
|
2024-12-28 23:24:32 -05:00
|
|
|
}
|