ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

ModuleNotFoundError: No module named 'models' for Rospy

asked 2021-04-13 17:09:54 -0500

Chao Chen gravatar image

updated 2021-04-15 12:42:54 -0500

  1. I have trouble to wrap my existing python program into ROS platform. I suppose my ROS structure as following, the package name is controller_msgs, and launch file should be able to call node and node should call /src and then __init__.py, then find dependency files in include. However, it does not work properly. Below is my ROS structure and my CMakefile.txt, package.xml

  2. I need to create a custom message in rospy and publish it. How should I modify my stuff?

/noetic-workspace
    /build
    /devel
    /src
       /my_meta_pkg
           /my_pkg_A
           /my_pkg B
           /my_pkg_etc...

Under /my_pkg_A:
     /controller_msgs
         /include
              /models
              /runs
              /utils
         /launch
               test.launch
         /msg
         /node
         /src
             /controller_msgs
                  /__init__.py
                  /foo.py
         setup.py

CMakeList.txt:

cmake_minimum_required(VERSION 2.8.3)
project(controller_msgs)

find_package(catkin REQUIRED COMPONENTS
  rospy
  std_msgs
  message_generation
  geometry_msgs
)

catkin_python_setup()

SET(CMAKE_MODULE_PATH ${${PROJECT_NAME}_SOURCE_DIR}/cmake)

FILE(GLOB rosMsgFiles RELATIVE "${${PROJECT_NAME}_SOURCE_DIR}/msg/dds" 
    "${${PROJECT_NAME}_SOURCE_DIR}/msg/dds/*.msg")

## Generate messages in the 'msg' folder
add_message_files(
  FILES
  dds/DoorLocationPacket.msg
)

generate_messages(
  DEPENDENCIES
  std_msgs
  geometry_msgs
)

install(PROGRAMS
   #scripts/simon_script1
   nodes/door_detection_node
   DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)

Package.xml is simpler, I only include the essential code here:

  <buildtool_depend>catkin</buildtool_depend>
  <build_depend>rospy</build_depend>
  <build_depend>std_msgs</build_depend>
  <build_depend>message_generation</build_depend>
  <run_depend>rospy</run_depend>
  <run_depend>std_msgs</run_depend>
  <run_depend>message_generation</run_depend>
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-04-14 07:42:05 -0500

miura gravatar image

The same problem is mentioned here.

It seems to happen when controller_msgs.py is present. In that case, renaming controller_msgs.py will solve the problem.

edit flag offensive delete link more

Comments

1

I do not quite have controller_msgs.py

Chao Chen gravatar image Chao Chen  ( 2021-04-15 12:37:34 -0500 )edit

Maybe it's not only controller_msgs.py, but also /src/controller_msgs. If you change directory name, it might work.

miura gravatar image miura  ( 2021-04-15 22:07:14 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2021-04-13 17:09:54 -0500

Seen: 1,175 times

Last updated: Apr 15 '21