ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Do I need to write my own PID controller when using ros2_control?

asked 2022-02-07 21:36:09 -0500

Tudala gravatar image

Hi all, while using forward_controller in ros2_control I found:

There is no PID control code involved in ros2_control_demo. I think this is because ros2_control_demo is built on virtual hardware, for example, it handles the relationship between hw_state and hw_command like this:

hardware_interface::return_type RRBotSystemPositionOnlyHardware::read()
{
  RCLCPP_INFO(rclcpp::get_logger("RRBotSystemPositionOnlyHardware"), "Reading...");

  for (uint i = 0; i < hw_states_.size(); i++)
  {
    // Simulate RRBot's movement
    hw_states_[i] = hw_states_[i] + (hw_commands_[i] - hw_states_[i]) / hw_slowdown_;
    RCLCPP_INFO(
      rclcpp::get_logger("RRBotSystemPositionOnlyHardware"), "Got state %.5f for joint %d!",
      hw_states_[i], i);
  }
  RCLCPP_INFO(rclcpp::get_logger("RRBotSystemPositionOnlyHardware"), "Joints successfully read!");

  return hardware_interface::return_type::OK;
}

Does that mean I need to write my own PID control code if using real hardware?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2022-02-08 23:20:50 -0500

guru_florida gravatar image

Ros2 controls isn't opinionated on how your hardware interface is implemented. Some hardware may have it's own PID control already. You don't have to implement your own PID though, there are many useful control classes in the ros2 control_toolbox package on github, or install via sudo apt install ros-<foxy|galactic>-control-toolbox.

See the PID class in include/control_toolbox/pid.hpp. There is also a Ros2 PID node that wraps this class, but for ros2_controls implementation you want the one in pid.hpp. I'd peruse the other classes in that package as well.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2022-02-07 21:36:09 -0500

Seen: 1,405 times

Last updated: Feb 08 '22