Ask Your Question
0

ROS2 ros2_control/hardware_interface/ - working example?

asked 2021-03-28 05:56:12 -0600

Dragonslayer gravatar image

updated 2021-03-28 05:57:34 -0600

Iam getting ready to migrate to ROS2, so I have to get my hw interface class working there. I had a look at github ros2_controls and it seems to be very different. Any direction or links to a more in detail explanation, tutorials or working examples would be highly appreciated. Also I couldnt find any kind of documentation, is there any?

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
2

answered 2021-03-28 16:05:23 -0600

RandyD gravatar image

Hi,

I have been strugling with the same issue and took me few days to figure it out. I commited my WIP code so u can see an exampled. https://github.com/DeborggraeveR/ros2...

This is a simular approuch as my ROS1 robot which is using the RobotHW interface and communicates with arduiono: https://github.com/DeborggraeveR/ampru

I don't have a tutorial yet, but here is a quick summary of what i done so far

Visualize the robot Create the mecanumbot_description package with urdf model Create the mecanumbot_bringup package with launch file for robot_state_publisher & join_state_publisher to be able to visualize the robot model in rviz2

Add the hardware interface Create the mecanumbot_hardware package and implement a "hardware_interface::SystemInterface" class. Most important line in this class is:

hardware_interface::CommandInterface(
            info_.joints[i].name, hardware_interface::HW_IF_VELOCITY, &velocity_commands_[i]
        )

If the joint name = wheel_joint, we map /joint_state/wheel_joint/velocity to "velocity_command_" So if the velocity changes, the value will be stored in the "velocity_command_" which u can read during the "write" call. Important on making this package work:

  • Add the plugin xml on the root of the package
  • Add the "PLUGINLIB_EXPORT_CLASS" in your hardware class
  • Add the "pluginlib_export_plugin_description_file" in your CMakeList file

Next you need to define the joints used by the hardware in the URDF file (see bottom of my URDF => ros2_control node) I also added the controller config file to the description package

Use the hardware class Next i removed the "joint_state_publisher" from the bringup package launch files and added ros2_control When u launch this, it wont work. U can call "ros2 control list_hardware_interfaces" to see your hardware and notice all joint are unclaimed U can call "ros2 control list_controllers" to see there are no active controllers

Next is to get your joint state published, this seems to do the same as the "joint_state_publisher" which is now commented out in my launch files

ros2 control load_start_controller joint_state_controller

Still the hardware is unclaimed. I tried with running "ros2 control load_start_controller diffbot_base_controller" to launch the DiffDriveController. I found example of this in PR or ros2_control_demos repo: https://github.com/BorgesJVT/ros2_con...

Custom controller As i'm working on a mecanum bot, i also created a mecanumbot_controller package, which contains the controller. Important part of the controller is that it subscribes to "/cmd_vel". Run "ros2 run teleop_twist_keyboard teleop_twist_keyboard" to publish those messages The controller added the joints used by the hardware in the "command_interface_configuration" method. This causes running this controller to claim the joins (ros2 control list_hardware_interfaces)

During the update of the controller i set the velocity as value of the "hardware_interface::LoanedCommandInterface" This causes the variable mapped in the hardware to be updated.

Auto launch controllers I have a open question here on the board on how to spawn the controllers trough launch files. As workaround i added the mecanumbot_control packages, where the main method is the same as the ros2_control controller_manager main and where i add, configure & start my controllers

Final When i run the teleopt_twist_keyboard and ... (more)

edit flag offensive delete link more

Comments

note: when u use the DiffDriveController, i might notice the model flickering in rviz and saying the tf messages are invalid. Not sure if this is a bug or if i did something wrong, but with my custom controller i dont have this issue

RandyD gravatar image RandyD  ( 2021-03-28 16:07:21 -0600 )edit

Thank you very, very much @RandyD!!

Dragonslayer gravatar image Dragonslayer  ( 2021-03-29 01:14:48 -0600 )edit

@Dragonslayer Updated my repo, which is now capable to drive the robot using a xbox-one controller connected to the raspberry pi running ros2 with ros2_control & hardware interface

RandyD gravatar image RandyD  ( 2021-04-02 17:21:17 -0600 )edit

Thanks. Are you on pi4?

Dragonslayer gravatar image Dragonslayer  ( 2021-04-03 03:09:16 -0600 )edit

yes rpi4, works great :)

RandyD gravatar image RandyD  ( 2021-04-03 04:49:40 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

4 followers

Stats

Asked: 2021-03-28 05:56:12 -0600

Seen: 877 times

Last updated: Mar 28