Ask Your Question
0

Kill rosrun gracefully

asked 2018-06-23 08:46:57 -0600

kk2105 gravatar image

updated 2018-06-26 07:08:10 -0600

Hi All,

I am running a rosrun command to generate and publish messages continuously from a node X. But I am not able to gracefully kill the session. I am currently closing the terminal in order to stop the task.

Kindly let me know if the below 2 approaches are correct and how to implement it.

  1. Open a new terminal and kill the node X
  2. Ctrl+C to stop the the publishing of messages and return to the terminal (This is what I am actually looking for)

Code Snippet;

     while(ros :: ok)
     {
         ros_time = ros:Time::now();
         publish the message;
         update the message;
         ros::SpinOnce();
      }

I would create a package and then run rosrun

Thank you.

edit retag flag offensive close merge delete

Comments

1

It's likely the node you cannot shutdown is not correctly programmed. Common cause: not checking ros::ok() in your while-loop. Please show us some code of the node or check it yourself.

gvdhoorn gravatar imagegvdhoorn ( 2018-06-23 10:57:56 -0600 )edit

Note btw: even if things were working correctly, you'd not be "killing rosrun", but would be shutting down the node.

gvdhoorn gravatar imagegvdhoorn ( 2018-06-23 11:02:16 -0600 )edit

@gvdhoorn Thank you for the response... code snippet does have ros::ok() condition in while loop... Is there a way I can use Ctrl+C to terminate the rosrun .?

kk2105 gravatar imagekk2105 ( 2018-06-23 11:35:03 -0600 )edit
2

Then please show your code, otherwise we can only guess why things don't work the way they should.

gvdhoorn gravatar imagegvdhoorn ( 2018-06-23 11:43:26 -0600 )edit

@gvdhoorn I was able to stop the node by killing it in another terminal.. however I need to know how can I use Ctrl+C to come out of terminal in this case.. I update the code soon.

kk2105 gravatar imagekk2105 ( 2018-06-26 06:42:32 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
3

answered 2018-06-26 07:20:11 -0600

gvdhoorn gravatar image

updated 2018-06-26 07:20:55 -0600

I believe this was already covered in your other question (#q294951), but this:

while(ros :: ok)

is not correct.

It should be: ros::ok(). It's a function, not a variable.

What you have now probably checks a function pointer, which will evaluate to true, hence making your while-loop equivalent to while (true).

In addition: you don't have a ros::Rate with a rate.sleep() in there anywhere. Adding one will probably help.

edit flag offensive delete link more

Comments

@gvdhoorn ros:ok() worked like a champ.. Now I am able to Ctrl+C to come out of the terminal.. That small mistake was ruining my day...

kk2105 gravatar imagekk2105 ( 2018-06-26 08:34:36 -0600 )edit
1

If you haven't, do add the ros::Rate. If you don't add it, your little node will be using 100% cpu even when it's doing nothing.

gvdhoorn gravatar imagegvdhoorn ( 2018-06-26 08:35:44 -0600 )edit

@gvdhoorn thank you.. Yep.. I have added the ros::Rate and sleep.rate()..

kk2105 gravatar imagekk2105 ( 2018-06-26 08:49:00 -0600 )edit

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: 2018-06-23 08:46:57 -0600

Seen: 297 times

Last updated: Jun 26 '18