Robotics StackExchange | Archived questions

using new message Age.msg

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

Asked by Nurbek on 2019-05-06 16:58:34 UTC

Comments

So what is your question?

Asked by gvdhoorn on 2019-05-06 23:58:12 UTC

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.

Asked by gvdhoorn on 2019-05-06 23:59:45 UTC

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!

Asked by Nurbek on 2019-05-07 01:42:06 UTC

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

Asked by gvdhoorn on 2019-05-07 01:45:48 UTC

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

Asked by Nurbek on 2019-05-07 02:17:56 UTC

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?

Asked by gvdhoorn on 2019-05-07 03:19:10 UTC

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!

Asked by Nurbek on 2019-05-07 03:51:15 UTC

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

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

I just changed node_example to mode_publishers

Asked by Nurbek on 2019-05-07 09:50:34 UTC

Answers