Add your dependencies
For this tutorial, we will need to use the
rclpy
and
irobot_create_msgs
packages. The
rclpy
package allows us to create ROS2 nodes and gives us full access to all the base ROS2
functionality in Python. The
irobot_create_msgs
package gives us access to the custom
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
super()
constructor and passes it the name of our node,
turtlebot4_first_python_node
.
We can now create our node in the
main
function and spin it. Since our node is empty, the node
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()
Summary of Contents for TurtleBot 4 Lite
Page 50: ...Running the Light Ring test...
Page 61: ...Adding Displays in Rviz2...
Page 63: ...Camera image displayed in Rviz2...
Page 82: ...TurtleBot 4 Lite with a NED2 arm...
Page 147: ...Color camera diagnostics...