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;
Rotation2d::Rotation2d(units::radian_t value)
@@ -68,3 +70,11 @@ Rotation2d Rotation2d::RotateBy(const Rotation2d& other) const {
return {Cos() * other.Cos() - Sin() * other.Sin(),
Cos() * other.Sin() + Sin() * other.Cos()};
}
void frc::to_json(wpi::json& json, const Rotation2d& rotation) {
json = wpi::json{{"radians", rotation.Radians().to<double>()}};
}
void frc::from_json(const wpi::json& json, Rotation2d& rotation) {
rotation = Rotation2d{units::radian_t{json.at("radians").get<double>()}};
}