ros_control code sample for a diff_drive

asked 2019-07-26 10:13:29 -0500

BuilderMike gravatar image

updated 2019-08-05 20:29:57 -0500

I am hoping your answer will serve as template for setting up diff_drive on a physical robot. Such a resource is missing, and is strongly needed.

Could you please create a small amount of code that will produce the equivalent of a hello world program for a hardware_interface that utilizes a diff_drive controller? or asked another way, could you please provide a hardware_interface implementation sample that utilizes a diff_drive controller? Please ignore advanced capabilities such as real-time capability, transmissions, limits, or any of that fancy stuff.

Why don't I do it myself? On account of a lack of documentation for ros_control and my lack of C++ skills I am not able to convert valuable examples I found into my own working code. Valuable examples being:

Could you please help by writing the simplest most minimalistic C++ code for these files:

  • src directory files:
    • robot/src/robot_hardware_interface.cpp
    • robot/src/robot_hardware_interface_node.cpp


  • include directory files:
    • robot/include/robot_hardware.h
    • robot/include/robot_hardware_interface.h

Code that is external to ros_control that hardware_interface node calls in read() and write(), such as converting diff_drive output (radians/second) to wheel motion, collecting feedback from the robot, as well as the URDF file is finished can be found here:

If someone chooses to answer this question, I will integrate the code you provide, with my code and test it out on a physical robot. By testing I mean I will use rospub to publish to the topic to which the diff drive subscribes to for geometry_msgs/Twist messages and observe the robot’s physical motion, and if needed modify the code you provided (with your permission) to verify that it works and is solid resource for the community.


edit retag flag offensive close merge delete



There might be readers here who would not have time / be in a position to write a complete hardware_interface for you, but who may be able to help you if you could describe what it is that you don't understand in the repositories / examples that you link to.

gvdhoorn gravatar imagegvdhoorn ( 2019-07-28 12:07:57 -0500 )edit

@gvdhoorn Since I am not a programmer, when I encounter complex code with no documentation (such as in this case) usually I am not able to hack my way to a working solution. I do know that the examples I mentioned are good, but they do not have a standardized structure, they have a bunch of code that I cannot distinguish as relevant to me or not, and generally without some guidance I have not been able to get very far. believe me I tried. If I begin to ask questions about what I do not understand, there will be at least 50 "noob" type questions that are not going to be very impressive. My thoughts were to get someone to finally create an answer that others like me (those who rely on simple documentation to build from) can use to implement a diff_drive controller. Such a resource can then ...(more)

BuilderMike gravatar imageBuilderMike ( 2019-08-02 20:20:04 -0500 )edit

My thoughts were to get someone to finally create an answer that others like me [..] can use to implement a diff_drive controller

A controller, or a hardware_interface? diff_drive_controller already exists, and you shouldn't need to create it for your own system.

Edit: if you're actually asking for an example hardware_interface implementation then the answer would be relative simple to give, but it would also miss quite some implementation details (specifically: how it interfaces with the underlying hw, which is the job of a hardware_interface).

If you're really asking for a controller, that would be something else.

gvdhoorn gravatar imagegvdhoorn ( 2019-08-03 06:07:58 -0500 )edit

@gvdhoornedit: I misspoke, I do not need to implement a diff_drive controller, I need help to implement the hardware_interface (as a complete sample) that utilizes a diff_drive controller. As for the underlying hw, that code is already written in the form of a library. My library needs a radians/sec input and then takes care of the corresponding wheel motion (can be found here: . If someone could please provide a hardware_interface sample that utilizes a diff drive controller (including the src and include files), or provide a link to the most basic sample that would be very, very, very appreciated.

BuilderMike gravatar imageBuilderMike ( 2019-08-03 11:25:31 -0500 )edit

Does my ugly code help? turtlebot3_custom_hardware.h: Set for two wheels, ignore the dynamic reconfigure part. Insert the hardware specific code in read() and write(). Or could you just add your code and tell us your error?

Humpelstilzchen gravatar imageHumpelstilzchen ( 2019-08-06 00:47:55 -0500 )edit