Robotics StackExchange | Archived questions

ros controller topics not being published

I am trying to write a custum ros hardware interface following this tutorial. I am trying to make a hardware interface for rrbot for testing purpose as it provides already present rrbot descrition and some launch files. Here is the git repository of this catkin package, which sucessfully builds but when i try to view the position controller topics i'm only seeing following ros topics:

$ rostopic list
/rosout
/rosout_agg
/rrbot/joint_states
/tf
/tf_static

when i launch the hardware interface node with the controller with command:

roslaunch rrbot_control rrbot_hardware_interface.launch

the output of the terminal display is:

started core service [/rosout]
process[rrbot/rrbot_hw_interface-2]: started with pid [14994]
process[rrbot/controller_spawner-3]: started with pid [14998]
process[rrbot/robot_state_publisher-4]: started with pid [14999]
read
write
[INFO] [1589016205.926310]: Controller Spawner: Waiting for service controller_manager/load_controller
[INFO] [1589016205.932689]: Controller Spawner: Waiting for service controller_manager/switch_controller
[INFO] [1589016205.938694]: Controller Spawner: Waiting for service controller_manager/unload_controller
[INFO] [1589016205.944457]: Loading controller: joint_state_controller
    read
    write
    read
    write
    ^C[rrbot/robot_state_publishe

r-4] killing on exit
[rrbot/controller_spawner-3] killing on exit
[rrbot/rrbot_hw_interface-2] killing on exit
[INFO] [1589016208.067200]: Shutting down spawner. Stopping and unloading controllers...
read
write

I am using ubuntu 18.04, ros melodic.

Asked by dinesh on 2020-05-09 04:27:21 UTC

Comments

You're most likely not spin()ing. Specifically: here.

Asked by gvdhoorn on 2020-05-09 05:35:30 UTC

i tried that also. but still not working.

Asked by dinesh on 2020-05-09 05:48:37 UTC

Have you tried using a ros::AsyncSpinner? If I remember correctly, it is needed to let the controller manager do its job while the hw is running...

Asked by ffusco on 2020-05-09 15:09:43 UTC

i tried that also. but still not working.

And for future questions: "it does not work" is not a sufficient description of your problem.

No one can help you like this.

Asked by gvdhoorn on 2020-05-10 04:26:06 UTC

Answers

From the repository you linked, this is the main():

int main(int argc, char **argv)
{
  ros::init(argc, argv, "rrbot_hw_interface");

  MyRobot robot;
  controller_manager::ControllerManager cm(&robot);

  while (ros::ok())
  {
     robot.read();
     cm.update(robot.get_time(), robot.get_period());
     robot.write();
     sleep(1);
  }
  return 0;
}

This seems to not be spinning at all. Without that, incoming events cannot be properly processed, which prevents controllers from being started.

i tried that also. but still not working.

You must spin somewhere.

I'm not saying you should literally add spin(), the AsyncSpinner @ffusco mentions would be my first choice, and is in fact also used by the ros_control_boilerplate package you have in your workspace (from here):

int main(int argc, char** argv)
{
  ros::init(argc, argv, "sim_hw_interface");
  ros::NodeHandle nh;

  // NOTE: We run the ROS loop in a separate thread as external calls such
  // as service callbacks to load controllers can block the (main) control loop
  ros::AsyncSpinner spinner(2);
  spinner.start();

  [..]

}

Edit:

is this tested? cas i did this before, but was not working i think.

This pattern is used in countless hardware_interface implementations.

I'm not guaranteeing it will solve your problem, but your code currently does not seem to spin at all, which is certainly something to address first, before looking at other causes.


Edit2: your repository has been updated, now the main() is this:

int main(int argc, char **argv)
{
  ros::init(argc, argv, "rrbot_hw_interface");

  MyRobot robot;
  controller_manager::ControllerManager cm(&robot);

     robot.read();
     cm.update(robot.get_time(), robot.get_period());
     robot.write();
     ros::AsyncSpinner spinner(0); // Use 4 threads
     spinner.start();
  return 0;
}

This will not work. Please compare the structure in the ros_control_boilerplate package with your own code: you'll want to create and start the ros::AsyncSpinner before everything else. Then create your ControllerManager and MyRobot and finally start your while-loop (which seems to have disappeared).

Asked by gvdhoorn on 2020-05-10 04:05:32 UTC

Comments

is this tested? cas i did this before, but was not working i think.

Asked by dinesh on 2020-05-10 04:11:23 UTC