Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def pause(self):
def unpause(self):
pass

def reset(self, robot_entity=None):
def reset(self, robot_entities=[]):
pass

def is_running(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def unpause(self):
10000,
)

def reset(self, robot_entity=None):
def reset(self, robot_entities=[]):
node = Node()

node.request(
Expand All @@ -114,7 +114,7 @@ def reset(self, robot_entity=None):
10000,
)

if robot_entity is not None:
for robot_entity in robot_entities:
node.request(
f"/world/default/remove",
Entity(name=robot_entity, type=Entity.MODEL),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def unpause(self):
self.running = True
pass

def reset(self, robot_entity=None):
def reset(self, robot_entities=[]):
# TODO: add reset
pass

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,6 @@ def terminate(self):
bufsize=1024,
universal_newlines=True,
)

def wait_robot_spawn(self, entities):
pass
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@

import logging
from robotics_application_manager import LogManager
from gz.transport13 import Node

from gz.msgs10.empty_pb2 import Empty
from gz.msgs10.scene_pb2 import Scene


class LauncherRobotRos2Api(ILauncher):
Expand All @@ -37,31 +33,14 @@ def run(self, entity, robot_pose, extra_config, callback):
extra_config = ""

if ACCELERATION_ENABLED:
exercise_launch_cmd = f"export VGL_DISPLAY={DRI_PATH}; vglrun ros2 launch {self.launch_file} x:={x} y:={y} z:={z} R:={R} P:={P} Y:={Y} {extra_config}"
exercise_launch_cmd = f"export VGL_DISPLAY={DRI_PATH}; vglrun ros2 launch {self.launch_file} x:={x} y:={y} z:={z} R:={R} P:={P} Y:={Y} entity:={entity} {extra_config}"
else:
exercise_launch_cmd = f"ros2 launch {self.launch_file} x:={x} y:={y} z:={z} R:={R} P:={P} Y:={Y} {extra_config}"
exercise_launch_cmd = f"ros2 launch {self.launch_file} x:={x} y:={y} z:={z} R:={R} P:={P} Y:={Y} entity:={entity} {extra_config}"

exercise_launch_thread = DockerThread(exercise_launch_cmd)
exercise_launch_thread.start()
self.threads.append(exercise_launch_thread)

# Wait until robot entity has spawned
node = Node()
spawned = False
while not spawned:
a = node.request(
f"/world/default/scene/info",
Empty(),
Empty,
Scene,
1000,
)
if a[0]:
for model in a[1].model:
if model.name == entity:
spawned = True
LogManager.logger.info("Robot spawned OK")

def terminate(self):
LogManager.logger.info(f"Terminating robot launcher")
for thread in self.threads[:]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,6 @@ def terminate(self):
thread.terminate()
thread.join()
self.threads.remove(thread)

def wait_robot_spawn(self, entities):
pass
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import os
import sys
from typing import List, Any
import time
import stat

from .launcher_interface import (
ILauncher,
LauncherException,
)
from robotics_application_manager.manager.docker_thread import DockerThread
import subprocess
from robotics_application_manager import LogManager
from gz.transport13 import Node
from gz.msgs10.empty_pb2 import Empty
from gz.msgs10.scene_pb2 import Scene
import logging


class LauncherRos2GzApi(ILauncher):
type: str
module: str
launch_file: str
threads: List[Any] = []

def run(self, callback):
DRI_PATH = self.get_dri_path()
ACCELERATION_ENABLED = self.check_device(DRI_PATH)

logging.getLogger("roslaunch").setLevel(logging.CRITICAL)

xserver_cmd = f"/usr/bin/Xorg -quiet -noreset +extension GLX +extension RANDR +extension RENDER -logfile ./xdummy.log -config ./xorg.conf :0"
xserver_thread = DockerThread(xserver_cmd)
xserver_thread.start()
self.threads.append(xserver_thread)

if ACCELERATION_ENABLED:
exercise_launch_cmd = f"source /.env;export VGL_DISPLAY={DRI_PATH}; vglrun ros2 launch {self.launch_file}"
else:
exercise_launch_cmd = f"source /.env;ros2 launch {self.launch_file}"

exercise_launch_thread = DockerThread(exercise_launch_cmd)
exercise_launch_thread.start()
self.threads.append(exercise_launch_thread)

def terminate(self):
LogManager.logger.info(f"Terminating world launcher")
for thread in self.threads[:]:
if thread.is_alive():
thread.terminate()
thread.join()
self.threads.remove(thread)

def wait_robots_spawn(self, entities):
# Wait until robots entities has spawned
node = Node()
missing_entities = entities
while len(missing_entities) > 0:
resp, output = node.request(
f"/world/default/scene/info",
Empty(),
Empty,
Scene,
1000,
)
if resp:
for model in output.model:
if model.name in missing_entities:
missing_entities.remove(model.name)
LogManager.logger.info(f"Robot ${model.name} spawned OK")
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def pause(self):
def unpause(self):
pass

def reset(self, robot_entity=None):
def reset(self, robot_entities=[]):
pass

def is_running(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"2": [
{
"type": "gz",
"module": "ros2_api",
"module": "ros2_gz_api",
"parameters": [],
"launch_file": [],
}
Expand Down Expand Up @@ -86,6 +86,10 @@ def process_terminated(name, exit_code):
def launch_command(self, configuration):
pass

def wait_robots_spawn(self, entities):
for launcher in self.launchers:
launcher.wait_robots_spawn(entities)


class LauncherSceneException(Exception):
def __init__(self, message):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def pause(self):
def unpause(self):
pass

def reset(self, robot_entity=None):
def reset(self, robot_entities=[]):
pass

def died(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ def unpause(self):
for launcher in self.launchers:
launcher.unpause()

def reset(self, robot_entity=None):
def reset(self, robot_entities=[]):
for launcher in self.launchers:
launcher.reset(robot_entity)
launcher.reset(robot_entities)

def pass_msg(self, data):
for launcher in self.launchers:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def pause(self):
def unpause(self):
pass

def reset(self, robot_entity=None):
def reset(self, robot_entities=[]):
pass

def died(self):
Expand Down
Loading
Loading