Support for sub-apps

This commit is contained in:
Alex Davies 2024-06-18 12:03:59 -03:00
parent 716161abeb
commit 33f103a5f0
2 changed files with 28 additions and 7 deletions

View File

@ -25,10 +25,10 @@ RUN make px4_sitl_default
RUN pip3 install typer-slim loguru sh
RUN apt-get install --yes virtualbox-guest-dkms virtualbox-guest-utils spice-vdagent qemu-guest-agent
RUN apt-get install --yes docker-compose-v2 firefox
# RUN apt-get install --yes virtualbox-guest-dkms virtualbox-guest-utils spice-vdagent qemu-guest-agent
RUN apt-get install --yes docker-compose-v2
#Install our desktop environment last
RUN apt-get install --yes --no-install-recommends lxqt sddm
# RUN apt-get install --yes --no-install-recommends lxqt sddm firefox
COPY ./skel/ /opt/spiri-sdk/user-home-skeleton/
RUN cp -r /opt/spiri-sdk/user-home-skeleton/* /etc/skel/

View File

@ -1,6 +1,11 @@
#!/bin/env python3
import typer, os, sys, contextlib
import typer
import os
import sys
import contextlib
import pathlib
import time
import functools
from loguru import logger
import sh
import atexit
@ -45,6 +50,9 @@ class outputLogger:
elif message.startswith("ERROR"):
message = message.lstrip("ERROR")
logger.error(message)
elif message.startswith("DEBUG"):
message = message.lstrip("DEBUG")
logger.debug(message)
else:
logger.info(message)
@ -102,7 +110,7 @@ def wait_for_gazebo(timeout=60, interval=1):
@app.command()
def start(sys_id: int = 1):
def start(sys_id: int = 1, extra_apps: list[pathlib.Path] = []):
"""Starts the simulated drone with a given sys_id,
each drone must have it's own unique ID.
"""
@ -131,14 +139,27 @@ def start(sys_id: int = 1):
_bg=True,
)
processes.append(docker_stack)
for extra_app in extra_apps:
logger.info(f"Starting app {extra_app}, this may take some time")
app_name = extra_app.stem
app_stack = sh.docker.compose(
"--project-name",
f"simulated_robot_{sys_id}_{app_name}",
"up",
_out=outputLogger(app_name, sys_id),
_err=sys.stderr,
_bg=True,
)
processes.append(app_stack)
@app.command()
def start_group(count: int = typer.Argument(min=1, max=10)):
@functools.wraps(start)
def start_group(count: int = typer.Argument(min=1, max=10), *args, **kwargs):
"""Start a group of robots"""
for i in range(count):
logger.info(f"start robot {i}")
start(sys_id=i + 1)
start(sys_id=i + 1, *args, **kwargs)
if i == 0:
wait_for_gazebo()