-
Notifications
You must be signed in to change notification settings - Fork 7
Using ROS from the command line [2425]
ROS 2 relies on the notion of "workspaces" as the locations where the code and configurations are stored. In ROS 2 you can have multiple workspaces active concurrently. ROS workspaces are created and built using the colcon
tools that are callable from a terminal.
For this module, you will not learn how to create and build workspaces because we want you to focus more on the theoretical aspects of the fundamentals of robotics. You are going to use ROS 2 as a tool to implement the theory.
Anytime we will ask you to modify a source code, a configuration or description file in ROS, for this and future workshops, you will need to re-build the workspace. To facilitate this task, we have created a utility function in your ROS environment that does that automatically for you.
To build, you simply need to open a terminal and run:
rebuild
You will see the output of building the workspace, and possibly some warning or errors.
❗ If you see warnings, it is usually fine; if you see errors, ask for help as you have done something wrong and the workspace has not been built correctly.
To launch an executable, a node usually, the template to follow is:
ros2 run <package_name> <executable_name>
ros2 run turtlesim turtlesim_node
If you open the VNC window, you will see that the turtlesim window has appeared.
ros2 run turtlesim turtle_teleop_key
Following the instructions you will be able to teleoperate the turtlebot.
ros2 node list
This will show the two nodes that you have launched before. If you go back to one of the previous terminals, kill a node (Ctrl+c followed by Enter), and list the nodes again you will see that the list has been updated.
ros2 node info <node_name>
This will list all the topics it subscribes to and publishes and all the server/client services it has.
turtlesim_node
and turtle_teleop_key
running, open a new terminal and launch:
rqt_graph
It shows you the nodes currently running, the topics that connects them and the topics directions.
ros2 topic list
Topics are channels of communication in which messages are exchanged. To see the stream of messages run:
ros2 topic echo <topic_name>
ros2 topic echo /turtle1/cmd_vel
.
ros2 topic pub /turtle1/cmd_vel geometry_msgs/msg/Twist "{linear: {x: 2.0, y: 0.0, z: 0.0}, angular: {x: 0.0, y: 0.0, z: 1.8}}"
Note that here we also need to specify the type of the message, and we have to fill in the arguments of the message. The message itself is always a dictionary and from the terminal is provided with its string representation. The above command is launched in a loop, but you can add the argument --once
to publish only one time.
ros2 interface show geometry_msgs/msg/Twist
ros2 launch mecharm slider_control.launch.py
From the VNC window, you should see a 6 Degree Of Freedom (DOF) simulated robot with the controls to move each individual joint:
Now, using the ROS terminal functionalities explored above:
▶️ 🧑💻 discover what topic is the slider window publishing to in order to move the robot;▶️ 🧑💻 check what is the message definition;▶️ 🧑💻 try to move the robot from a terminal command.
Parts for the workshops are extracted, edited from and/or inspired by the following sources.
- Official ROS humble tutorials: https://docs.ros.org/en/humble/Tutorials.html
- Elephant Robotics docs: https://docs.elephantrobotics.com/docs/gitbook-en/