Robotics StackExchange | Archived questions

how can you check that gazebo gui is fully started?

How can I check (programmatically) if the gazebo GUI is fully loaded and the scene is visible? I use ROS2 Foxy and Gazebo Classic at the moment

Asked by vane on 2023-04-28 06:03:39 UTC

Comments

Answers

To programmatically check if the Gazebo GUI is fully loaded and the scene is visible, you can use the gzclient tool to check if the Gazebo client process is running. Here's an example Python code that you can use:

import subprocess
import time

def is_gazebo_ready():
    ps_output = subprocess.check_output(['ps', 'aux'])
    ps_output_str = ps_output.decode('utf-8')
    if 'gzclient' in ps_output_str:
        return True
    else:
        return False

if __name__ == '__main__':
    while not is_gazebo_ready():
        time.sleep(1)
    print('Gazebo is ready')

This code uses the subprocess module to execute the ps command and get the list of running processes. It then checks if the gzclient process is running by searching for it in the process list. If the gzclient process is found, it means that the Gazebo GUI is fully loaded and the scene is visible. Otherwise, the code waits for one second and checks again.

You can customize the sleep duration (currently set to 1 second) to fit your specific use case.

Asked by hunterlineage1 on 2023-04-28 16:40:22 UTC

Comments