Skip to content

Workshop 2 ‐ Introspecting your robot

Riccardo Polvara edited this page Oct 3, 2023 · 1 revision

The goal of this workshop is to make you familiar with the LIMO robot platform which will be used throughout all remaining workshop sessions. Moreover, you will start using ROS tools for inspecting your robot sensor data and you will write a simple controller for navigating your robot around.

1 Setup

If you are not familiar yet, please refer to Workshop 1 to start your robot and establish a connection to it.

2 Basic ROS operations

  1. Inspect the robot's nodes and topics by using the ros2 node and ros2 topic commands (in a new terminal, no need to source this time). When you type the command without any additional arguments, you should see all available options. Display and compare the format of the following topics /odom, /scan, /tf and /camera/color/image_raw. You might want to also refer to the official node and topic tutorials.

  2. Now, let us use the graphical visualiser RVIZ to look at the robot and its sensor topics. Start by typing rviz2 -d src/limo_description/rviz/model_sensors_real.rviz which uses a pre-defined configuration file, and you should see the interface with a robot model and its sensor data displayed in the robot's touch screen (and your VNC screen too!). To get familiar with the interface, adjust the laser scan visualisation options and see how these affect the output. Try to add new visualisation for sensors not included in the provided configuration (e.g. odometry).

  3. Teleoperation. Leave the RVIZ running. In a new terminal start the keyboard teleoperation node ros2 run teleop_twist_keyboard teleop_twist_keyboard and drive the robot around using the keyboard. Have fun, but pay attention to other robots and your human fellows, though!

  4. Let's now send some basic robot control commands using ROS topics. The robot's speed can be controlled by the /cmd_vel topic. Use the ros2 topic pub functionality to send a single Twist message (linear and angular velocity command) as in this example:

    ros2 topic pub --once /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.5}}"
    

    Now, adjust the linear components of the Twist message and see the resulting trajectory.

  5. Using your knowledge of the topic publishing, issue a series of commands that will drive the robot:

    • in a circle with a radius of 0.5 m;
    • in a 1 m square.

    Try using as few commands as possible.

3 Your first ROS controller

You can control your LIMO robot autonomously by writing a small controller in Python that publishes velocity commands on a dedicated topic. To do so, you can modify the publisher.py script seen during the lecture in order to reflect the command used at point 4. of the Section #2 above.

In order to do so, remember you need to change the topic on which to publish from topic to cmd_vel, the published message from String to geometry_msgs/msg/Twist and correctly populate the message's fields.

import rclpy
from rclpy.node import Node

from std_msgs.msg import String


class MinimalPublisher(Node):

    def __init__(self):
        super().__init__('minimal_publisher')
        self.publisher_ = self.create_publisher(String, 'topic', 10)
        timer_period = 0.5  # seconds
        self.timer = self.create_timer(timer_period, self.timer_callback)
        self.i = 0

    def timer_callback(self):
        msg = String()
        msg.data = 'Hello World: %d' % self.i
        self.publisher_.publish(msg)
        self.get_logger().info('Publishing: "%s"' % msg.data)
        self.i += 1


def main(args=None):
    rclpy.init(args=args)

    minimal_publisher = MinimalPublisher()

    rclpy.spin(minimal_publisher)

    # Destroy the node explicitly
    # (optional - otherwise it will be done automatically
    # when the garbage collector destroys the node object)
    minimal_publisher.destroy_node()
    rclpy.shutdown()


if __name__ == '__main__':
    main()