Ask Your Question
0

g_main_loop_new

asked 2016-06-07 16:04:04 -0500

I have an object that uses glib (g_main_loop_new) for its callbacks that i want to use to build a ROS node. How does the two loops spin and g_main_loop_run run at the same time?.

until now I have try this:

GMainLoop* main_loop = NULL;
main_loop = g_main_loop_new (NULL, FALSE);
thread t(g_main_loop_run, main_loop);   
ros::spin();
t.join();

But just main_loop seams to be runing.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2019-10-01 13:44:59 -0500

mwenger gravatar image

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.

edit flag offensive delete link more
0

answered 2016-06-08 05:27:43 -0500

gvdhoorn gravatar image

Use ros::spinonce() in your GMainLoop.

See roscpp/Overview/Callbacks and Spinning.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2016-06-07 16:04:04 -0500

Seen: 187 times

Last updated: Jun 08 '16