Skip to content

Commit

Permalink
test: ensures pendulum env fixture runs mj_forward
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidPL1 committed Nov 7, 2024
1 parent a34e23c commit b787f38
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Loading and reset times are reported in the server debug log. All plugin stats c
* *mujoco_ros_sensors*: now skipping user sensors, as they should be handled in separate, dedicated plugins.
* When loading takes more than 0.25 seconds the simulation is no longer automatically paused.
* Fixed fetching of body quaternion in `get_body_state` service.
* *tests*: PendulumEnvFixture now makes sure `mj_forward` has been run at least once. This ensures the data object is populated with correct initial positions and velocities.

### Changed
* Moved `mujoco_ros::Viewer::Clock` definition to `mujoco_ros::Clock` (into common_types.h).
Expand Down
7 changes: 7 additions & 0 deletions mujoco_ros/test/mujoco_env_fixture.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class MujocoEnvTestWrapper : public MujocoEnv
MujocoEnvTestWrapper(const std::string &admin_hash = std::string()) : MujocoEnv(admin_hash) {}
mjModel *getModelPtr() { return model_.get(); }
mjData *getDataPtr() { return data_.get(); }
MujocoEnvMutex *getMutexPtr() { return &physics_thread_mutex_; }
int getPendingSteps() { return num_steps_until_exit_; }

std::string getFilename() { return { filename_ }; }
Expand Down Expand Up @@ -124,6 +125,12 @@ class PendulumEnvFixture : public ::testing::Test
seconds += 0.001;
}
EXPECT_EQ(env_ptr->getFilename(), xml_path) << "Model was not loaded correctly!";

// Make sure forward has been run at least once
{
std::lock_guard<MujocoEnvMutex> lock(*env_ptr->getMutexPtr());
mj_forward(env_ptr->getModelPtr(), env_ptr->getDataPtr());
}
}

void TearDown() override
Expand Down

0 comments on commit b787f38

Please sign in to comment.