From c86e3b2a1a30148aa2ed12a579610708deff7f39 Mon Sep 17 00:00:00 2001 From: AimanHaidar Date: Fri, 24 Oct 2025 22:12:11 +0300 Subject: [PATCH] Format max_velocity and max_acceleration for YAML output as float --- .../src/srdf_config.cpp | 32 +++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/moveit_setup_assistant/moveit_setup_framework/src/srdf_config.cpp b/moveit_setup_assistant/moveit_setup_framework/src/srdf_config.cpp index 69002a3ec7..066dc9e59f 100644 --- a/moveit_setup_assistant/moveit_setup_framework/src/srdf_config.cpp +++ b/moveit_setup_assistant/moveit_setup_framework/src/srdf_config.cpp @@ -300,7 +300,21 @@ bool SRDFConfig::GeneratedJointLimits::writeYaml(YAML::Emitter& emitter) // Output property emitter << YAML::Key << "max_velocity"; - emitter << YAML::Value << static_cast(std::min(fabs(b.max_velocity_), fabs(b.min_velocity_))); + + // To Solve Putting integer Values like 100 as 100.0 in YAML + double val = std::min(fabs(b.max_velocity_), fabs(b.min_velocity_)); + + // Check if val is a full integer (within floating-point tolerance) + bool is_integer = std::fabs(val - std::round(val)) < 1e-9; + + // Format value as string + std::ostringstream oss; + if (is_integer) + oss << std::fixed << std::setprecision(1) << val; // e.g. 100.0 + else + oss << val; // e.g. 99.75 + + emitter << YAML::Value << oss.str(); // Output property emitter << YAML::Key << "has_acceleration_limits"; @@ -315,7 +329,21 @@ bool SRDFConfig::GeneratedJointLimits::writeYaml(YAML::Emitter& emitter) // Output property emitter << YAML::Key << "max_acceleration"; - emitter << YAML::Value << static_cast(std::min(fabs(b.max_acceleration_), fabs(b.min_acceleration_))); + + // To Solve Putting integer Values like 100 as 100.0 in YAML + val = std::min(fabs(b.max_acceleration_), fabs(b.min_acceleration_)); + + // Check if val is a full integer (within floating-point tolerance) + is_integer = std::fabs(val - std::round(val)) < 1e-9; + + // Format value as string + oss.str(""); // Clear the stringstream + if (is_integer) + oss << std::fixed << std::setprecision(1) << val; // e.g. 100.0 + else + oss << val; // e.g. 99.75 + + emitter << YAML::Value << oss.str(); emitter << YAML::EndMap; }