Categories
Gazebo ROS

How to Move a Gazebo Model from Terminal

Gazebo is a great simulator for robot development and has become a must-have for roboticists, robot developers, and robotics researchers. Sometime, you want to move a model or an object from the terminal so you don’t have to type the position values every time. How can you do that?

Prerequisite

This tutorial assumes you have successfully installed ROS which should also install Gazebo for you. For the version, ROS Melodic is the current release, and Gazebo 9 is bundled with ROS Melodic. To install ROS, refer to the official guide here: https://wiki.ros.org/ROS/Installation. You should also already have Ubuntu 20.04 running on your computer.

What is Gazebo?

Gazebo is a robot simulator. It allows you to test if your algorithm works, design of your first ever robot prototype. It also allows you to run regression testing to avoid bugs to reappear, or train your AI Deep Learning algorithm by simulating realistic worlds with all the sensors. Gazebo provides the ability to model robot environments reliably and effectively in diverse indoor and outdoor settings to suit your needs.

Find the model name from Gazebo Window

To move an object in a Gazebo world, i.e., scene, we will need to find the name of the model.

First, select the object in the scene. In the following screenshot, we selected a table.

A table model is selected in Gazebo.

Do you know?

You can also choose the model from the tree in the “World” tab located on the top of the left sidebar. Actually, the models in the sub-tree “models” are the names of the models in the Gazebo world.

Once the table is selected, you will see a two-column view: Property and Value. This sidebar shows you all the worlds currently in the scene and allows you to change the parameters of the models, such as light and pose. Here we are specifically interested in the pose of a model. A pose include position and orientation.

The first row shows you the same of the model. In the example shown in the screenshot, the name is table.

Get the current pose of the model

Get current pose from Gazebo GUI

Once you know the name of your model, click on the arrow on the left of the pose property.

The pose property of a table model is expanded in Gazebo.

Now you will see 6 properties of a pose. The first three, x, y, and z, belong to the position of the pose. The last thee, roll, pitch, yaw, belong to the orientation of the pose.

If you haven’t moved the model to a position you want it to be, click on the move icon to the right of the mouse courser, and move it to the desired position.

Get current pose from rosservice

Alternatively, you can run the following command to get the current pose of a given mode, e.g., table. Replace with table with your desired model name.

When Gazebo starts, it will advertise a few services that allow us to control Gazebo from the command line or in our ROS program. Here we called /gazebo/get_model_state and passed model_name table in order to get the state of table, which includes its pose.

rosservice call /gazebo/get_model_state "model_name: 'table'" 

You then will see output like this:

header: 
  seq: 1
  stamp: 
    secs: 1504
    nsecs: 567000000
  frame_id: ''
pose: 
  position: 
    x: 1.15193
    y: -0.256452
    z: 0.0
  orientation: 
    x: 0.0
    y: 0.0
    z: 0.0
    w: 1.0
twist: 
  linear: 
    x: 0.0
    y: 0.0
    z: 0.0
  angular: 
    x: 0.0
    y: 0.0
    z: 0.0
success: True
status_message: "GetModelState: got properties"

Do you know?

This is actually a YAML response of the message gazebo_msgs/GetModelState. The way to know this is using roservice info: rosservice info /gazebo/get_model_state.

This is actually a YAML response of the message gazebo_msgs/GetModelState. The way to know this is using roservice info: rosservice info /gazebo/get_model_state.

The useful information here is the x, y, z of the position property.

Move the model

Now you have the position values where you want the model to move to.

Next, open a new terminal window or tab. Make sure you have sourced the setup.bash file. If you haven’t, run source ~/WORKSPACE/install/setup.bash. Mare sure you replace WORKSPACE with your own catkin workspace directory. For example, my catkin workspace is located at ~/tiago_public_ws/, so I run source ~/tiago_public_ws/install/setup.bash.

Type rostopic pub -1 /gazebo/set_model_state gazebo_msgs/ModelState (with a space in the end) and press tab. You will see the ModelState message response is autocompleted, which is good to know. However, it is not easy to edit. You can either copy it to an editor or use the following HTML form input to modify it. For the latter, now press Ctrl+C and change the model_name and the position values in the following textbox:

Once you have your onw model name and position values, paste it to your terminal.

Congrats. Now you know how to move an object in Gazebo! If you frequently use a position of an object, you can also add the command to you project’s README.md file to easily reference it.

In A Nutshell

Time Needed : 3 minutes

  1. Open Gazebo

    You can run gazebo to open it or use a ros launch file from the robot companygazebo typed in Ubuntu's gnome-terminal

  2. Find the model name

    You can find the model name in the sidebar after selecting the model.image 10

  3. Get the current pose of the model

    You can either get the current pose from the left side bar after selecting the mode name, or run rosservice call /gazebo/get_model_state "model_name: 'REPLACE ME'".image 11

  4. Move the model

    You can move the model by publishing to gazebo/set_model_state gazebo_msgs.Screenshot of Gazebo, a popular robot simulator

Tools
  • Terminal

Like

By VarHowto Editor

Welcome to VarHowto!

Leave a Reply

Your email address will not be published. Required fields are marked *