29#include <SimoxUtility/json/json.hpp>
43 return std::atan2(pose.linear()(1, 0), pose.linear()(0, 0));
53 toJson(
const core::GlobalTrajectory& parametrized,
const core::GlobalTrajectory& planned)
55 nlohmann::json points = nlohmann::json::array();
57 const std::size_t count = parametrized.points().size();
58 const bool limitsUsable = planned.points().size() == count;
60 for (std::size_t i = 0; i < count; i++)
62 const core::GlobalTrajectoryPoint& point = parametrized.points()[i];
63 const core::Position& position = point.waypoint.pose.translation();
65 points.push_back(nlohmann::json{
68 {
"yaw", yawOf(point.waypoint.pose)},
69 {
"velocity", point.velocity},
73 limitsUsable ? planned.points()[i].velocity : point.velocity}});
77 return nlohmann::json{
79 {
"length", parametrized.length()},
85 toJson(
const algorithms::Toppra& toppra)
89 const Eigen::MatrixXd& samples = toppra.lastSamples();
91 nlohmann::json waypoints = nlohmann::json::array();
92 for (Eigen::Index i = 0; i < samples.rows(); i++)
94 waypoints.push_back(nlohmann::json{
95 {
"t", samples(i, Column::T)},
96 {
"x", samples(i, Column::X)},
97 {
"y", samples(i, Column::Y)},
98 {
"yaw", samples(i, Column::YAW)},
99 {
"velocity", samples(i, Column::VELOCITY)},
100 {
"angular_velocity", samples(i, Column::ANGULAR_VELOCITY)},
101 {
"tangential_acceleration", samples(i, Column::TANGENTIAL_ACCELERATION)},
102 {
"angular_acceleration", samples(i, Column::ANGULAR_ACCELERATION)}});
105 return nlohmann::json{
106 {
"success",
true}, {
"duration", toppra.lastDuration()}, {
"waypoints", waypoints}};
117 dump[
"success"] =
true;
130 dump[
"reparametrization_reference"] = toJson(*record.
toppra);
138 dump[
"parametrization_limits"] = nlohmann::json{
144 {
"acceleration_polygon_sides", 32},
145 {
"acceleration_frame",
"body"},
152 const std::filesystem::path latest{path};
153 if (latest.has_parent_path())
155 std::filesystem::create_directories(latest.parent_path());
158 const auto write = [&
dump](
const std::filesystem::path& to)
160 std::ofstream stream{to};
161 if (not stream.good())
163 ARMARX_WARNING <<
"Cannot write the parametrization record to " << to;
166 stream <<
dump.dump(2) << std::endl;
173 std::filesystem::path stamped = latest;
174 stamped.replace_filename(latest.stem().string() +
"-" +
176 latest.extension().string());
179 ARMARX_INFO <<
"Wrote the parametrization record to " << latest;
181 catch (
const std::exception& e)
184 ARMARX_WARNING <<
"Could not write the parametrization record: " << e.what();
std::string toDateTimeString() const
SampleColumn
Column layout of lastSamples().
const Eigen::MatrixXd & lastSamples() const
The time-parametrized profile from the most recent apply(), (M, 8).
void dump(vec_point_2d &vec)
#define ARMARX_INFO
The normal logging level.
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
std::string ToString(const TrajectoryParametrization parametrization)
The lowercase name used in configs, logs and the analysis application's results.
This file is part of ArmarX.
void writeParametrizationDump(const ParametrizationRecord &record, const std::string &path)
Write record as JSON, for offline rendering with plot-navigation-request.
Everything the python side needs that does not change between paths.
float motorMaxTorque
Drive train.
float maxWheelVelocity
Motor/gearbox speed rating referred to the wheel [rad/s], always in rad/s regardless of the drive's o...
float maxAcceleration
Device command ramp. Infinite leaves the profile bounded by torque alone.
One navigation request's velocity profile, before and after parametrization.
core::TrajectoryParametrization applied
What actually ran.
core::TrajectoryParametrization requested
What the stack was configured to use.
std::optional< algorithms::Toppra::DriveParams > driveParams
The bounds the profile was solved against, when TOPP-RA was configured.
core::GlobalTrajectory parametrized
The profile that will be executed.
const algorithms::Toppra * toppra
Null unless TOPP-RA ran; supplies the time axis, which a GlobalTrajectory lacks.
core::GlobalTrajectory planned
The planner's output.