ZebraDevs / robot_controllers

Robot control infrastructure
92 stars 79 forks source link

How to use robot_controllers with a non-Fetch robot #34

Closed pirobot closed 6 years ago

pirobot commented 6 years ago

We have been using the diff_drive_controller/DiffDriveController plugin in Gazebo 2.3 under ROS Indigo with a model of our custom robot (Jackrabbot) at Stanford University. However, we have discovered that the robot rotates very slowly in Gazebo even with no Twist control input, in an empty world, and no matter how we set the pose and twist covariances.

We therefore wanted to try the robot_controllers/DiffDriveBaseController provided here since I noticed that the Fetch Gazebo model (also under ROS Indigo and Gazebo 2.3) does not have this rotation problem.

I include my YAML file below but the DiffDriveBaseController plugin is not being loaded when spawning our Jackrabbot model in Gazebo. I noticed that with the Fetch gazebo launch file, the following lines at the end of the file fetch.gazebo.xacro:

<gazebo>
    <plugin name="fetch_gazebo_plugin" filename="libfetch_gazebo_plugin.so"/>
</gazebo>

are necessary for the DiffDriveBaseController plugin to be loaded. My question is therefore, how can I get the DiffDriveBaseController plugin to load without using the fetch_gazebo_plugin which I am guessing is specific to the Fetch robot?

Thank you! Here is my controllers yaml file:

base_controller:
  type: "robot_controllers/DiffDriveBaseController"
  autostart: true
  base_frame: sibot/base_link
  l_wheel_joint: "left_wheel"
  r_wheel_joint: "right_wheel"
  track_width: 0.542391
  radians_per_meter: 4.15682711
  publish_tf: true
  max_velocity_x: 3.57632
  max_velocity_r: 4.5
  max_acceleration_x: 0.75
  max_acceleration_r: 3.0
  publish_frequency: 100

gazebo:
  default_controllers:
    - "base_controller"
  l_wheel_joint:
    position:
      p: 0.0
      d: 0.0
      i: 0.0
      i_clamp: 0.0
    velocity:
      p: 8.85
      d: 0.0
      i: 0.5
      i_clamp: 6.0
  r_wheel_joint:
    position:
      p: 0.0
      d: 0.0
      i: 0.0
      i_clamp: 0.0
    velocity:
      p: 8.85
      d: 0.0
      i: 0.5
      i_clamp: 6.0
mikeferguson commented 6 years ago

The robot_controllers are not Gazebo-plugins. They are ROS pluginlib-based modules. Thus, you need a gazebo plugin that can load these controllers, and connect the gazebo joints to an instance of ControllerManager which can then load the appropriate controllers (which is exactly what the fetch_gazebo_plugin is doing).

AFAIK, there is nothing specific to Fetch used in our Gazebo plugin -- if you simply add that plugin, it will load the controllers, connect with gazebo, and I think things will start to work. In retrospect, that plugin could have probably even been called robot_controllers_gazebo_plugin -- but I think when we started we imagined it would have more Fetch-specific stuff in it (like providing fake breaker interfaces, etc, which we never ended up implementing).

mikeferguson commented 6 years ago

One additional comment for posterity - since OPs question only really talked about simulation. In a non-simulated robot, if you wanted to use the controllers, you would need to create a node with an instance of a ControllerManager, and then create a class that derives from JointHandle that actually processes the commands by sending them onto your hardware. The Gazebo demo is the only open-source reference I'm aware of, since our drivers are closed source, so the "real" JointHandle used on a robot is not available.

Things are documented, albeit briefly, on the ROS wiki at http://docs.ros.org/kinetic/api/robot_controllers_interface/html/

pirobot commented 6 years ago

Many thanks Fergs. Once again you saved the day! :) FYI, I submitted this issue for the Gazebo differential_drive_controller plugin. Using the fetch_gazebo_plugin instead does not suffer from the same problem.