Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Learning Robotics using Python

You're reading from  Learning Robotics using Python

Product type Book
Published in May 2015
Publisher Packt
ISBN-13 9781783287536
Pages 330 pages
Edition 1st Edition
Languages
Concepts

Table of Contents (19) Chapters

Learning Robotics Using Python
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Introduction to Robotics Mechanical Design of a Service Robot Working with Robot Simulation Using ROS and Gazebo Designing ChefBot Hardware Working with Robotic Actuators and Wheel Encoders Working with Robotic Sensors Programming Vision Sensors Using Python and ROS Working with Speech Recognition and Synthesis Using Python and ROS Applying Artificial Intelligence to ChefBot Using Python Integration of ChefBot Hardware and Interfacing it into ROS, Using Python Designing a GUI for a Robot Using Qt and Python The Calibration and Testing of ChefBot Index

Chapter 11. Designing a GUI for a Robot Using Qt and Python

In the last chapter, we discussed the integration of robotic hardware components and software packages for performing autonomous navigation. After the integration, the next step is to build a GUI to control the robot. We are building a GUI that can act as a trigger for the underlying ROS commands. Instead of running all the commands on the terminal, the user can work with the GUI buttons. The GUI we are going to design is for a typical hotel room with nine tables. The user can set a table position in the map of the hotel room and command the robot to go to a particular table to deliver food. After delivering the food, the user can command the robot to go to its home position.

Some of the most popular GUI frameworks currently available are Qt (http://qt.digia.com) and GTK+ (http://www.gtk.org/), Qt and GTK+ are open source, cross-platform user interface toolkits and development platforms. These two software frameworks are widely used...

Installing Qt on Ubuntu 14.04.2 LTS


Qt is a cross-platform application framework that is widely used to develop application software with a GUI interface as well as command line tools. Qt is available on almost all operating systems, like Windows, Mac OS X, Android, and so on. The main programming language used for developing Qt applications is C++ but there are bindings available for languages such as Python, Ruby, Java, and so on. Let's take a look at how to install Qt SDK on Ubuntu 14.04.2. We will install Qt from the Advance Packaging Tool (APT) in Ubuntu. The APT already comes with the Ubuntu installation. So for installing Qt/Qt SDK, we can simply use the following command, which will install Qt SDK and its required dependencies from the Ubuntu package repository. We can install Qt version 4 using the following command:

$ sudo apt-get install qt-sdk

This command will install the entire Qt SDK and its libraries required for our project. The packages available on Ubuntu repositories...

Working with Python bindings of Qt


Let's see how we can interface Python and Qt. In general, there are two modules available in Python for connecting to the Qt user interface. The two most popular frameworks are:

  • PyQt

  • PySide

PyQt

PyQt is one of the popular most Python bindings for Qt cross-platform. PyQt is developed and maintained by Riverbank Computing Limited. It provides binding for Qt version 4 and Qt version 5, and comes with GPL (version 2 or 3) along with a commercial license. PyQt is available for Qt version 4 and 5, called PyQt4 and PyQt5, respectively. These two modules are compatible with Python versions 2 and 3. PyQt contains more than 620 classes that cover user interface, XML, network communication, web, and so on.

PyQt is available on Windows, Linux, and Mac OS X. It is a prerequisite to install Qt SDK and Python in order to install PyQt. The binaries for Windows and Mac OS X are available on the following link:

http://www.riverbankcomputing.com/software/pyqt/download

We can see...

Working with PyQt and PySide


After installing the PyQt and PySide packages, we can see how to write a Hello World GUI using PyQt and PySide. The main difference between PyQt and PySide is only in some commands; most of the steps are the same. Let's see how to make a Qt GUI and convert it into Python code.

Introducing Qt Designer

Qt Designer is the tool for designing and inserting control into Qt GUI. Qt GUI is basically an XML file that contains the information of its components and controls. The first step to work with GUI is its designing. The Qt Designer tool provides various options to make excellent GUIs.

Start Qt Designer by entering the command designer-qt4 in the terminal. The following image shows what you will be able to see after running this command:

The preceding image shows the Qt designer interface. Select the Widget option from the New Form window and click on the Create button. This will create an empty widget; we can drag various GUI controls from the left-hand side of Qt 4...

Working with ChefBot's control GUI


After completing the Hello World application in PyQt, next we can discuss a GUI for controlling ChefBot. The main use of building a GUI is to create an easier way to control the robot, for example, if the robot is deployed in a hotel to serve food, the person who controls this robot need not have knowledge about the complex commands to start and stop this robot; so building a GUI for ChefBot can reduce the complexity and make it easier for the user. We are planning to build a GUI using PyQt, ROS and Python interface. The ChefBot ROS package is available on GitHub on the following link:

https://github.com/qboticslabs/Chefbot_ROS_pkg.git

If you haven't cloned the code yet, you can do it now using following command:

$ git clone https://github.com/qboticslabs/Chefbot_ROS_pkg.git

The GUI code named robot_gui.py is placed in the scripts folder, which is inside the chefbot_bringup package.

The following screenshot shows the GUI that we have designed for ChefBot...

Questions


  1. What are the popular UI toolkits available on the Linux platform?

  2. What are the differences between PyQt and PySide Qt bindings?

  3. How do you convert a Qt UI file into Python script?

  4. What are Qt signals and slots?

  5. What is rqt and what are its main applications?

Summary


In this chapter, we discussed creating a GUI for ChefBot that can be used by an ordinary user who doesn't have any idea about the internal working of a robot. We used Python binding of Qt called PyQt to create this GUI. Before we go to the main GUI design, we saw a Hello World application to get an easier understanding of PyQt. The UI design was done using the Qt Designer tool and the UI file was converted into its equivalent Python script using Python UI compiler. After designing the main GUI in Qt Designer, we converted the UI file into Python script and inserted the necessary slots in the generated script. The ChefBot GUI can start the robot, select a table number, and command the robot to get into that position. The position of each table is acquired from the generated map we hardcoded the positions in this Python script for testing. When a table is selected, we set a goal position on the map, and when we click on the Go button, the robot will move into the goal position. The...

lock icon The rest of the chapter is locked
You have been reading a chapter from
Learning Robotics using Python
Published in: May 2015 Publisher: Packt ISBN-13: 9781783287536
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}