ros2_control - rolling
Loading...
Searching...
No Matches
duck_mini_mujoco_system_interface.hpp
1// Copyright (C) 2026 ros2_control Development Team
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//
15// Authors: Julia Jia
16
17#ifndef ROS2_CONTROL_DEMO_EXAMPLE_18__DUCK_MINI_MUJOCO_SYSTEM_INTERFACE_HPP_
18#define ROS2_CONTROL_DEMO_EXAMPLE_18__DUCK_MINI_MUJOCO_SYSTEM_INTERFACE_HPP_
19
20#include <mujoco/mujoco.h>
21
22#include <algorithm>
23#include <cctype>
24#include <string>
25#include <vector>
26
27#include <hardware_interface/hardware_info.hpp>
28#include <hardware_interface/types/hardware_interface_return_values.hpp>
29#include <mujoco_ros2_control/mujoco_system_interface.hpp>
30
31namespace ros2_control_demo_example_18
32{
33
35{
36 std::string name;
37 double contact_raw_value{0.0}; // unfiltered 0/1 from mjData->contact[]
38
39 // Jazzy+ StateInterface handles own their value instead of aliasing a double*, so this handle is
40 // built once in on_export_state_interfaces() and synced from contact_raw_value every read().
41 hardware_interface::StateInterface::SharedPtr contact_raw_interface;
42
43 std::string body1_name;
44 std::string body2_name;
45 int body1_id{-1};
46 int body2_id{-1};
47};
48
50{
51public:
54
55 hardware_interface::CallbackReturn
56
58
59 std::vector<hardware_interface::StateInterface::ConstSharedPtr> on_export_state_interfaces()
60 override;
61
62 hardware_interface::return_type read(
63 const rclcpp::Time & time, const rclcpp::Duration & period) override;
64
65private:
66 void register_contact_detection();
67 void update_contact_detection();
68 std::vector<ContactDetectionData> contact_detection_data_;
69 // Cached copy of the (immutable) MuJoCo model and a reused scratch buffer for contact queries
70 mjModel * contact_model_{nullptr};
71 mjData * contact_data_{nullptr};
72};
73
74} // namespace ros2_control_demo_example_18
75
76#endif // ROS2_CONTROL_DEMO_EXAMPLE_18__DUCK_MINI_MUJOCO_SYSTEM_INTERFACE_HPP_
Definition mujoco_system_interface.hpp:82
Definition duck_mini_mujoco_system_interface.hpp:50
std::vector< hardware_interface::StateInterface::ConstSharedPtr > on_export_state_interfaces() override
Definition duck_mini_mujoco_system_interface.cpp:113
hardware_interface::CallbackReturn on_init(const hardware_interface::HardwareComponentInterfaceParams &params) override
Initialization of the hardware interface from data parsed from the robot's URDF.
Definition duck_mini_mujoco_system_interface.cpp:36
hardware_interface::return_type read(const rclcpp::Time &time, const rclcpp::Duration &period) override
Read the current state values from the hardware.
Definition duck_mini_mujoco_system_interface.cpp:127
Parameters required for the initialization of a specific hardware component plugin....
Definition hardware_component_interface_params.hpp:32
Definition duck_mini_mujoco_system_interface.hpp:35