I created ROS2 custom message that contains sensor_msgs/Image.
int64 id
int64 num
sensor_msgs/Image image
inside the python code, when I call this message from tutorial_interfaces.msg import Cropimage
, I always got this error :
raise UnsupportedTypeSupport(pkg_name) rosidl_generator_py.import_type_support_impl.UnsupportedTypeSupport: Could not import 'rosidl_typesupport_c' for package 'tutorial_interfaces'
If I do not add sensor_msgs/Image image
on the message, I do not get this error. Where is my problem, could you help me?
You can create you custom message following below steps,
mkdir ~/ros2_ws/src
# Create a custom_msg package
cd ~/ros2_ws/src && ros2 pkg create --build-type ament_cmake custom_msg --dependencies rclcpp std_msgs rosidl_default_generators
mkdir -p ~/ros2_ws/src/custom_msg/msg/
# Create a LogTf.msg
touch ~/ros2_ws/src/custom_msg/msg/Cropimage.msg
Cropimage.msg content,
int64 id
int64 num
sensor_msgs/Image image
Add the following lines to CMakeLists.txt,
# Add after BUILD_TESTING endif()
rosidl_generate_interfaces(${PROJECT_NAME}
"msg/Cropimage.msg"
)
Add the following lines to to package.xml,
# Add after <depend>std_msgs</depend> line
<depend>rosidl_default_generators</depend>
<exec_depend>rosidl_default_runtime</exec_depend>
<member_of_group>rosidl_interface_packages</member_of_group>
Now compile and Run,
# Compile and Run,
cd ~/ros2_ws
colcon build --packages-select custom_msg #Compilation
source install/setup.zsh
Now you can import it in your python code,
from custom_msg.msg import Cropimage"
You can refer this post,
https://medium.com/@nullbyte.in/ros2-from-the-ground-up-part-3-a-hands-on-guide-to-creating-custom-messages-and-turtlebot3-service-96a68df2e670