Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 107 d #111

Open
wants to merge 2 commits into
base: issue-107
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions manager/manager/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,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"
Expand All @@ -90,6 +91,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:
Expand Down Expand Up @@ -172,8 +180,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", application_file], 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)
rosservice.call_service("/gazebo/unpause_physics", [])
else:
Expand Down Expand Up @@ -224,9 +231,9 @@ def on_pause(self, msg):
rosservice.call_service('/gazebo/pause_physics', [])

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):
"""
Expand Down