TurtleSim Playground

Series of projects explaining robotics concepts

Hello there!!!
This is the first article in the series of articles based on small robotics projects.

Robotics is a vast field that consists of various domains such as perception, localization, navigation, and control of a robot. Each of these domains has a lot of concepts associated with it. For the successful functioning of a mobile robot, all these domains need to work in unison.

Robot Operating System (ROS) is a framework that is used to implement all these domains on a robot. In this series of articles, I have tried to explain the concepts associated with the above-mentioned domains using ROS and turtlesim.

The following is the content of this article:

  • Target Audience

Target Audience

The target audience for this series is — individuals who are familiar with Ubuntu, ROS and have a prior basic understanding of robotics.

The series is not intended to teach ROS but showcase the application of ROS concepts(like nodes, topics, custom messages, services, actions, etc.) in action to explain robotics concepts such as image processing, transformations, PID controller and many more.

Series Introduction

The series consists of multiple projects. Each project has a particular goal to be accomplished using concepts across multiple domains. These concepts will be demonstrated in action using a 2D simulator called TurtleSim. There are numerous simulators out there such as Gazebo, Ignition, Carla, etc. which can be used to demonstrate the same robotics concepts but I will be using a turtlesim in this series. Two main reasons to choose turtlesim over other simulators are:
1. The ease of implementing the concepts in turtlesim compared to other
2. The primary focus is on robotics concepts and not on the tools used to explain these concepts

In this series, I will be using a turtlesim package which has support across various distributions of ROS(Robot Operating System).

What is a turtlesim?

Turtlesim

  • It is a 2D simulator with 500 x 500 pixels window
  • At an initial look, the simulator looks like a very basic application which cannot be used for the complex robotics concepts

In short, I will try to explain the concepts in action using the turtlesim. These articles will serve as an entry point for the various important concepts used in the Robotics Industry.

Project1: Turtlesim-Sketch

This is a first project in the series. Here, I have sketched contours of an image using turtlesim.

Left: Original Image, Center: Canny edges, Right: Sketch drawn using turtlesim

The above image shows the original image on the left, Canny edges in the centre and the contours drawn using turtlesim. In this project, OpenCV is used to import and find the edges in an image. Using ROS and turtlesim, the contours are extracted from the image and drawn on the simulator.

The stepwise procedure is mentioned below:

Step1: Import an image

  • To import an image and perform image processing operations, OpenCV library is used
# Code to import an image
img = cv2.imread(IMAGE_PATH)
Imported image
  • To find the contours and sketch them on the turtlesim it is important to have an image as the same size as the turtlesim. Hence, it is resized to 500x500 pixels using OpenCV
# Resize the image
img = cv2.resize(img, (500, 500))

Step2: Find edges in the image

  • OpenCV has a built-in function to find edges in an image using various types of edge detectors like Sobel edge detector, Laplacian edge detector, Canny edge detector etc.
# Grayscale Conversion
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
  • The grayscale image contains values between 0–255 for each pixel. To get a binary image, thresholding is done in which the pixels with values below a certain threshold are ignored and only the pixels above a certain threshold are filtered out
Source — OpenCV Python Tutorial
# Canny edge detection
edges = cv2.Canny(img, 100, 200)
  • To select the minimum and maximum threshold values, dynamic reconfigure the package is used. The trackbars are used to adjust the minimum and maximum threshold values

Step3: Find the contours in the image

Using OpenCV built-in functions, we can find the contours from the edges in an image

# Contours
contours, hierarchy = cv2.findContours(edged, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)

Step4: Spawn a turtle at the first point of each contour

Using ROS services, we can spawn turtles at the first point of each contour

Step5: Sketch the contours

  • The contours can be sketched using a sequential mode or a parallel mode
<!-- Draw Sketch of the selected contours -->
<node name="Sketch" pkg="sketch" type="sketcher.py" args="1" output="screen"></node>
  • For the parallel execution, multi-processing module is used. A new process is spawned for each turtle

Step6: Remove the turtles

  • After the sketch is completed, all the turtles are removed from the screen using a ROS service associated in the turtlesim package

The GitHub repository link attached below contains the source code for the projects. The README.md explains the procedure to set up and run the project on your local system. To select sequential or parallel execution, change the arg tag in the sketch.launch file.

Future work

Below are some features that will be added to this project:

  • Create an rqt plugin

GitHub Repository

To know more about the updates regarding this project and the series of projects, please click on the watch button on the GitHub

I am a robotics enthusiast and a life-long learner. Currently, working on autonomous technology for commercial vehicles.