Exercise 3.2 - import my custom message

Hello,
I’m stuck with how to import my customed message.

I followed the steps and modified CMakeLists.txt and package.xml files inside my package.
I think that part is fine (I read the literature and watched the video), when I do rosmage show Age it prints the correct info.

But after I modify the code (from ex3.1) to import the message, I get an error. My code is as follows:
from ex3_package.msg import Age # (ex3_package is my package name; msg is the message dir)

I get the following error:
" from ex3_package.msg import Age
ImportError: No module named ex3_package.msg"

My script is named differently (I saw online that it could cause issues if not), and I’m not sure what else I’m doing wrong.

Thanks

Hi @lneharde
You package name is defined in the package.xml and CMakeLists.txt, NOT the folder name. Please check if that is correct

Hello @simon.steinmann91, thanks for the message.
From my understanding my package name is ex3_package (I created it using catkin_create_pkg ex3_package rospy)

Also, if I do
rospack list | grep ex3
I get the path to my package.

Can you spot the issue?

I think I solved it. I didn’t run source devel/setup.bash after I changed things.

I’m still very stuck with this exercise, any help will be appreciated since I’m already trying to solve it for a few hours.

Glad to hear that you solved that Error. As for further help, you will have to be a bit more specific. What exactly are you struggling with?

I don’t know how to solver exercise.
I know that I need to create a publisher, but where do I publish to? How can I print the results? Should I pass two parameters to the function?
Just any help will be useful.

I can share my code, but it’s garbage at this point.

@lneharde,

I have checked your package. The problem I see is that you are trying to solve several exercises with one python file. While this is possible, this can create the kind of confusion you have. It’s better to create different python files for the exercises, to start with.

For instance:

  1. Exercise 3.2 only requires a subscriber. You just need to print the odometry message in the subscriber. You don’t the Age message here. Here rospy.spin() is useful.
  2. Exercise 3.3 only requires a publisher. You don’t need a callback function here. Just create the publisher, create the message and publish the message. You don’t need rospy.spin() here. You can decide to publish only once (in which case the publish statement will be the last line) or public a number of times (or forever) using conditional statements like while and for.

I’m assuming here that you’re familiar with Python. If not, I’ll recommend that you consider taking the Python for Robotics course.