0
$\begingroup$

I have very similar problem as in this question: ros2_control manage hardware_interface::return_type::ERROR

Basically, I use ROS2, Humble and wrote hardware interface for my controller. Everything works and I can read joint states, write motor commands.

But I wanted to write hardware interface, which might connect back if connection is lost.

So. I wrote on_configure like this:

hardware_interface::CallbackReturn DiffBotSystemHardware::on_configure(
  const rclcpp_lifecycle::State & /*previous_state*/)
{
  // BEGIN: This part here is for exemplary purposes - Please do not copy to your production code
  RCLCPP_INFO(rclcpp::get_logger("DiffBotSystemHardware"), "Configuring ...please wait...");

  RCLCPP_INFO(rclcpp::get_logger("DiffBotSystemHardware"), "Opening port ... %s", cfg_.device_name.c_str()); 

  int status = device_.Connect(cfg_.device_name);
  if (status != RQ_SUCCESS)
  {
    RCLCPP_INFO(rclcpp::get_logger("DiffBotSystemHardware"), "Could not connect to controller," \
              " got status code: %d", status);
    return hardware_interface::CallbackReturn::ERROR;
  }
  RCLCPP_INFO(rclcpp::get_logger("DiffBotSystemHardware"), "Successfully configured!");

  return hardware_interface::CallbackReturn::SUCCESS;
}

So, if it fails, it returns return hardware_interface::CallbackReturn::ERROR.

Ans I tried the same in read and write function - if communication is lost, it returns error.

As far as I understood, in this situation on_error function is called to handle this error and I guess it should as well change it state. https://control.ros.org/master/doc/ros2_control/hardware_interface/doc/hardware_components_userdoc.html

I expect and I want if on_configure functions returns return hardware_interface::CallbackReturn::ERROR, I expect that on_cleanup function is called and after some timeout on_configure is called again. So it tries to reconnect.

But in reality it does not call on_cleanup function. Should I do that somehow manually? Am I missing something? I checked examples, did not see solution.

And error output is as this if on_configure functions returns return hardware_interface::CallbackReturn::ERROR:

[ros2_control_node-1] Opening port: '/dev/ttyACM0'...failed.
[ros2_control_node-1] [INFO] [1709206199.569121295] [DiffBotSystemHardware]: Could not connect to controller, got status code: 1
[ros2_control_node-1] [INFO] [1709206199.569125271] [resource_manager]: Failed to 'configure' hardware 'DiffBot'
[ros2_control_node-1] [INFO] [1709206199.570563099] [controller_manager]: update rate is 10 Hz
[ros2_control_node-1] [INFO] [1709206199.570684613] [controller_manager]: RT kernel is recommended for better performance
[ros2_control_node-1] [WARN] [1709206199.570710731] [resource_manager]: (hardware 'DiffBot'): 'left_wheel_joint/velocity' command interface not in available list. This should not happen (hint: multiple cleanup calls).
[ros2_control_node-1] [WARN] [1709206199.570715183] [resource_manager]: (hardware 'DiffBot'): 'right_wheel_joint/velocity' command interface not in available list. This should not happen (hint: multiple cleanup calls).
[ros2_control_node-1] [WARN] [1709206199.570716868] [resource_manager]: (hardware 'DiffBot'): 'left_wheel_joint/position' state interface not in available list. This should not happen (hint: multiple cleanup calls).
[ros2_control_node-1] [WARN] [1709206199.570718409] [resource_manager]: (hardware 'DiffBot'): 'left_wheel_joint/velocity' state interface not in available list. This should not happen (hint: multiple cleanup calls).
[ros2_control_node-1] [WARN] [1709206199.570719804] [resource_manager]: (hardware 'DiffBot'): 'right_wheel_joint/position' state interface not in available list. This should not happen (hint: multiple cleanup calls).
[ros2_control_node-1] [WARN] [1709206199.570721317] [resource_manager]: (hardware 'DiffBot'): 'right_wheel_joint/velocity' state interface not in available list. This should not happen (hint: multiple cleanup calls).
$\endgroup$

1 Answer 1

0
$\begingroup$

This is a known limitation and got solved on rolling afaik. Could you please check if the code from this PR (should compile on humble) has a different behavior for you? If yes: It is not certain if we backport this to humble because it breaks ABI, but you can always compile ros2_control from source from the PR above even on humble. If no: please report an issue.

$\endgroup$
2
  • $\begingroup$ I compiled [github.com/ros-controls/ros2_control/pull/1422] this PR. But I could not launch it, not sure if is fully compatible with Humble. Although this PR [github.com/ros-controls/ros2_control/pull/838] was launched without any problems. But it did not solved this problem. It worked the same as I was using binary ros2_control packages. I tried humble branch from sources as well. Result is different, but still could not manage to make connection safe working. Anyway, thank you for helping out. I will continue to dig in. $\endgroup$
    – Hercogs
    Commented Mar 1 at 9:58
  • $\begingroup$ 1422 itself should be fine, but probably we have to fix something with ros2_controller as well. your issue might be related to github.com/ros-controls/ros2_control/issues/1103, it was fixed but not backported to humble. $\endgroup$ Commented Mar 1 at 12:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.