Skip to content

Instantly share code, notes, and snippets.

@a-mhamdi
Last active January 14, 2024 15:59
Show Gist options
  • Save a-mhamdi/5793a17dcdf784da8b01e1847f6f7d1d to your computer and use it in GitHub Desktop.
Save a-mhamdi/5793a17dcdf784da8b01e1847f6f7d1d to your computer and use it in GitHub Desktop.
Turtlesim in ROS2: Humble Hawksbill

Getting started w/ ROS2

We begin by checking which shell we are using on Linux:

which $SHELL

Sourcing our ROS installation.

source /opt/ros/humble/setup.bash

Run the turtlesim_node executable from the turtlesim package.

ros2 run turtlesim turtlesim_node

The below command returns the list of current active topics

ros2 topic list -t

Details on a particular type of message can be retrieved through:

ros2 interface show geometry_msgs/msg/Twist

We can publish data on a topic as follows:

ros2 topic pub --once /turtle1/cmd_vel geometry_msgs/msg/Twist "{linear: {x: 1.}}"

--once means we publish only one message and exit.

ros2 topic pub -r 1 /turtle1/cmd_vel geometry_msgs/msg/Twist "{linear: {x: 1.,y: 0.,z:0.}, angular:{x: 0.,y: 0.,z: .7}}"

-r 1 means we keep publishing our message in a steady stream at 1 Hz. We can see the data being published on the /turtle1/cmd_vel by running:

ros2 topic echo /turtle1/cmd_vel

We can also use the keyboard to move around turtle1

ros2 run teleop_twist_keyboard teleop_twist_keyboard --ros-args --remap cmd_vel:=/turtle1/cmd_vel

The executable turtle_teleop_key does the same previous thing and avoids all the hassle of remapping

ros2 run turtlesim turtle_teleop_key

This utility allows us to display the graph of data flow between our running nodes;

rqt_graph
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment