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

[ROS2] ModuleNotFoundError: No module named

asked 2019-03-14 01:09:06 -0500

vKuehn gravatar image

updated 2019-03-14 03:07:48 -0500

jayess gravatar image

from the examples of ROS 2 I tried to copy the AddTwoInts Example to my own package. ros2 run try_srv add_two_ints_server generates an error when importing AddTwoInts

ModuleNotFoundError: No module named 'try_srv'

thought the reason is that the idl file is not generated (can't find them in install or build folder).

Changing from try_srv.srv import AddTwoInts back to from example_interfaces.srv import AddTwoInts works fine

this is the folder structure

image description

this is the package file

<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format2.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
  <name>try_srv</name>
  <version>0.0.1</version>
  <description>migrated from examples</description>

  <license>Apache License 2.0</license>

  <buildtool_depend>rosidl_default_generators</buildtool_depend>

  <exec_depend>rclpy</exec_depend>
  <exec_depend>std_msgs</exec_depend>

  <member_of_group>rosidl_interface_packages</member_of_group>

  <export>
    <build_type>ament_python</build_type>
  </export>
</package>

is the folder and package.xml structure ok ?

if so what else could be the reason that the import fails ?

edit retag flag offensive close merge delete

Comments

Can you please update your question with a link to the tutorial that you're referring to?

jayess gravatar image jayess  ( 2019-03-14 03:07:10 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
2

answered 2019-03-14 04:37:01 -0500

marguedas gravatar image

In ROS 2, message generation is done using the CMake macro rosidl_generate_interfaces, you can find an example of that macro invocation here.

As your package is a pure python package, it cannot invoke that CMake macro and generate the files.


Looking at your folder structure, the AddTwoInts_{Request,Reply}.msg files are not necessary. These will be generated automatically from your srv file.


In the package.xml: If your srv file depend on std_msgs, the std_msgs dependency needs to be listed as a build_depend as well as an exec_depend.


Finally, it is recommended to have the message definitions in a separate package and then import them from the packages that have the actual code and use them. If you want to use messages/services from the same package, you will need to specify it in your CMakeLists.txt by using the macro rosidl_target_interfaces, an example can be found here

HTH

edit flag offensive delete link more

Comments

thanks for the help will check it out

vKuehn gravatar image vKuehn  ( 2019-03-14 22:11:20 -0500 )edit

now I was able to create a try_srv and a try_srv_msgs package which both work as expected. Thanks a lot

vKuehn gravatar image vKuehn  ( 2019-03-15 00:14:04 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2019-03-14 01:09:06 -0500

Seen: 11,046 times

Last updated: Mar 14 '19