ros2_control - galactic
Loading...
Searching...
No Matches
mock_pendulum_hardware.hpp
1// Copyright 2026 kamal2730
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#ifndef MOCK_PENDULUM_HARDWARE__MOCK_PENDULUM_HARDWARE_HPP_
16#define MOCK_PENDULUM_HARDWARE__MOCK_PENDULUM_HARDWARE_HPP_
17
18#include <string>
19#include <vector>
20
21#include "hardware_interface/handle.hpp"
22#include "hardware_interface/hardware_info.hpp"
23#include "hardware_interface/system_interface.hpp"
24#include "hardware_interface/types/hardware_interface_return_values.hpp"
25#include "rclcpp/macros.hpp"
26#include "rclcpp_lifecycle/node_interfaces/lifecycle_node_interface.hpp"
27#include "rclcpp_lifecycle/state.hpp"
28
29namespace mock_pendulum_hardware
30{
31using CallbackReturn = rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn;
32
47{
48public:
49 RCLCPP_SHARED_PTR_DEFINITIONS(MockPendulumHardware)
50
51 CallbackReturn on_init(
52 const hardware_interface::HardwareComponentInterfaceParams & params) override;
53
54 std::vector<hardware_interface::StateInterface> export_state_interfaces() override;
55
56 std::vector<hardware_interface::CommandInterface> export_command_interfaces() override;
57
58 CallbackReturn on_activate(const rclcpp_lifecycle::State & previous_state) override;
59
60 CallbackReturn on_deactivate(const rclcpp_lifecycle::State & previous_state) override;
61
62 hardware_interface::return_type read(
63 const rclcpp::Time & time, const rclcpp::Duration & period) override;
64
65 hardware_interface::return_type write(
66 const rclcpp::Time & time, const rclcpp::Duration & period) override;
67
68private:
69 // State: [motor/pos, motor/vel, pendulum/pos, pendulum/vel]
70 std::vector<double> hw_states_;
71 // Command: [motor/acceleration]
72 std::vector<double> hw_commands_;
73
74 // Dynamics state
75 double q1_; // motor joint angle (rad)
76 double q1_dot_; // motor joint velocity (rad/s)
77 double q2_; // pendulum angle from upright (rad)
78 double q2_dot_; // pendulum velocity (rad/s)
79
80 // Physical parameters
81 double J1_; // motor joint inertia (kg*m^2)
82 double J2_; // pendulum inertia (kg*m^2)
83 double m2_; // pendulum mass (kg)
84 double l2_; // pendulum CoM distance (m)
85 double b1_; // motor joint damping (N*m*s/rad)
86 double b2_; // pendulum damping (N*m*s/rad)
87 double g_; // gravity (m/s^2)
88
89 double initial_q2_; // initial pendulum perturbation (rad)
90};
91
92} // namespace mock_pendulum_hardware
93
94#endif // MOCK_PENDULUM_HARDWARE__MOCK_PENDULUM_HARDWARE_HPP_
Virtual Class to implement when integrating a complex system into ros2_control.
Definition system_interface.hpp:68
virtual return_type read()=0
Read the current state values from the actuator.
virtual return_type write()=0
Write the current command values to the actuator.
Definition mock_pendulum_hardware.hpp:47
std::vector< hardware_interface::CommandInterface > export_command_interfaces() override
Exports all command interfaces for this hardware interface.
Definition mock_pendulum_hardware.cpp:70
std::vector< hardware_interface::StateInterface > export_state_interfaces() override
Exports all state interfaces for this hardware interface.
Definition mock_pendulum_hardware.cpp:60