Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
afc5c26
Change mock hardware to also save the joint names
christophfroehlich Sep 19, 2025
042cc99
Initial rewrite of the system
christophfroehlich Sep 19, 2025
97eb516
Switch some EXPECT/ASSERT macros
christophfroehlich Sep 19, 2025
f13cf89
Parse initial values in on_activate
christophfroehlich Sep 19, 2025
bba6291
Some more asserts
christophfroehlich Sep 19, 2025
9420712
Fix mimicked interfaces and standard interfaces if isnan/isinf
christophfroehlich Sep 19, 2025
a941b8f
Fix logic for custom_interface_with_following_offset_
christophfroehlich Sep 19, 2025
17df730
Fix gpio mock
christophfroehlich Sep 19, 2025
25d4da5
Fix calculate dynamics
christophfroehlich Sep 19, 2025
17c723b
Support boolean
christophfroehlich Sep 19, 2025
1d9fcdd
Support boolean for joints
christophfroehlich Sep 19, 2025
a008bfb
Remove debug output
christophfroehlich Sep 19, 2025
67c6bae
Remove debug output
christophfroehlich Sep 19, 2025
d56c818
Fix missing braces
christophfroehlich Sep 21, 2025
381e79f
Use the mimic joint index instead
christophfroehlich Sep 23, 2025
0d0d5b2
Revert "Change mock hardware to also save the joint names"
christophfroehlich Sep 23, 2025
e771e43
Merge branch 'master' into Handles_GenericSystem
christophfroehlich Sep 23, 2025
b8a6fdc
Add test for boolean data_type
christophfroehlich Sep 23, 2025
73812bb
Preallocate skip_interfaces
christophfroehlich Sep 23, 2025
a4ebdca
Use some references instead of copies
christophfroehlich Sep 23, 2025
2546161
Move comments
christophfroehlich Sep 23, 2025
eda82f4
Use unordered maps to improve efficiency
christophfroehlich Sep 23, 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