ROS2 cannot load custom my_package.srv
I am trying to add my custom service to my_package. I created a 'srv' folder under 'my_package' and add "Battery.srv" as below
---
float64 volt
float64 SOC
float64 current
and added followings to package.xml
<build_depend>rosidl_default_generators</build_depend>
<exec_depend>rosidl_default_runtime</exec_depend>
<member_of_group>rosidl_interface_packages</member_of_group>
and in CMakeLists.txt
find_package(builtin_interfaces REQUIRED)
find_package(rosidl_default_generators REQUIRED)
rosidl_generate_interfaces(${PROJECT_NAME}
"srv/Battery.srv"
)
Also in my setup.py
setup(
name=package_name,
version='0.0.1',
packages=find_packages(exclude=[]),
data_files=[
('share/ament_index/resource_index/packages', ['resource/' + package_name]),
('share/' + package_name, ['package.xml']),
(os.path.join('share', package_name, 'launch'), glob(os.path.join('launch', '*.launch.py'))),
(os.path.join('share', package_name, 'param'), glob(os.path.join('param', '*.yaml'))),
(os.path.join('share', package_name, 'srv'), glob(os.path.join('srv', '*.srv'))),
],
Finally in my package_node.py I tried to import
from my_package.srv import Battery
After colcon build this package successfully, to checked my service I entered below
$ ros2 interface show my_package/srv/Battery
---
float64 volt
float64 SOC
float64 current
Now when I tried to run my package node I got error like this
File "/home/my/ros2_ws/build/my_package/my_package/scripts/my_package_node.py", line 14, in <module>
from my_package.srv import Battery
ModuleNotFoundError: No module named 'my_package.srv'
Is there anything wrong with my practice? Any advice would be much appreciated. Kyu