Ask Your Question
0

2 Inputs but 1 output

asked 2019-02-12 03:23:41 -0500

loguna gravatar image

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.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2019-02-12 03:50:48 -0500

Delb gravatar image

updated 2019-02-12 03:54:14 -0500

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
edit flag offensive delete link more

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: 2019-02-12 03:23:41 -0500

Seen: 24 times

Last updated: Feb 12