Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ repos:

# Python hooks
- repo: https://github.com/asottile/pyupgrade
rev: v3.17.0
rev: v3.22.0
hooks:
- id: pyupgrade
args: [--py36-plus]
Expand Down
7 changes: 4 additions & 3 deletions mujoco_ros2_control/src/mujoco_system_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2462,8 +2462,10 @@ void MujocoSystemInterface::reset_simulation_state(bool /*fill_initial_state*/)
// Reset command interfaces to initial position commands
for (auto& actuator : mujoco_actuator_data_)
{
restore_authored_position_gains(simulation_.get(), &actuator);
actuator.is_impedance_control_enabled = false;
// Impedance mode follows the claimed kp/kd interfaces, not the world state:
// keep it so the active controller still drives the joint after a reset.
// Force write() to reprogram native-position gains on its next cycle.
actuator.last_requested_parameters.reset();
actuator.position_interface.state_ = simulation_->data()->qpos[actuator.mj_pos_adr];
actuator.velocity_interface.state_ = simulation_->data()->qvel[actuator.mj_vel_adr];
actuator.effort_interface.state_ = 0.0;
Expand Down Expand Up @@ -2507,7 +2509,6 @@ void MujocoSystemInterface::reset_simulation_state(bool /*fill_initial_state*/)
// Set joint commands to current state (maintaining position control)
for (auto& joint : urdf_joint_data_)
{
joint.is_impedance_control_enabled = false;
joint.position_interface.command_ = joint.position_interface.state_;
joint.velocity_interface.command_ = 0.0;
joint.effort_interface.command_ = 0.0;
Expand Down
18 changes: 7 additions & 11 deletions mujoco_ros2_control/tests/test_headless_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ TEST_F(HeadlessInitTest, PositionImpedanceHonorsAuthoredRangesAndRestoresAuthore
EXPECT_DOUBLE_EQ(model->actuator_biasprm[actuator_id * mjNBIAS + 2], -0.7);
mj_deleteModel(model);

// Re-enter impedance mode so reset exercises restoration independently.
// Re-enter impedance mode before the world reset.
ASSERT_EQ(interface_->perform_command_mode_switch(
{ "hinge/position", "hinge/velocity", "hinge/effort", "hinge/kp", "hinge/kd" }, {}),
hardware_interface::return_type::OK);
Expand All @@ -512,27 +512,23 @@ TEST_F(HeadlessInitTest, PositionImpedanceHonorsAuthoredRangesAndRestoresAuthore
rclcpp::FutureReturnCode::SUCCESS);
ASSERT_TRUE(reset_future.get()->success);

// The controller still claims kp/kd, so the reset keeps impedance mode and
// the next write programs the commanded gains without a new mode switch.
ASSERT_EQ(interface_->write(rclcpp::Time(0), rclcpp::Duration::from_seconds(0.01)),
hardware_interface::return_type::OK);
model = nullptr;
interface_->get_model(model);
ASSERT_NE(model, nullptr);
EXPECT_DOUBLE_EQ(model->actuator_gainprm[actuator_id * mjNGAIN], 3.0);
EXPECT_DOUBLE_EQ(model->actuator_biasprm[actuator_id * mjNBIAS + 1], -3.0);
EXPECT_DOUBLE_EQ(model->actuator_biasprm[actuator_id * mjNBIAS + 2], -0.7);
EXPECT_DOUBLE_EQ(model->actuator_gainprm[actuator_id * mjNGAIN], 20.0);
EXPECT_DOUBLE_EQ(model->actuator_biasprm[actuator_id * mjNBIAS + 2], -4.0);
mj_deleteModel(model);

data = nullptr;
interface_->get_data(data);
ASSERT_NE(data, nullptr);
EXPECT_DOUBLE_EQ(data->qpos[0], 0.5);
EXPECT_DOUBLE_EQ(data->qfrc_actuator[0], -1.5);
mj_deleteData(data);

ASSERT_EQ(interface_->perform_command_mode_switch(
{ "hinge/position", "hinge/velocity", "hinge/effort", "hinge/kp", "hinge/kd" }, {}),
hardware_interface::return_type::OK);
ASSERT_EQ(interface_->write(rclcpp::Time(0), rclcpp::Duration::from_seconds(0.01)),
hardware_interface::return_type::OK);

rclcpp_lifecycle::State inactive_state(0, "inactive");
ASSERT_EQ(interface_->on_deactivate(inactive_state), hardware_interface::CallbackReturn::SUCCESS);

Expand Down
Loading