ROS Basics in 5 Days: Exercise 4.3 can't found module package that contain Age.msg

How to solve this problem?

  • CMakeList.txt :
    cmake_minimum_required(VERSION 3.0.2)
    project(ex_42)
    find_package(catkin REQUIRED COMPONENTS
    nav_msgs
    rospy
    message_generation
    )
    add_message_files(
    FILES
    Age.msg
    )
    generate_messages(
    DEPENDENCIES
    nav_msgs
    )
    catkin_package(
    CATKIN_DEPENDS rospy message_runtime
    )
    include_directories(
    ${catkin_INCLUDE_DIRS}
    )

  • package.xml :

<?xml version="1.0"?>

<package format=“2” '> #My code don’t have ’
<name '>ex_42</name '> #My code don’t have ’
<version '>0.0.0</version '>
<description '>The topic_ex package</description '>
<maintainer email=“user@todo.todo” '>user</maintainer '>
<license '>TODO</license '>
<buildtool_depend>catkin</buildtool_depend>
<build_depend>rospy</build_depend>
<build_depend>nav_msgs</build_depend>
<build_depend>message_generation</build_depend>
<build_export_depend>rospy</build_export_depend>
<exec_depend>rospy</exec_depend>
<build_export_depend>nav_msgs</build_export_depend>
<exec_depend>nav_msgs</exec_depend>
<build_export_depend>message_runtime</build_export_depend>
<exec_depend>message_runtime</exec_depend>
<export '>
</export '>
</package '>

  • age_pub.py :
    #! /usr/bin/env python
    import rospy
    from ex_42.msg import Age
    rospy.init_node(‘Age_pub’)
    pub = rospy.Publisher(’/age’, Age, queue_size=1)
    rate = rospy.Rate(2)
    age = Age()
    age.years = 20
    age.months = 0
    age.days = 21
    while not rospy.is_shutdown():
    pub.publish(age)
    rate.sleep()

  • Age.msg :
    float32 years
    float32 months
    float32 days

1 Like

messageImage_1607086570454 !

messageImage_1607086841155

messageImage_1607086896516

In your CMakeLists.txt under generate_messages remove nav_msgs and add std_msgs. Also add it to your catkin_package: CATKIN_DEPENDS rospy std_msgs message_runtime.
In your package.xml replace all your nav_msgs with std_msgs. Then delete your build and devel directories:
cd catkin_ws/
rm -rf build/
rm -rf devel/
finally run catkin_make and it will rebuild everything for you. When done run: source devel/setup.bash and everything should be fine. I have deleted my build and devel folder more than once so don’t worry about it.

1 Like

Thank you, I can imported package but


How to solve next problem. TT

OK ,I can solved it
Beacause I’m open new terminal , It must source again.

Maker sure you source devel/setup.bash before you try and import you have to do this in every terminal you want to use it in Get use to sourcing your devel/setup.bash it it required in future exercises.