Add JSON support for Trajectories (#2025)

This commit is contained in:
carbotaniuman
2019-11-02 13:35:03 -05:00
committed by Peter Johnson
parent 2b6811eddb
commit ed30d5d40e
23 changed files with 581 additions and 12 deletions

View File

@@ -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>()};
}