Lab 08 - Publishing data
ROS 2 - publishing data

Setting up the environment
Before you start working with ROS, call the command in each newly opened terminal:
- after the first compilation (there are
build,install,logdirectories):
source install/setup.bash- before the first compilation:
source /opt/ros/humble/setup.bashIntroduction
In this manual, we will publish data using topics. We will use different robots: turtlesim and simulated robotic arm.
Information about topics in ROS and turtlesim can be
found here.
Publishing in the
context of turtlesim
Run the simulation:
ros2 run turtlesim turtlesim_nodeTest the simulation interactivity by running the
turtle_teleop_key node in a separate terminal:
ros2 run turtlesim turtle_teleop_keyView the running nodes and the connections between them using the
rqt_graph tool.
We can control our RoboTurtle using topics. Use the appropriate command to get a list of them
ros2 topic listand display the current pose of the RoboTurtle:
ros2 topic echo /turtle1/poseUse Ctrl+c to terminate the data subscription.
Wanting to publish data to the /turtle1/cmd_vel topic
and move the RoboTurtle, we should first check the topic type:
ros2 topic type /turtle1/cmd_velThe command returns the type geometry_msgs/msg/Twist. We
can check the type with the following command:
ros2 interface show geometry_msgs/msg/TwistThe Twist structure contains two 3D vectors. The first
vector defines the linear velocity and the second defines the angular
velocity. Our robotic turtle, unlike multi-rotor drones, is a
non-holonomic system. This means that the robot can move
forward/backward (x axis) and rotate around the
z axis. To move the robot, you need to publish data to the
/turtle1/cmd_vel topic by setting the appropriate values
for linear and angular velocity:
ros2 topic pub /turtle1/cmd_vel geometry_msgs/msg/Twist "linear:
x: 0.0
y: 0.0
z: 0.0
angular:
x: 0.0
y: 0.0
z: 0.0"🐢🐢🐢
You don’t need to remember the type and structure of the
message. Use the Tab button and the Linux terminal will
help you with the correct names.
🐢🐢🐢
Change the parameter values so that the robot turtle starts moving. Test different variations.
Manipulating the robotic arm
Let’s start by installing the driver for Universal Robots:
apt install ros-${ROS_DISTRO}-ur-robot-driverAfter installation, we can start the UR3 robot
simulator. This step internally uses Docker software (in case of an
error, make sure you have completed docker
configuration):
ros2 run ur_robot_driver start_ursim.sh -m ur3After starting the simulator, we can run the robot driver in a new terminal window:
ros2 launch ur_robot_driver ur_control.launch.py ur_type:=ur3 robot_ip:=192.168.56.101 launch_rviz:=true🐢🐢🐢
If the rviz program shows a sad, curled up in a
ball and textureless robotic arm try aborting the above script and
running it again. After restarting, wait a few seconds. If restarting
several times doesn’t help, open the robot panel in your browser (the
link displays the command that starts the simulator) and try to move the
robot with the buttons in the panel. Restart the controller with the
visualization (potentially several times).
🐢🐢🐢
The browser-launched robot panel (PolyScope) is a graphical user interface (GUI) for controlling the robot arm, executing robot programs and easily creating new ones. A properly run simulation should allow you to control the robot in PolyScope and observe its movements in RViz.
Tasks
- Read the frequency of the
UR3robot control loop. To do this, display the frequency for the subject/joint_states. - Move the arm in the
UR3panel. Verify thatrvizcorrectly renders the robot’s pose. - In the terminal, check what topics and what types the
UR3controller has created. - Set the arm to the
Homeposition using theUR3panel. - Try to run the sample trajectory using the command:
ros2 launch ur_robot_driver test_scaled_joint_trajectory_controller.launch.py. Does the robot move? - Use the
UR3panel to create a new, empty program. Add theExternal Controlcommand to it (fromStructure->URCaps). Run the program and the example trajectory from the previous task. Does the robot move in the panel andrviz? - Test the above on another
URrobot, for exampleur3e.