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

ros publisher not publishing in debug

asked 2021-12-22 14:01:36 -0600

Nachum gravatar image

Hi

I'm running my node in debug (vscode) and getting weird results. I have a loop which is publishing to a motor

while (std::abs(orientation.roll) > ROLL_FLAT_SURFACE)
{     
    ros::spinOnce();
    bla bla bla


    robotControlPublisher_.publish(motor_cmd_);
    ros::Duration(TIME_TO_SLEEP).sleep();


}

if I put a breakpoint before and after the loop and run in debug the publisher will publish. if I stop each iteration the publisher won't publish. how can I fix it? Thanks

edit retag flag offensive close merge delete

Comments

What do you mean by "stop each iteration"?

Geoff gravatar image Geoff  ( 2021-12-22 16:43:46 -0600 )edit

put a breakpoint after ros::spinOnce(); press F5 to run to the next breakpoint

Nachum gravatar image Nachum  ( 2021-12-23 01:20:53 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2021-12-23 17:08:39 -0600

Geoff gravatar image

The debugger is probably stopping the entire ROS infrastructure in your process before it's had a chance to actually publish your message. ros::spinOnce() only spins the processing loop once, and when that returns and the debugger stops your process, the message might not have made it through the entire publishing process yet.

edit flag offensive delete link more

Comments

This command (ros::Duration(TIME_TO_SLEEP).sleep should have helped

Nachum gravatar image Nachum  ( 2021-12-24 00:35:57 -0600 )edit

TIME_TO_SLEEP =0.1

Nachum gravatar image Nachum  ( 2021-12-24 00:40:15 -0600 )edit
0

answered 2021-12-23 08:06:23 -0600

Mike Scheutzow gravatar image

It is probably publishing the message, but you are not sending them fast enough to activate the motor controller. For safety reasons, many motor controllers require you to publish command messages at a minimum rate. 5 Hz is usually enough.

edit flag offensive delete link more

Comments

I'm looking at the published topic no msgs are received

Nachum gravatar image Nachum  ( 2021-12-23 14:47:26 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2021-12-22 14:01:36 -0600

Seen: 272 times

Last updated: Dec 23 '21