Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
0367bdb
Change mock hardware to also save the joint names
christophfroehlich Sep 19, 2025
871e34a
Initial rewrite of the system
christophfroehlich Sep 19, 2025
8e2e56e
Switch some EXPECT/ASSERT macros
christophfroehlich Sep 19, 2025
a953669
Parse initial values in on_activate
christophfroehlich Sep 19, 2025
1594059
Some more asserts
christophfroehlich Sep 19, 2025
19c87e4
Fix mimicked interfaces and standard interfaces if isnan/isinf
christophfroehlich Sep 19, 2025
900b7f4
Fix logic for custom_interface_with_following_offset_
christophfroehlich Sep 19, 2025
a2b5228
Fix gpio mock
christophfroehlich Sep 19, 2025
dab6571
Fix calculate dynamics
christophfroehlich Sep 19, 2025
afe38ba
Support boolean
christophfroehlich Sep 19, 2025
b4d774f
Support boolean for joints
christophfroehlich Sep 19, 2025
15fa168
Remove debug output
christophfroehlich Sep 19, 2025
4f3968f
Remove debug output
christophfroehlich Sep 19, 2025
e5848fa
Fix missing braces
christophfroehlich Sep 21, 2025
184fe7d
Use the mimic joint index instead
christophfroehlich Sep 23, 2025
56ee431
Revert "Change mock hardware to also save the joint names"
christophfroehlich Sep 23, 2025
6d2ed1a
Add test for boolean data_type
christophfroehlich Sep 23, 2025
49be0d4
Preallocate skip_interfaces
christophfroehlich Sep 23, 2025
9a7c980
Use some references instead of copies
christophfroehlich Sep 23, 2025
2144988
Move comments
christophfroehlich Sep 23, 2025
e9f4b6b
Use unordered maps to improve efficiency
christophfroehlich Sep 23, 2025
0a30daa
No need for setting initial_values (done by handle itself)
christophfroehlich Oct 13, 2025
75acdcb
Revert "No need for setting initial_values (done by handle itself)"
christophfroehlich Oct 13, 2025
04ba6fd
Only set initial values if position_state_following_offset_ is set
christophfroehlich Oct 13, 2025
3475fc3
Fix tests
christophfroehlich Oct 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions hardware_interface/doc/mock_components_userdoc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ calculate_dynamics (optional; boolean; default: false)
Calculation of states from commands by using Euler-forward integration or finite differences.

custom_interface_with_following_offset (optional; string; default: "")
Mapping of offsetted commands to a custom interface.
Mapping of offsetted commands to a custom interface (see ``position_state_following_offset``).

disable_commands (optional; boolean; default: false)
Disables mirroring commands to states.
Expand All @@ -92,7 +92,9 @@ mock_sensor_commands (optional; boolean; default: false)
Those interfaces are usually used by a :ref:`forward controller <forward_command_controller_userdoc>` to provide access from ROS-world.

position_state_following_offset (optional; double; default: 0.0)
Following offset added to the commanded values when mirrored to states. Only applied, if ``custom_interface_with_following_offset`` is false.
Following offset added to the state values when commands are mirrored to states.
If ``custom_interface_with_following_offset`` is empty, the offset is applied to the ``position`` state interface.
If a custom interface is set, the ``position`` state value + offset is applied to that interface.

Per-Interface Parameters
########################
Expand Down
41 changes: 7 additions & 34 deletions hardware_interface/include/mock_components/generic_system.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ class GenericSystem : public hardware_interface::SystemInterface
CallbackReturn on_init(
const hardware_interface::HardwareComponentInterfaceParams & params) override;

std::vector<hardware_interface::StateInterface> export_state_interfaces() override;
hardware_interface::CallbackReturn on_activate(
const rclcpp_lifecycle::State & previous_state) override;

std::vector<hardware_interface::CommandInterface> export_command_interfaces() override;
std::vector<hardware_interface::InterfaceDescription>
export_unlisted_command_interface_descriptions() override;

return_type prepare_command_mode_switch(
const std::vector<std::string> & start_interfaces,
Expand Down Expand Up @@ -75,51 +77,22 @@ class GenericSystem : public hardware_interface::SystemInterface
const std::vector<std::string> standard_interfaces_ = {
hardware_interface::HW_IF_POSITION, hardware_interface::HW_IF_VELOCITY,
hardware_interface::HW_IF_ACCELERATION, hardware_interface::HW_IF_EFFORT};

/// The size of this vector is (standard_interfaces_.size() x nr_joints)
std::vector<std::vector<double>> joint_command_values_;
std::vector<std::vector<double>> joint_state_values_;
std::vector<std::string> skip_interfaces_;

std::vector<std::string> other_interfaces_;
/// The size of this vector is (other_interfaces_.size() x nr_joints)
std::vector<std::vector<double>> other_command_values_;
std::vector<std::vector<double>> other_state_values_;

std::vector<std::string> sensor_interfaces_;
/// The size of this vector is (sensor_interfaces_.size() x nr_joints)
std::vector<std::vector<double>> sensor_mock_command_values_;
std::vector<std::vector<double>> sensor_state_values_;

std::vector<std::string> gpio_interfaces_;
/// The size of this vector is (gpio_interfaces_.size() x nr_joints)
std::vector<std::vector<double>> gpio_mock_command_values_;
std::vector<std::vector<double>> gpio_command_values_;
std::vector<std::vector<double>> gpio_state_values_;
std::vector<std::string> gpio_mock_interfaces_;

private:
template <typename HandleType>
bool get_interface(
const std::string & name, const std::vector<std::string> & interface_list,
const std::string & interface_name, const size_t vector_index,
std::vector<std::vector<double>> & values, std::vector<HandleType> & interfaces);

void initialize_storage_vectors(
std::vector<std::vector<double>> & commands, std::vector<std::vector<double>> & states,
const std::vector<std::string> & interfaces,
const std::vector<hardware_interface::ComponentInfo> & component_infos);

template <typename InterfaceType>
bool populate_interfaces(
const std::vector<hardware_interface::ComponentInfo> & components,
std::vector<std::string> & interfaces, std::vector<std::vector<double>> & storage,
std::vector<InterfaceType> & target_interfaces, bool using_state_interfaces);
std::vector<hardware_interface::InterfaceDescription> & command_interface_descriptions) const;

bool use_mock_gpio_command_interfaces_;
bool use_mock_sensor_command_interfaces_;

double position_state_following_offset_;
std::string custom_interface_with_following_offset_;
size_t index_custom_interface_with_following_offset_;

bool calculate_dynamics_;
std::vector<size_t> joint_control_mode_;
Expand Down
Loading