Gazebo | Ignition | Community
Ask Your Question

Control robot in Gazebo

asked 2018-10-08 14:19:08 -0500

VansFannel gravatar image

updated 2018-10-10 10:30:19 -0500

I've just started to learn Gazebo 7.

I have added a Pioneer 2DX robot and I want to control it. But I don't know how.

I have noticed that the robot has the plugin Checking the topics, with gz topic -l, I have found interesting this one:


Maybe I can use it to move the robot but I don't know how to publish to it.

I have tried with rqt, using Robot Steering, but it seems that it publishes to /cmd_vel.

How can I move the robot using the keyboard?

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2018-10-10 08:07:51 -0500

kumpakri gravatar image

updated 2018-10-10 08:09:59 -0500

To move my custom robot, I had to write a plugin into rqt. I don't know if Pioneer 2DX has any solution ready.

You would need to install QT 4 Designer

$ sudo apt-get install python-qt4 qt4-designer

Then you design your own GUI window image description

Pay attention how you name the buttons. You will use the name to connect the buttons with a specific function. My GUI window has 4 buttons


a slider on which I can choose the velocity with which I will accelerate the robot


and a text field


which shows the currently set velocity which will be set to robot if I push the button. You can also write directly into the text field.

image description

I have created a new package just for this feature.

 ├── CMakeLists.txt
 ├── package.xml
 ├── plugin_description.xml
 ├── resource
 │   └── control.ui
 ├── scripts
 │   └──
 └── src
     └── robot_teleop

The widget from the QT 4 Designer is saved in the /resource/control.ui file.

The CMakeLists.txt

cmake_minimum_required(VERSION 2.8.3)

find_package(catkin REQUIRED COMPONENTS

## This macro ensures modules and global scripts declared therein get installed
## See

## Build ##

## Specify additional locations of header files
## Your package locations should be listed before other locations

## Install ##

# all install targets should use catkin DESTINATION variables
# See

## Mark executable scripts (Python etc.) for installation
## in contrast to, you can choose the destination


<library path="src">
    <class name="GUIControllerPlugin"
            A GUI rqt plugin for a manual robot controll.


<?xml version="1.0"?>
<package format="2">
  <description>rqt plugin for manual control of the robot</description>





    <rqt_gui plugin="${prefix}/plugin_description.xml"/>


from distutils.core import setup
from catkin_pkg.python_setup import generate_distutils_setup

setup_args = generate_distutils_setup(
     package_dir={'': 'src'},



#!/usr/bin/env python
import sys

from robot_teleop.rqt_plugin import GUIControllerPlugin
from rqt_gui.main import Main

Starts rqt plugin.

run with command:
$ rqt --standalone robot_teleop

main = Main(filename='robot_teleop')
sys.exit(main.main(sys.argv, standalone='robot_teleop'))

The /src/robot_teleop/__init.py__ is an empty file. I suppose it is located where it is to tell catkin where to find the plugin.

And finaly the plugin /src/robot_teleop/

import rospy
import os
import rospkg

from qt_gui.plugin import Plugin
from python_qt_binding import loadUi
from python_qt_binding.QtWidgets import QWidget, QMessageBox

from std_msgs.msg import Float64

class GUIControllerPlugin ...
edit flag offensive delete link more


Thanks for your answer. So, the only way to control a robot with keyboard in Gazebo is using ROS, isn't it?

VansFannel gravatar imageVansFannel ( 2018-10-10 10:31:00 -0500 )edit

You can define Gazebo plugins for your model. I'm aware that there is a model plugin which will make your robot follow closest object, so there is some possibility to control robot movement within Gazebo itself. I have not come across a Gazebo model plugin, that would allow you to use keyboard or GUI with buttons to control the robot.

kumpakri gravatar imagekumpakri ( 2018-10-11 05:52:57 -0500 )edit

There are also teleop packages available. I didn't try them, but try searching for 'teleop' or 'keyop' or 'keyboard op' or 'keyboard teleop'. Maybe this answer is of interest to you or this answer for gazebo solution only

kumpakri gravatar imagekumpakri ( 2018-10-12 09:31:36 -0500 )edit

hello, thank you for your answer, I am writing a similar controller for my robot following your answer, can you please explain how to execute the plugin after everything has been set up? Thank you

josejaramillo gravatar imagejosejaramillo ( 2019-06-04 10:17:05 -0500 )edit

@josejaramillo if you meant the rqt plugin, then you need to run a command

rqt --standalone robot_teleop

it will launch the rqt process and load the plugin into it. You might need to add certain flag to the command, if your system is unable to see it at first. The terminal will tell you the flag.

kumpakri gravatar imagekumpakri ( 2019-06-06 10:32:05 -0500 )edit

@kumpakri Thank you very much! works like a champ!

josejaramillo gravatar imagejosejaramillo ( 2019-06-19 09:12:00 -0500 )edit

Hi I am trying to do the Plugin out using these but there is some problem with my UI file. Does it possible that you can post the Ui folder/ code for me? It will help a lot thanks!!

potatoo gravatar imagepotatoo ( 2021-01-19 01:36:05 -0500 )edit

Question Tools

1 follower


Asked: 2018-10-08 14:19:08 -0500

Seen: 2,253 times

Last updated: Oct 10 '18