Keep having issues with custom message

Hello like many this exercise for creating a custom message is a bit hard.

To be honest I have done this before but while I’m following all the steps I keep having an import error. But when I do rosmsg list | grep Age I get the correct information as shown in the examples. Now when I even copy the code form the solution and only change the package name it still won’t work.
Than I removed the Build and Devel folders but still issues, So I don’t know what to do anymore actually.

The package.xml file

<?xml version="1.0"?>
<package format="2">
  <description>The read_odometry_pkg package</description>

  <maintainer email="user@todo.todo">user</maintainer>





cmake_minimum_required(VERSION 2.8.3)

## Here go all the packages needed to COMPILE the messages of topic, services and actions.
## Its only geting its paths, and not really importing them to be used in the compilation.
## Its only for further functions in CMakeLists.txt to be able to find those packages.
## In package.xml you have to state them as build
find_package(catkin REQUIRED COMPONENTS

## Generate topic messages in the 'msg' folder
## In this function will be placed all the topic messages files of this package ( in the msg folder ) to be compiled.

## Here is where the packages needed for the topic messages compilation are imported.

## State here all the packages that will be needed by someone that executes something from your package.
## All the packages stated here must be in the package.xml as exec_depend
  CATKIN_DEPENDS rospy message_runtime


And the scripts I wrote

#! /usr/bin/env python

import rospy
from read_odometry_pkg import Age

pub = rospy.Publisher("/age_info", Age, queue_size=1 )
rate = rospy.Rate(2)

age = Age()
age.years = 5
age.monts = 6
age.days = 15

while not rospy.is_shutdown():

Obviously the message file I created is called Age.msg and contains the three float32’s. I don’t see where I make any mistake here. I started first to make adjust CMakeLists and the package.xml files but when that didn’t work out well I copied it from the solution but I keep having issues.

Maybe this information helps, it is the error info:
ImportError: cannot import name ‘Age’ from ‘read_odometry_pkg’ (/home/user/catkin_ws/devel/lib/python3/dist-packages/read_odometry_pkg/

Anybody knows why?

Perhaps this is your scenario.

Did you run source devel/setup.bash on the same terminal where you are attempting to run your package? After (re)compiling your package, you need to source devel/setup.bash on each terminal, otherwise they will not know about your changes.

Additionally, since it appears that you modified your package a number of times, you might need to remove build and devel folder every time you are recompiling (after every change):

cd ~/catkin_ws
rm -rf build/ devel/
source devel/setup.bash # run this line only on the other terminals too


Yes I did both of your suggestions, thats why I posted the question cause I don’t know where to look anymore.

Wait a second…!

Your import line for the message is incorrect. It should be:

from read_odometry_pkg.msg import Age

Ai ai ai I think you are right it seems I made a mistake which I completely overlooked. I will try it asap when I have better internet. I’m working offshore at the moment so I have limited access to the internet.

But again I think you have seen my error correctly




This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.