Skip to content

Commit b787f38

Browse files
committed
test: ensures pendulum env fixture runs mj_forward
1 parent a34e23c commit b787f38

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Loading and reset times are reported in the server debug log. All plugin stats c
1515
* *mujoco_ros_sensors*: now skipping user sensors, as they should be handled in separate, dedicated plugins.
1616
* When loading takes more than 0.25 seconds the simulation is no longer automatically paused.
1717
* Fixed fetching of body quaternion in `get_body_state` service.
18+
* *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.
1819

1920
### Changed
2021
* Moved `mujoco_ros::Viewer::Clock` definition to `mujoco_ros::Clock` (into common_types.h).

mujoco_ros/test/mujoco_env_fixture.h

+7
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class MujocoEnvTestWrapper : public MujocoEnv
4949
MujocoEnvTestWrapper(const std::string &admin_hash = std::string()) : MujocoEnv(admin_hash) {}
5050
mjModel *getModelPtr() { return model_.get(); }
5151
mjData *getDataPtr() { return data_.get(); }
52+
MujocoEnvMutex *getMutexPtr() { return &physics_thread_mutex_; }
5253
int getPendingSteps() { return num_steps_until_exit_; }
5354

5455
std::string getFilename() { return { filename_ }; }
@@ -124,6 +125,12 @@ class PendulumEnvFixture : public ::testing::Test
124125
seconds += 0.001;
125126
}
126127
EXPECT_EQ(env_ptr->getFilename(), xml_path) << "Model was not loaded correctly!";
128+
129+
// Make sure forward has been run at least once
130+
{
131+
std::lock_guard<MujocoEnvMutex> lock(*env_ptr->getMutexPtr());
132+
mj_forward(env_ptr->getModelPtr(), env_ptr->getDataPtr());
133+
}
127134
}
128135

129136
void TearDown() override

0 commit comments

Comments
 (0)