close one publisher and start another publisher

asked 2022-01-05 07:19:05 -0500

Yanniesburg gravatar image

Dear all,

I have a quite special need in my program, and I didn't found solution after long time search. Therefore I am posting it here, expecting help form experts here.

Simply speaking, I have two publishers, who returns o and 1 on the same topic, so that the motor receices the msg and the system moves quicker or slower. I donot want to them in one fuction,because I have to connect them with external buttons. Say, the vehicle is moving fast (publishe 1 works), when I press button 2, publisher 1 should be deactivated and publisher 2 should be activated. My question is, how can I realise this, i.e. close publisher 1 and start publisher 2 please?

Your suggestion and advice would be of great help to me. Many thanks in advance.

Best regards Yannie

edit retag flag offensive close merge delete

Comments

1

Can both publishers be on at the same time? Or is it one or the other at any given time? Can your system start with either publisher?

osilva gravatar image osilva  ( 2022-01-07 07:26:22 -0500 )edit

Is it possible to return more info from the publisher other than 0 and 1 to identify the origin of the publisher? Maybe 11 10 01 00

osilva gravatar image osilva  ( 2022-01-07 07:29:19 -0500 )edit

Hi @osilva, thank you for your comment.

Regarding your first comment, at a given time should only one of the publishers work. The system can be start only with publisher 2.

To your second comment, surely more info can be returned by the publisher, because the output can be defined by us. But if there are only two publishes, I think '0' and '1' is already suffcient to distinguish them.

I have a ugly solution now. I just wrote two launch files for each case, and call "rosnode kill" when I wanna switch. But start the core every time costs extra time and is according to my opinion unneccesary, because what is needed is only to switsch the publisher.

Any comments and advices are sincerely welcome. Thank you in advance.

Yanniesburg gravatar image Yanniesburg  ( 2022-01-10 06:49:00 -0500 )edit