mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[wpilib] Add AprilTag and AprilTagFieldLayout (#4421)
This is an API for looking up a Pose3d from a tag id, and includes functionality to load that map from a JSON file. This also adds JSON support to Pose3d, Rotation3d. Translation3d, and Quaternion. Co-authored-by: Tyler Veness <calcmogul@gmail.com> Co-authored-by: AMereBagatelle <themerebagatelle@gmail.com>
This commit is contained in:
@@ -4,6 +4,11 @@
|
||||
|
||||
#include "frc/geometry/Translation3d.h"
|
||||
|
||||
#include <wpi/json.h>
|
||||
|
||||
#include "units/length.h"
|
||||
#include "units/math.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
Translation3d::Translation3d(units::meter_t distance, const Rotation3d& angle) {
|
||||
@@ -39,3 +44,15 @@ bool Translation3d::operator==(const Translation3d& other) const {
|
||||
bool Translation3d::operator!=(const Translation3d& other) const {
|
||||
return !operator==(other);
|
||||
}
|
||||
|
||||
void frc::to_json(wpi::json& json, const Translation3d& translation) {
|
||||
json = wpi::json{{"x", translation.X().value()},
|
||||
{"y", translation.Y().value()},
|
||||
{"z", translation.Z().value()}};
|
||||
}
|
||||
|
||||
void frc::from_json(const wpi::json& json, Translation3d& translation) {
|
||||
translation = Translation3d{units::meter_t{json.at("x").get<double>()},
|
||||
units::meter_t{json.at("y").get<double>()},
|
||||
units::meter_t{json.at("z").get<double>()}};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user