Skip to main content
Version: QTrobot V2

Using ROS blocks

 Level:  Advanced
 Goal:  learn how to program using ROS blocks in QTrobot studio

Why using ROS with blockly?

ROS provides a rich sets of software components and libraries which are accessible via ROS messages or service calls. Other programs (e.g. written in Python or C++) can easily make use of functionality provided by these third-party software components. When using blockly (e.g. QTrobot Studio) to program a robot, we also want to be part of this ecosystem and benefits from its limitless functionalities. QTrobot dedicated blocks already leverage ROS to communicate with the robot via messages and services for playing gestures, speaking or interact with the user via tablet. In fact, hundreds of sophisticated and interactive applications (games) have been developed using these blocks. However, we want to have more generic way to

  • benefits from QTrobot full functionalities such as human gesture or emotion recognition
  • and interact with other custom ROS software written in other programming languages.

Imagine we want to implement a voice interaction application using blockly which needs a sophisticated speech recognition (e.g. Google speech) or Amazon chatbot AI. In this case, we need to interact with the third-party ROS software from our blockly application.

LuxAI blocks for ROS

QTrobot studio offers very flexible and powerful blocks to handle complex ROS messages and interact with other publishers, subscribers and services. These blocks enable developers to extend their application beyond the capabilities of blockly and add limitless functionalities to their programs.

Message object blocks

To provide a generic way to interact with ROS software, we need to handle every type of ROS messages and parameters of services. There are two different blocks in QTrobot studio: one creates generic message object and the other extracts field values from a message object.

The Create object block uses key-value pairs to construct ROS message and service parameters. Key is simply the name of an item in a message or parameter of a service. Value can be simple string, number, list or even another object. Following examples show how to use QTrobot Studio Create object block to represent some ROS messages and service parameters.

create object

To extract specific value from an object, we can use Get element block. It extracts the value of a given key. Let's take a look at the following examples.

get element

As you can see in the above examples, to get the value of an item, we simply need to specify its key in our Get element block.

ROS Publisher, Subscriber and Service blocks

Now that we know how to create ROS messages in Blockly, we can use ROS Publisher and ROS Subscriber blocks to respectively publish and receive ROS messages. Let's see first how we can publish a message using ROS Publisher block via some examples. Imagine we want to publish 'Hello QT!' message to /qt_robot/speech/say topic. We also know that the required message type is std_msgs/String. Therefore, we can use the ROS Publisher block as follows:

block publish


The aim of above example is to show how we can use ROS Publisher block to publish a simple string message. However for QTrobot speech interface, you need to use the dedicated QTrobot Show Says Act block!

Let's see how we can use our ROS Subscriber blocks to read a specific robots' joint position:

block subscribe

The following example shows how we can configure QTrobot to speak slower (e.g. 50% of its normal speed) with using ROS Service call block.

block service