using new message Age.msg

asked 2019-05-06 17:00:44 -0500

Nurbek gravatar image

updated 2019-05-06 23:57:59 -0500

gvdhoorn gravatar image

I need to create a python file that creates a publisher that indicates the age of the robot.

I have created a new message Age.msg:

float32 years
float32 months
float32 days

script:

#! /usr/bin/env python  

import rospy

from std_msgs.msg import Float32
print "Age of our robot: "

rospy.init_node("publish_age_node")
pub = rospy.Publisher('/pub_custom_ros_msg', Float32, queue_size=1)

rate=rospy.Rate(5)

age=Float32()

age.years = 5
age.years = 10
age.years = 21

while not rospy.is_shutdown(): 
        pub.publish(age)
    rate.sleep()

SOMETHING WRONG HERE

edit retag flag offensive close merge delete

Comments

1

So what is your question?

gvdhoorn gravatar image gvdhoorn  ( 2019-05-06 23:58:12 -0500 )edit
1

Looking at your code, this doesn't seem right:

age=Float32()

age.years = 5
age.years = 10
age.years = 21

first you make age a Float32, then you try using it like an Age. That won't work.

You'll want to import your custom message and make age an instance of that message.

gvdhoorn gravatar image gvdhoorn  ( 2019-05-06 23:59:45 -0500 )edit

I need to make a simple python file that creates a publisher that indicates the age of the robot.

I have created a new message Age.msg:

float32 years float32 months float32 days

By using this Age.msg file I should create the Python file

Thanks!

Nurbek gravatar image Nurbek  ( 2019-05-07 01:42:06 -0500 )edit
1

Ok. Just making sure: have you completed the introductory tutorials about creating your own message and using it with rospy?

gvdhoorn gravatar image gvdhoorn  ( 2019-05-07 01:45:48 -0500 )edit

Yes, I completed. I also completed publisher and subscriber part

Nurbek gravatar image Nurbek  ( 2019-05-07 02:17:56 -0500 )edit

Did that not give you an idea how to import your own message?

Why are you not using the same approach for your Age message?

gvdhoorn gravatar image gvdhoorn  ( 2019-05-07 03:19:10 -0500 )edit

Maybe I am not sure how to do it properly.

Let me try one more time and I come back here later.

Thanks for comments!

Nurbek gravatar image Nurbek  ( 2019-05-07 03:51:15 -0500 )edit

I did exactly what was said here, in youtube video: https://www.youtube.com/watch?v=ZPmlF...

But still I am getting --- ImportError: No module named mode_publishers.msg

I just changed node_example to mode_publishers

Nurbek gravatar image Nurbek  ( 2019-05-07 09:50:34 -0500 )edit