Moved extra env to it's own function
Some checks failed
Build Docs / build (push) Failing after 26s

This commit is contained in:
Alex Davies 2025-01-06 19:59:22 -04:00
parent b78f6853b8
commit 9ce1c6e403
2 changed files with 23 additions and 13 deletions

View File

@ -271,25 +271,18 @@ class Robot:
async def async_start(self): async def async_start(self):
return await run.io_bound(self.start) return await run.io_bound(self.start)
def extra_env(self):
return {}
def start(self): def start(self):
"""Starts the simulated drone with a given sysid, """Starts the simulated drone with a given sysid,
each drone must have it's own unique ID. each drone must have it's own unique ID.
""" """
instance = self.sysid - 1 with logger.contextualize(drone=str(self)):
sysid = self.sysid
with logger.contextualize(syd_id=sysid):
env = os.environ
with modified_environ( with modified_environ(
SERIAL0_PORT=str(int(env["SERIAL0_PORT"]) + 10 * instance),
MAVROS2_PORT=str(int(env["MAVROS2_PORT"]) + 10 * instance),
MAVROS1_PORT=str(int(env["MAVROS1_PORT"]) + 10 * instance),
FDM_PORT_IN=str(int(env["FDM_PORT_IN"]) + 10 * instance),
GSTREAMER_UDP_PORT=str(int(env["GSTREAMER_UDP_PORT"]) + 10 * instance),
SITL_PORT=str(int(env["SITL_PORT"]) + 10 * instance),
INSTANCE=str(instance),
DRONE_SYS_ID=str(self.sysid),
ROBOT_NAME=self.robot_name, ROBOT_NAME=self.robot_name,
WORLD_NAME="citadel_hill", WORLD_NAME="citadel_hill",
**self.extra_env(),
): ):
self.spawn_gz_model() self.spawn_gz_model()
logger.info("Starting drone stack, this may take some time") logger.info("Starting drone stack, this may take some time")
@ -329,6 +322,9 @@ class Robot:
def delete_gz_model(self): def delete_gz_model(self):
pass pass
def spawn_gz_model(self):
pass
for file in Path("/robots").glob("**/robot_plugins.py"): for file in Path("/robots").glob("**/robot_plugins.py"):
logger.info(f"Loading plugin {file}") logger.info(f"Loading plugin {file}")
spec = importlib.util.spec_from_file_location("robot_plugins", file) spec = importlib.util.spec_from_file_location("robot_plugins", file)
@ -368,6 +364,21 @@ class Spirimu(Robot):
ui.number(value=1, label="SysID", min=1, max=254, ui.number(value=1, label="SysID", min=1, max=254,
).bind_value(newRobotParams, 'sysid') ).bind_value(newRobotParams, 'sysid')
def extra_env(self):
instance = self.sysid - 1
env = os.environ
return dict(
SERIAL0_PORT=str(int(env["SERIAL0_PORT"]) + 10 * instance),
MAVROS2_PORT=str(int(env["MAVROS2_PORT"]) + 10 * instance),
MAVROS1_PORT=str(int(env["MAVROS1_PORT"]) + 10 * instance),
FDM_PORT_IN=str(int(env["FDM_PORT_IN"]) + 10 * instance),
GSTREAMER_UDP_PORT=str(int(env["GSTREAMER_UDP_PORT"]) + 10 * instance),
SITL_PORT=str(int(env["SITL_PORT"]) + 10 * instance),
INSTANCE=str(instance),
DRONE_SYS_ID=str(self.sysid),
)
@logger.catch @logger.catch
def spawn_gz_model(self): def spawn_gz_model(self):

View File

@ -1,4 +1,3 @@
services: services:
whoami: whoami:
image: "traefik/whoami" image: "traefik/whoami"
container_name: "simple-service"