Skip to content

Instantly share code, notes, and snippets.

@ibraEssam
Created September 29, 2020 18:42
Show Gist options
  • Select an option

  • Save ibraEssam/4c6f7d17a0373f82a95c70e9e1f6a19a to your computer and use it in GitHub Desktop.

Select an option

Save ibraEssam/4c6f7d17a0373f82a95c70e9e1f6a19a to your computer and use it in GitHub Desktop.

Revisions

  1. ibraEssam created this gist Sep 29, 2020.
    26 changes: 26 additions & 0 deletions gazebo_ros.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    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