Conversation
samuelsadok
left a comment
There was a problem hiding this comment.
There's one thing I missed when writing the comment in #24 (comment): There is already a vendor independent ROS2 way to do this: mock_components/GenericSystem.
This repo already showcases it in the odrive_botwheel_explorer usage example, in diffbot.ros2_control.xacro.
With this in mind, do you still have a use case where mock support directly in odrive_hardware_interface.cpp would be important? (please describe)
Still added some review comments while I was at it.
| return_type ODriveHardwareInterface::read(const rclcpp::Time& timestamp, const rclcpp::Duration&) { | ||
| return_type ODriveHardwareInterface::read(const rclcpp::Time& timestamp, const rclcpp::Duration& period) { | ||
| if (use_mock_hardware_) { | ||
| for (auto& axis : axes_) { |
There was a problem hiding this comment.
the body of this for loop should be in a separate function, e.g. Axis::update_mock()
| can_intf_name_ = info_.hardware_parameters["can"]; | ||
| auto mock_parameter = info_.hardware_parameters.find("use_mock_hardware"); | ||
| use_mock_hardware_ = mock_parameter != info_.hardware_parameters.end() && | ||
| (mock_parameter->second == "true" || mock_parameter->second == "1"); |
There was a problem hiding this comment.
hardware_interface::parse_bool() seems to be the standard way to do this.
|
|
||
| for (auto& joint : info_.joints) { | ||
| axes_.emplace_back(&can_intf_, std::stoi(joint.parameters.at("node_id"))); | ||
| if (!use_mock_hardware_) { |
There was a problem hiding this comment.
This adds more complexity than necessary to the init logic. Note that we can just construct the Axis objects with {nullptr, 0} if use_mock_hardware_ is true. Could be as simple as:
use_mock_hardware_ = // load from params
if (use_mock_hardware_) {
// fill axes_ array with Axis(nullptr, 0)
} else {
// old instantiation logic
}
Summary
Add a
use_mock_hardwareparameter to theodrive_ros2_controlsystem interface so controllers can be developed and tested without SocketCAN or physical ODrives.Behavior
NaNThe README documents the parameter and model. This implements the behavior outlined by the maintainer in #24.
Validation
git diff --checkA full build requires the repository ROS 2 development container and is left to project CI.
Closes #24