From 7c57e08d35792490293fb1e3d4a4ac23299878bc Mon Sep 17 00:00:00 2001 From: Ruddick Lawrence <679360+mrjogo@users.noreply.github.com> Date: Fri, 23 Feb 2024 14:41:23 -0800 Subject: [PATCH] Reset Gazebo with initial joint positions and velocities --- gz_ros2_control/src/gz_system.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/gz_ros2_control/src/gz_system.cpp b/gz_ros2_control/src/gz_system.cpp index d5aa0b8a..a60a4eb3 100644 --- a/gz_ros2_control/src/gz_system.cpp +++ b/gz_ros2_control/src/gz_system.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -48,8 +49,10 @@ #include #include #include +#include #include #include +#include #include #include #include @@ -427,9 +430,15 @@ bool GazeboSimSystem::initSim( // independently of existence of command interface set initial value if defined if (!std::isnan(initial_position)) { this->dataPtr->joints_[j].joint_position = initial_position; + this->dataPtr->ecm->CreateComponent( + this->dataPtr->joints_[j].sim_joint, + sim::components::JointPositionReset({initial_position})); } if (!std::isnan(initial_velocity)) { this->dataPtr->joints_[j].joint_velocity = initial_velocity; + this->dataPtr->ecm->CreateComponent( + this->dataPtr->joints_[j].sim_joint, + sim::components::JointVelocityReset({initial_velocity})); } }