Robotics StackExchange | Archived questions

2 Inputs but 1 output

Hi,

I been playing with publisher and subscribers recently and wish to challenge myself. Recently i wish to make a program such that: node A : ask user for input ("H or B") node B : ask user for input ( "key in 2 numbers:")

the 2 nodes will transfer the user data via topics to node C.

node C: publish (Hello and the value of the addition of the 2 numbers if 'H' is key on node A.) Otherwise (publish bye if 'B' is keyed on node A).

However i encounter problems as i am unsure if a topic can publish both string and integer on node C.

Asked by loguna on 2019-02-12 04:23:41 UTC

Comments

Answers

However i encounter problems as i am unsure if a topic can publish both string and integer on node C.

It is totally possible to do that, you just have to specify the right type of message for the topic. From the standard ros messages (std_msgs) you have either std_msgs::Int16 or std_msgs::String but not both, so you just have to define a custom message (see here the wiki about custom messages).

You can even avoid using the standard ros messages as they use an additional field data, your message would simply be :

int your_integer
string your_string

Asked by Delb on 2019-02-12 04:50:48 UTC

Comments