From 1dcd944638540a9e1e65814c3a9baf3d4b2292f6 Mon Sep 17 00:00:00 2001 From: ReyDoran Date: Fri, 22 Dec 2023 14:37:07 +0100 Subject: [PATCH] Generic exexrcise.py path --- manager/manager/manager.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/manager/manager/manager.py b/manager/manager/manager.py index 7c6734d..816f576 100644 --- a/manager/manager/manager.py +++ b/manager/manager/manager.py @@ -81,6 +81,7 @@ def __init__(self, host: str, port: int): self.running = True self.gui_server = None self.linter = Lint() + self.ros_version = self.get_ros_version() # Creates workspace directories worlds_dir = "/workspace/worlds" @@ -93,6 +94,13 @@ def __init__(self, host: str, port: int): if not os.path.isdir(binaries_dir): os.makedirs(binaries_dir) + def get_ros_version(self): + version = subprocess.check_output(['bash', '-c', 'echo $ROS_DISTRO']) + if "noetic" in str(version): + return "ros1_noetic" + else: + return "ros2_humble" + def state_change(self, event): LogManager.logger.info(f"State changed to {self.state}") if self.consumer is not None: @@ -180,8 +188,7 @@ def on_run_application(self, event): f = open("/workspace/code/academy.py", "w") f.write(code) f.close() - - self.application_process = subprocess.Popen(["python3", "/RoboticsAcademy/exercises/static/exercises/autoparking_newmanager/python_template/ros1_noetic/exercise.py"], stdout=sys.stdout, stderr=subprocess.STDOUT, + self.application_process = subprocess.Popen(["python3", f"/RoboticsAcademy/exercises/static/exercises/{exercise_id}/python_template/{self.ros_version}/exercise.py"], stdout=sys.stdout, stderr=subprocess.STDOUT, bufsize=1024, universal_newlines=True) print("\n\n\n PROCESS APPLICATION STARTED: " + str(self.application_process) + "\n\n\n") rosservice.call_service("/gazebo/unpause_physics", []) @@ -236,9 +243,9 @@ def on_pause(self, msg): self.__code_loaded = False def on_resume(self, msg): + rosservice.call_service("/gazebo/unpause_physics", []) proc = psutil.Process(self.application_process.pid) proc.resume() - rosservice.call_service("/gazebo/unpause_physics", []) def start(self): """