Skip to content

RoboC00p/robot-back

Repository files navigation

Robocoop Backend

WebSocket backend for the Robocoop medical assistance robot. Bridges the robot hardware (via ROS/rosbridge) to the dashboard frontend.

What it does

  • Connects to the robot via rosbridge (WebSocket → ROS topics)
  • Reads battery voltage from /battery, converts it to a percentage
  • Broadcasts real-time robot state to all connected dashboard clients
  • Records audit events (robot connected/disconnected, battery low, emergency stop)
  • Supports mock mode for frontend development without a physical robot

Architecture overview

Dashboard (frontend)
      │  WebSocket ws://host:8765
      ▼
  app/server.py              — lifecycle, signal handling
  app/websocket_handler.py   — client connections, message routing
  app/backend_context.py     — dependency container (single init point)
      │
      ├── modules/robot/     — state store + telemetry pipeline
      ├── modules/audit/     — event logging + history
      └── adapters/          — robot communication layer
              │
              ├── mock_adapter.py        — no-op, always connected (dev)
              └── rosbridge_adapter.py   — real robot via rosbridge WebSocket
                      │
                      └── rosbridge_client.py  — pure WebSocket transport
                                │
                           rosbridge server (ws://robot:9090)
                                │
                              ROS topics (/battery, ...)

Project structure

src/
  robocoop_backend/
    robocoop_backend/
      app/          — server, websocket handler, contracts, DI context
      adapters/     — robot adapter implementations + rosbridge client
      modules/
        robot/      — RobotState, RobotStateStore, TelemetryService
        audit/      — AuditEvent, AuditService, sinks (console, file)
      utils/        — Config loader (.env + YAML)
  robocoop_bringup/
    config/         — YAML config files per environment
    launch/         — ROS2 launch files (future use)
.env                — local environment variables (not committed)
.env.example        — template for .env

Setup

Requirements: Python 3.11+

git clone <repo>
cd robot-back

python -m venv .venv # or python3 
source .venv/bin/activate        # macOS/Linux
# .venv\Scripts\activate         # Windows

pip install -e src/robocoop_backend

Copy the environment file and configure it:

cp .env.example .env

.env defaults to ROBOCOOP_ENV=mock — no robot needed to start.

Running

# Mock mode (no robot required)
ROBOCOOP_ENV=mock python -m robocoop_backend.app.server

# Real robot (rosbridge must be running on the robot)
ROBOCOOP_ENV=real python -m robocoop_backend.app.server

Or use the launch script:

bash run_backend.sh mock
bash run_backend.sh real

Server starts on ws://0.0.0.0:8765.

Quick connection test

Connect to ws://localhost:8765 with any WebSocket client (Postman, WebSocket King, wscat) and send:

{"type": "ping"}

Expected response:

{"type": "pong"}

On connection, the server automatically pushes the current robot state and the last 50 audit events. See app/contracts.py for the full message reference.

Connexion to the robot jetson

  ssh jetson@**.**.***.** # follow instructions and write [ Yes ] or press enter
  jetson@**.**.***.**'s password : < password_value >
  docker ps ## get into this container name : < m3pro >
  docker exec -it m3pro /bon/bash ## for write command ( display topic list and whatever )

Environment variables

Variable Default Description
ROBOCOOP_ENV mock Which config to load: mock or real
ROBOCOOP_CONFIG_DIR auto-detected Path to the YAML config directory

Configuration

YAML config lives in src/robocoop_bringup/config/. Two files are loaded on startup:

  1. common.params.yaml — shared across all environments
  2. {ROBOCOOP_ENV}.params.yaml — environment-specific overrides

See src/robocoop_bringup/config/README.md for details.

Testing

# Install test dependencies
pip install -e "src/robocoop_backend[test]"

# Run all tests (unit + integration)
pytest -m "not real" -v

# Unit tests only
pytest -m unit -v

# Integration tests only
pytest -m integration -v

# Real rosbridge tests (requires a live rosbridge server)
ROSBRIDGE_URL=ws://localhost:9090 pytest -m real -v

Tests live in src/robocoop_backend/robocoop_backend/tests/. CI runs automatically on push and pull requests via GitHub Actions (.github/workflows/ci.yml).

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors