0
$\begingroup$

Rosanswers logo

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 ?


Originally posted by zeroth on ROS Answers with karma: 1 on 2012-11-23

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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.


Originally posted by dornhege with karma: 31395 on 2012-11-23

This answer was ACCEPTED on the original site

Post score: 0


Original comments

Comment by Nap on 2014-05-18:
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?

Comment by dornhege on 2014-05-18:
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.

Comment by Nap on 2014-05-25:
@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?

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.