ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I realize this was asked a while back, but in case anyone is still struggling with a similar issue, something like the following is working for me...

glib_mainloop = g_main_loop_new (NULL, false);
glib_context = g_main_context_default();

while (ros::ok())
 {
    g_main_context_iteration(glib_context, false);
    ros::spinOnce();
}

g_main_loop_unref (glib_mainloop);

The idea here is that for each loop of the while statement, the glib main loop is iterated once, followed by a single interation of the ROS loop.

I realize this was asked a while back, but in case anyone is still struggling with a similar issue, something like the following is working for me...

glib_mainloop = g_main_loop_new (NULL, false);
glib_context = g_main_context_default();

while (ros::ok())
 {
    g_main_context_iteration(glib_context, false);
    ros::spinOnce();

  // sleep for a while to avoid maxing out CPU
   std::this_thread::sleep_for(std::chrono::milliseconds(20));
}

g_main_loop_unref (glib_mainloop);

The idea here is that for each loop of the while statement, the glib main loop is iterated once, followed by a single interation of the ROS loop.