Is rclpy and rclpy.node different?

asked 2022-08-25 14:21:38 -0500

choton gravatar image

updated 2022-08-29 04:22:18 -0500

ljaniec gravatar image

I am trying to learn how to use the ROS python client library rclpy to create ROS nodes. The example of a simple publisher node has the code:

import rclpy
from rclpy.node import Node

class Publisher(Node):
   ... # rest of the code

Which works completely fine. I changed it a bit as this:

import rclpy
import rclpy.node

class Publisher(rclpy.node.Node):
   ... # rest of the code

This also work. But as I thought rclpy.node should be inside the rclpy I removed the import of rclpy.node like this:

import rclpy

class Publisher(rclpy.node.Node):
   ... # rest of the code

The code no longer works and shows this error:

AttributeError: module 'rclpy' has no attribute 'node'

Does it mean that rclpy and rclpy.node are completely different library? Why is it so?

The rclpy library has a method called create_node() to create an instance of a ROS node.

When should I use a child class named class Dummy_node(rospy.node.Node): #rest of code to create a node and when should I use rospy.create_node() to create a node? What is the difference?

edit retag flag offensive close merge delete