Ask Your Question
0

Publish a complex msg on a topic

asked 2015-10-26 05:00:50 -0600

azfboom gravatar image

updated 2015-10-26 05:38:17 -0600

gvdhoorn gravatar image

Hey,

I read the topic on publishing for python scipt but now I would like to published complex msg like :

People.msg

Inside
Int Age
String FName
String LName

I don't know what I am supposed to write in the python script to publish data ob the different part of the message ? Something like :

pub_People = rospy.Publisher('people', People);

And the I change the value of the people.age before publishing ?

People.age =10
pub_People .publish(people.age)

Thank you for your help.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2015-10-26 05:10:34 -0600

gvdhoorn gravatar image

updated 2015-10-26 05:38:59 -0600

Something like :

pub_People = rospy.Publisher('people', People);

And the I change the value of the people.age before publishing ?

People.age =10
pub_People .publish(people.age)

Yes, that is the gist of it.

You'd work with an instance of the message though, not the People class itself. So:

from wherever.msg import People
...
pub_People = rospy.Publisher('people', People)
...
my_msg = People()
my_msg.age = 10
my_msg....
...
pub_People.publish(my_msg)

I've skipped things like initialisation and spinning, be sure to add those as well.

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: 2015-10-26 04:53:35 -0600

Seen: 639 times

Last updated: Oct 26 '15