mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
Add JSON support for Trajectories (#2025)
This commit is contained in:
committed by
Peter Johnson
parent
2b6811eddb
commit
ed30d5d40e
@@ -9,6 +9,8 @@
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include <wpi/json.h>
|
||||
|
||||
using namespace frc;
|
||||
|
||||
Pose2d::Pose2d(Translation2d translation, Rotation2d rotation)
|
||||
@@ -96,3 +98,13 @@ Twist2d Pose2d::Log(const Pose2d& end) const {
|
||||
|
||||
return {translationPart.X(), translationPart.Y(), units::radian_t(dtheta)};
|
||||
}
|
||||
|
||||
void frc::to_json(wpi::json& json, const Pose2d& pose) {
|
||||
json = wpi::json{{"translation", pose.Translation()},
|
||||
{"rotation", pose.Rotation()}};
|
||||
}
|
||||
|
||||
void frc::from_json(const wpi::json& json, Pose2d& pose) {
|
||||
pose = Pose2d{json.at("translation").get<Translation2d>(),
|
||||
json.at("rotation").get<Rotation2d>()};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user