pythonlinuxdriverrosmotordriver

ROS use two same controllers(drivers) for seperate motors


I use ROS Noetic, for an AGV project. I would like to use two controllers/drivers of the same type. In particular, I want to use Roboteqs controllers. In the github there are the packages that is used so that to control roboteq driver (git clone https://github.com/Roboteq-Inc/ROS-Driver.git), and I can use the topics so that to monitor some parameters such the speed, and also using the teleop_twist_keyboard package I can rotate the motor normally, until here all are ok. In the case that I want to connect a second driver, which is the best way to do this? I tried to create two different nodes for each controller, but the topics are the same for both of them, I tries also to create two different packages for the two different controllers but I faced some issues because of the same naming files. So my generally questions are:

If I use two different nodes, how can I select the only one node to publish/subscribe to a specific node, as the two nodes have the same topics, for example i want to select to move the first motor using the cmd_vel topic.

How can I use two same devices with the same driver//package (here motor/drivers) ?

Thank you in advance

I tried creating two different nodes but without any succeed. Also I created two different packages but I faced some issues also.

Thank you in advance


Solution

  • In ROS, the solution to this is using namespaces and remapping as outlined here: http://wiki.ros.org/roslaunch/XML/remap. The key point being that when you have multiple motor controller node instances that each are expecting a /cmd_vel topic, you can remap 'FROM topic "A" TO topic "B", then whenever a node thinks it is subscribing to topic "A", it is actually subscribing to topic "B"' This allows you to reuse the node code for multiple devices that have identical interfaces.

    An example of a launch file remapping the second motor controller would look something like this

    <node name   = "roboteq_motor_controller_driver_1"
          pkg    = "roboteq_motor_controller_driver"
          type   = "roboteq_motor_controller_driver_node" 
          output = "screen">
    </node>
    
    <node name   = "roboteq_motor_controller_driver_2"
          pkg    = "roboteq_motor_controller_driver"
          type   = "roboteq_motor_controller_driver_node" 
          output = "screen">
        <remap from="/cmd_vel" to="/motor_2/cmd_vel" />
    </node>
    

    This way, only the first motor controller is reading the /cmd_vel topic from the teleop_twist_keyboard node.

    If you would like blended control of both motors using the keyboard package (say for a two wheeled robot), you should create a in-between node that reads the /cmd_vel and calculates each motor command separately and publishes the separate commands to /motor_1/cmd_vel and /motor_2/cmd_vel