|
| 1 | +""" |
| 2 | +argos.__main__ -- CLI entry point for the ARGOS inspection system. |
| 3 | +
|
| 4 | +Usage: |
| 5 | + python -m argos --config config.yaml --mode simulation |
| 6 | +""" |
| 7 | + |
| 8 | +from __future__ import annotations |
| 9 | + |
| 10 | +import argparse |
| 11 | +import asyncio |
| 12 | +import logging |
| 13 | +import sys |
| 14 | +from pathlib import Path |
| 15 | + |
| 16 | +import yaml |
| 17 | + |
| 18 | +from argos.config import ArgosSettings |
| 19 | +from argos.inspector import InspectionEngine |
| 20 | + |
| 21 | +logger = logging.getLogger("argos") |
| 22 | + |
| 23 | + |
| 24 | +def parse_args(argv: list[str] | None = None) -> argparse.Namespace: |
| 25 | + """Parse command-line arguments.""" |
| 26 | + parser = argparse.ArgumentParser( |
| 27 | + prog="argos", |
| 28 | + description="ARGOS -- Autonomous Robot for General Onboard Surveillance", |
| 29 | + ) |
| 30 | + parser.add_argument( |
| 31 | + "--config", type=Path, default=Path("config.yaml"), |
| 32 | + help="Path to YAML configuration file (default: config.yaml)", |
| 33 | + ) |
| 34 | + parser.add_argument( |
| 35 | + "--mode", choices=["simulation", "live", "replay"], |
| 36 | + default="simulation", |
| 37 | + help="Inspection mode: simulation (fake frames), live (camera), replay (video file)", |
| 38 | + ) |
| 39 | + parser.add_argument( |
| 40 | + "--replay-file", type=Path, default=None, |
| 41 | + help="Path to video file for replay mode", |
| 42 | + ) |
| 43 | + parser.add_argument( |
| 44 | + "--interval", type=float, default=5.0, |
| 45 | + help="Seconds between inspection cycles (default: 5.0)", |
| 46 | + ) |
| 47 | + parser.add_argument( |
| 48 | + "--log-level", default="INFO", |
| 49 | + choices=["DEBUG", "INFO", "WARNING", "ERROR"], |
| 50 | + help="Logging verbosity (default: INFO)", |
| 51 | + ) |
| 52 | + return parser.parse_args(argv) |
| 53 | + |
| 54 | + |
| 55 | +def load_config(path: Path) -> ArgosSettings: |
| 56 | + """Load settings from a YAML file, falling back to env/defaults.""" |
| 57 | + if path.exists(): |
| 58 | + with open(path) as fh: |
| 59 | + raw = yaml.safe_load(fh) or {} |
| 60 | + logger.info("Loaded config from %s", path) |
| 61 | + return ArgosSettings(**raw) |
| 62 | + logger.warning("Config file %s not found, using defaults", path) |
| 63 | + return ArgosSettings() |
| 64 | + |
| 65 | + |
| 66 | +async def run(args: argparse.Namespace) -> None: |
| 67 | + """Initialise and run the inspection engine.""" |
| 68 | + settings = load_config(args.config) |
| 69 | + engine = InspectionEngine(settings=settings) |
| 70 | + |
| 71 | + if args.mode == "simulation": |
| 72 | + logger.info("Starting in SIMULATION mode (interval=%.1fs)", args.interval) |
| 73 | + elif args.mode == "live": |
| 74 | + logger.info("Starting in LIVE mode with camera device") |
| 75 | + elif args.mode == "replay": |
| 76 | + if not args.replay_file or not args.replay_file.exists(): |
| 77 | + logger.error("Replay mode requires --replay-file with a valid path") |
| 78 | + sys.exit(1) |
| 79 | + logger.info("Starting in REPLAY mode from %s", args.replay_file) |
| 80 | + |
| 81 | + await engine.run_continuous( |
| 82 | + gps_lat=45.4315, gps_lon=12.3456, |
| 83 | + interval_s=args.interval, |
| 84 | + ) |
| 85 | + |
| 86 | + |
| 87 | +def main(argv: list[str] | None = None) -> None: |
| 88 | + """Entry point for ``python -m argos``.""" |
| 89 | + args = parse_args(argv) |
| 90 | + logging.basicConfig( |
| 91 | + level=getattr(logging, args.log_level), |
| 92 | + format="%(asctime)s [%(levelname)s] %(name)s: %(message)s", |
| 93 | + ) |
| 94 | + try: |
| 95 | + asyncio.run(run(args)) |
| 96 | + except KeyboardInterrupt: |
| 97 | + logger.info("Interrupted by user") |
| 98 | + |
| 99 | + |
| 100 | +if __name__ == "__main__": |
| 101 | + main() |
0 commit comments