Add your dependencies
For this tutorial, we will need to use the
package allows us to create ROS2 nodes and gives us full access to all the base ROS2
functionality in Python. The
messages used by the Create® 3 for reading the button presses and controlling the lightring.
In package.xml, add these lines under <buildtool_depend>ament_cmake</buildtool_depend>:
<depend>rclpy</depend>
<depend>irobot_create_msgs</depend>
In your
.py
file, import these packages:
from irobot_create_msgs.msg import InterfaceButtons, LightringLeds
import rclpy
from rclpy.node import Node
from rclpy.qos import qos_profile_sensor_data
Create a class
Now that the dependencies are set, we can create a class that inherits from the rclpy.Node
class. We will call this class TurtleBot4FirstNode.
class TurtleBot4FirstNode(Node):
def __init__(self):
super().__init__('turtlebot4_first_python_node')
Notice that our class calls the
turtlebot4_first_python_node.
We can now create our node in the
will be created but it won't do anything.
def main(args=None):
rclpy.init(args=args)
node = TurtleBot4FirstNode()
rclpy.spin(node)
node.destroy_node()
rclpy.shutdown()
rclpy
and
irobot_create_msgs
super()
constructor and passes it the name of our node,
main
function and spin it. Since our node is empty, the node
irobot_create_msgs
package gives us access to the custom
packages. The
rclpy
Need help?
Do you have a question about the Turtlebot4 and is the answer not in the manual?
Questions and answers