I’ve created my own message to show the age of the robot, but I keep getting this error. I believe I have correctly made the changes in CMakeList and Package.xml files. The msg shows up in rosmsg show, but gives error in python script. I have made sure to catkin_make and source devel/setup.bash too. Help!
Hi @Yogesh_G ,
- Could you post the contents of your message?
- If you have used your custom message in a program code, could you also post that program code here?
Please use the Preformatted Text </> in your reply to encapsulate your code.
Sure, here are the contents: -
age.msg file: -
path - ~/catkin_ws/src/read_odom_pkg/msg
float32 years float32 months float32 days
The program code, age_pub.py: -
#! /usr/bin/env python import rospy from read_odom_pkg.msg import age rospy.init_node('age_publisher_node') # Initiating node. # Defining publisher. pub = rospy.Publisher('/age_pub_topic', age, queue_size=1) rate = rospy.Rate(2) # 2Hz publish rate. a = age() a.years = 22 # Defining the msg a.months = 8 a.days = 15 while not rospy.is_shutdown(): # Loop till force shutdown pub.publish(a) # Publish. rate.sleep() # sleep to match publish rate.
Your age.msg and your age_pub.py looks fine. Only difference is that you are using
float instead of
int for age variables.
Could you post your error traceback as a screenshot ?
Also, did you add std_msgs as a dependency to CMakeLists.txt and package.xml?
Yes, I have added std_msgs as a dependency to CMakeList.txt and package.xml.
This is the error’s screenshot: -
That is weird. Are you sure you created
catkin_create_pkg and not using
Did you do
catkin_make after you created the custom message?
Did you try
rosrun read_odom_pkg age_pub.py ?
Yes I did! I used
catkin_makeas well as source the
~/catkin_ws/devel/setup.bashfile too. Hence I’m confused what’s going wrong.
Just tried rosrun,
I am actually out of ideas. All your steps seem to be correct.
float instead of
int is a problem, which I think will not be, you should not get this error.
As a last resort, I would tell you to re-create the package from scratch.
Hey @girishkumar.kannan , I made the complete package again. tried different names and used int32 instead of float32, but the error still persists. I get the same traceback error.
Thankyou for your time and help!
I was facing the same issue till yesterday. i cleaned my workspace and then it worked. Your codes are alright try cleaning your workspace once. I suppose when you are using catkin_make the packages are not updating. Thus if you clean and reset your workspace everything should work fine.
For the process of resetting kindly follow the following link
hope it helps.
Hey @ra130 , I used your suggestion and it helped me. Thanks a lot for the help.
This topic was automatically closed after 17 hours. New replies are no longer allowed.