Ask Your Question
0

why node handler not publishing without infinite loop on pr2?

asked 2012-11-23 01:48:31 -0500

zeroth gravatar image

updated 2014-11-22 17:05:14 -0500

ngrennan gravatar image

I have just modified the teleop_pr2_keboard code to do one task in the function void

TeleopPR2Keyboard::keyboardLoop(){
// I removed everything and added 
    cmd.linear.y = 50;
    vel_pub_.publish(cmd);
// See no while or infinite loop 
}
this doesn't work but if i just do 
TeleopPR2Keyboard::keyboardLoop(){
   while(1){ 
    cmd.linear.y = 50;
    vel_pub_.publish(cmd);
   } 
}

everything starts wroking but i just want the program to do one thing and stop how do i do this ?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2012-11-23 02:21:58 -0500

dornhege gravatar image

You didn't post the whole code, so I can only guess what is happening.

My suspicion is that this is called somewhere once from your main after startup. In that case the publish line is called, but there are no subscribers connected yet. Just wait until vel_pub_.getNumSubscribers() > 0 and then execute one command.

edit flag offensive delete link more

Comments

That explains a problem I've been having. However that is a ridiculous design. A publisher should not be concerned about subscribers, that is ROSCORE's job. So now I have to advertise my node, and then check if anyone is interested?

Nap gravatar imageNap ( 2014-05-18 03:49:23 -0500 )edit

Everything is working as intended. You can and usually should publish without worrying if anyone is connected - unless you have some requirement to explicitly check for that.

dornhege gravatar imagedornhege ( 2014-05-18 05:40:42 -0500 )edit

@dornhedge, I really appreciate the answer you gave above because I had run out of ideas and it fixed the problem. However, what do you mean by *usually* and *unless*? If there are no subscribers, either the message is bufferer (in accordance to the buffer parameter) or the message is dropped. But in my case, the subscriber was there listening but didn't receive anything. And similar to Zoroth's case, having a loop made the difference. This doesn't seem to me how it was intended to be?

Nap gravatar imageNap ( 2014-05-25 19:22:20 -0500 )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

Stats

Asked: 2012-11-23 01:48:31 -0500

Seen: 129 times

Last updated: Nov 23 '12