ROS2 custom message python import error
Hi Deatails: ROS Env
ROS_VERSION=2
ROS_PYTHON_VERSION=3
ROS_LOCALHOST_ONLY=0
ROS_DISTRO=foxy
I created a custom message as follows in Custom.msg file
uint32 number
I have a publisher code with as follows
import rclpy
from rclpy.node import Node
from std_msgs.msg import String
from ros_nodes import Custom
class MinimalPublisher(Node):
def __init__(self):
super().__init__('minimal_publisher')
self.publisher_ = self.create_publisher(String, 'topic', 10)
timer_period = 0.5 # seconds
self.timer = self.create_timer(timer_period, self.timer_callback)
self.i = 0
def timer_callback(self):
#msg = String()
msg = Custom()
msg.number = self.i
self.publisher_.publish(msg)
self.get_logger().info('Publishing: "%s"' % msg.data)
self.i += 1
def main(args=None):
rclpy.init(args=args)
minimal_publisher = MinimalPublisher()
rclpy.spin(minimal_publisher)
# Destroy the node explicitly
# (optional - otherwise it will be done automatically
# when the garbage collector destroys the node object)
minimal_publisher.destroy_node()
rclpy.shutdown()
if __name__ == '__main__':
main()
When i try to run i am getting following error
ImportError: cannot import name 'Custom' from 'ros_nodes'
This error is not python import error but specific to that python is not able to import custo.msg Am i doing something wrong. Can you guys share a sample project. As of now i am not using CMakeList or package.xml I don't think any of them are required. How do we use ros generate message to get the message imported. What is the right way to do with custom messages in python.