File tree Expand file tree Collapse file tree 2 files changed +46
-0
lines changed
include/mujoco_ros2_simulation Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Original file line number Diff line number Diff line change @@ -73,6 +73,30 @@ class MujocoSystemInterface : public hardware_interface::SystemInterface
7373 hardware_interface::return_type read (const rclcpp::Time& time, const rclcpp::Duration& period) override ;
7474 hardware_interface::return_type write (const rclcpp::Time& time, const rclcpp::Duration& period) override ;
7575
76+ /* *
77+ * @brief Returns a copy of the MuJoCo model.
78+ *
79+ * This method locks the simulation mutex to ensure thread safety.
80+ * @param dest Pointer to an mjModel structure where the copy will be stored. The pointer will be allocated if it is nullptr.
81+ */
82+ void get_model (mjModel*& dest);
83+
84+ /* *
85+ * @brief Returns a copy of the current MuJoCo data.
86+ *
87+ * This method locks the simulation mutex to ensure thread safety.
88+ * @param dest Pointer to an mjData structure where the copy will be stored. The pointer will be allocated if it is nullptr.
89+ */
90+ void get_data (mjData*& dest);
91+
92+ /* *
93+ * @brief Sets the MuJoCo data to the provided value.
94+ *
95+ * This method locks the simulation mutex to ensure thread safety.
96+ * @param mj_data Pointer to an mjData structure containing the new data.
97+ */
98+ void set_data (mjData* mj_data);
99+
76100private:
77101 /* *
78102 * @brief Loads actuator information into the HW interface.
Original file line number Diff line number Diff line change @@ -1212,6 +1212,28 @@ void MujocoSystemInterface::publish_clock()
12121212 clock_publisher_->publish (sim_time_msg);
12131213}
12141214
1215+ void MujocoSystemInterface::get_model (mjModel*& dest)
1216+ {
1217+ const std::unique_lock<std::recursive_mutex> lock (*sim_mutex_);
1218+ mj_copyModel (dest, mj_model_);
1219+ }
1220+
1221+ void MujocoSystemInterface::get_data (mjData*& dest)
1222+ {
1223+ const std::unique_lock<std::recursive_mutex> lock (*sim_mutex_);
1224+ if (dest == nullptr )
1225+ {
1226+ dest = mj_makeData (mj_model_);
1227+ }
1228+ mj_copyData (dest, mj_model_, mj_data_);
1229+ }
1230+
1231+ void MujocoSystemInterface::set_data (mjData* mj_data)
1232+ {
1233+ const std::unique_lock<std::recursive_mutex> lock (*sim_mutex_);
1234+ mj_copyData (mj_data_, mj_model_, mj_data);
1235+ }
1236+
12151237} // namespace mujoco_ros2_simulation
12161238
12171239#include " pluginlib/class_list_macros.hpp"
You can’t perform that action at this time.
0 commit comments