mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-25 01:41:43 +00:00
SCRIPT: wpiformat
This commit is contained in:
committed by
Peter Johnson
parent
ae6bdc9d25
commit
2109161534
@@ -10,18 +10,19 @@ using namespace wpi::math;
|
||||
|
||||
void wpi::math::to_json(wpi::util::json& json, const Trajectory::State& state) {
|
||||
json = wpi::util::json{{"time", state.t.value()},
|
||||
{"velocity", state.velocity.value()},
|
||||
{"acceleration", state.acceleration.value()},
|
||||
{"pose", state.pose},
|
||||
{"curvature", state.curvature.value()}};
|
||||
{"velocity", state.velocity.value()},
|
||||
{"acceleration", state.acceleration.value()},
|
||||
{"pose", state.pose},
|
||||
{"curvature", state.curvature.value()}};
|
||||
}
|
||||
|
||||
void wpi::math::from_json(const wpi::util::json& json, Trajectory::State& state) {
|
||||
void wpi::math::from_json(const wpi::util::json& json,
|
||||
Trajectory::State& state) {
|
||||
state.pose = json.at("pose").get<Pose2d>();
|
||||
state.t = wpi::units::second_t{json.at("time").get<double>()};
|
||||
state.velocity =
|
||||
wpi::units::meters_per_second_t{json.at("velocity").get<double>()};
|
||||
state.acceleration =
|
||||
wpi::units::meters_per_second_squared_t{json.at("acceleration").get<double>()};
|
||||
state.acceleration = wpi::units::meters_per_second_squared_t{
|
||||
json.at("acceleration").get<double>()};
|
||||
state.curvature = wpi::units::curvature_t{json.at("curvature").get<double>()};
|
||||
}
|
||||
|
||||
@@ -67,9 +67,9 @@ Trajectory TrajectoryParameterizer::TimeParameterizeTrajectory(
|
||||
// acceleration limit. v_f = √(v_i² + 2ad).
|
||||
|
||||
constrainedState.maxVelocity = wpi::units::math::min(
|
||||
maxVelocity,
|
||||
wpi::units::math::sqrt(predecessor.maxVelocity * predecessor.maxVelocity +
|
||||
predecessor.maxAcceleration * ds * 2.0));
|
||||
maxVelocity, wpi::units::math::sqrt(
|
||||
predecessor.maxVelocity * predecessor.maxVelocity +
|
||||
predecessor.maxAcceleration * ds * 2.0));
|
||||
|
||||
constrainedState.minAcceleration = -maxAcceleration;
|
||||
constrainedState.maxAcceleration = maxAcceleration;
|
||||
@@ -131,7 +131,7 @@ Trajectory TrajectoryParameterizer::TimeParameterizeTrajectory(
|
||||
// v_f = √(v_i² + 2ad), where v_i = successor.
|
||||
wpi::units::meters_per_second_t newMaxVelocity =
|
||||
wpi::units::math::sqrt(successor.maxVelocity * successor.maxVelocity +
|
||||
successor.minAcceleration * ds * 2.0);
|
||||
successor.minAcceleration * ds * 2.0);
|
||||
|
||||
// No more limits to impose! This state can be finalized.
|
||||
if (newMaxVelocity >= constrainedState.maxVelocity) {
|
||||
|
||||
@@ -9,9 +9,10 @@
|
||||
#include "wpi/util/protobuf/ProtobufCallbacks.hpp"
|
||||
#include "wpimath/protobuf/trajectory.npb.h"
|
||||
|
||||
std::optional<wpi::math::Trajectory> wpi::util::Protobuf<wpi::math::Trajectory>::Unpack(
|
||||
InputStream& stream) {
|
||||
wpi::util::StdVectorUnpackCallback<wpi::math::Trajectory::State, SIZE_MAX> states;
|
||||
std::optional<wpi::math::Trajectory>
|
||||
wpi::util::Protobuf<wpi::math::Trajectory>::Unpack(InputStream& stream) {
|
||||
wpi::util::StdVectorUnpackCallback<wpi::math::Trajectory::State, SIZE_MAX>
|
||||
states;
|
||||
wpi_proto_ProtobufTrajectory msg{
|
||||
.states = states.Callback(),
|
||||
};
|
||||
@@ -22,8 +23,8 @@ std::optional<wpi::math::Trajectory> wpi::util::Protobuf<wpi::math::Trajectory>:
|
||||
return wpi::math::Trajectory{states.Vec()};
|
||||
}
|
||||
|
||||
bool wpi::util::Protobuf<wpi::math::Trajectory>::Pack(OutputStream& stream,
|
||||
const wpi::math::Trajectory& value) {
|
||||
bool wpi::util::Protobuf<wpi::math::Trajectory>::Pack(
|
||||
OutputStream& stream, const wpi::math::Trajectory& value) {
|
||||
wpi::util::PackCallback<wpi::math::Trajectory::State> states{value.States()};
|
||||
wpi_proto_ProtobufTrajectory msg{
|
||||
.states = states.Callback(),
|
||||
|
||||
Reference in New Issue
Block a user