Skip to content

Instantly share code, notes, and snippets.

@HemaZ
Created September 29, 2020 18:42
Show Gist options
  • Save HemaZ/4c6f7d17a0373f82a95c70e9e1f6a19a to your computer and use it in GitHub Desktop.
Save HemaZ/4c6f7d17a0373f82a95c70e9e1f6a19a to your computer and use it in GitHub Desktop.
import subprocess
import os
import time
class Gazebo:
def on_start(self):
"""This block is used to launch gazebo in noVNC
it builds the ros workspace, source it , then run a launch file
which run gazebo ros and load the appropriate world file.
"""
self.ws_path = self.get_property("ws_path") # Workspace Path
self.pkg_name = self.get_property("pkg_name") # ROS package name
self.launch_file = self.get_property("launch_file") # ROS launch file name
subprocess.Popen("sh /usr/local/bin/start_desktop.sh", shell=True) # Start the desktop
time.sleep(5) # sleep for some seconds until the desktop is started
self.alert("Building the ROS Workspace", "INFO")
subprocess.run(
"cd {} && . /opt/ros/melodic/setup.sh && catkin_make".format(self.ws_path),
shell=True,
) # build the ROS workspace
self.alert("Starting Gazebo", "INFO")
subprocess.Popen(
"vglrun bash -c 'source {}devel/setup.bash && roslaunch {} {}'".format(
os.path.join(self.ws_path, ""), self.pkg_name, self.launch_file
),
shell=True,
) #run the launch file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment