Compare commits

..

2 Commits

Author SHA1 Message Date
e0e864ea13 Thêm hướng dẫn vào tài liệu
Some checks failed
Test / test (push) Has been cancelled
2026-06-24 17:09:58 +07:00
4b702756bb Đổi tên phần mềm từ lidar_manager_app thành robot_app 2026-06-24 16:31:28 +07:00
13 changed files with 428 additions and 453 deletions

View File

@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.16) cmake_minimum_required(VERSION 3.16)
project(lidar_manager_web LANGUAGES CXX) project(robot_app LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_STANDARD_REQUIRED ON)
@@ -29,9 +29,9 @@ endif()
find_package(SQLite3 REQUIRED) find_package(SQLite3 REQUIRED)
add_executable(lidar_manager_web add_executable(robot_app
src/main.cpp src/main.cpp
src/app/lidar_manager_app.cpp src/app/robot_app.cpp
src/util/file_util.cpp src/util/file_util.cpp
src/util/string_util.cpp src/util/string_util.cpp
src/util/id_util.cpp src/util/id_util.cpp
@@ -75,18 +75,18 @@ add_executable(lidar_manager_web
src/server/api_dashboard_routes.cpp src/server/api_dashboard_routes.cpp
) )
target_link_libraries(lidar_manager_web PRIVATE Threads::Threads SQLite::SQLite3) target_link_libraries(robot_app PRIVATE Threads::Threads SQLite::SQLite3)
target_include_directories(lidar_manager_web PRIVATE target_include_directories(robot_app PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/src" "${CMAKE_CURRENT_SOURCE_DIR}/src"
) )
target_include_directories(lidar_manager_web SYSTEM PRIVATE target_include_directories(robot_app SYSTEM PRIVATE
"${cpp_httplib_SOURCE_DIR}" "${cpp_httplib_SOURCE_DIR}"
"${nlohmann_json_SOURCE_DIR}/single_include" "${nlohmann_json_SOURCE_DIR}/single_include"
) )
target_compile_definitions(lidar_manager_web PRIVATE target_compile_definitions(robot_app PRIVATE
_DEFAULT_SOURCE _DEFAULT_SOURCE
) )
@@ -112,24 +112,24 @@ if(BUILD_TESTING)
src/validation/sensor_validator.cpp src/validation/sensor_validator.cpp
) )
add_executable(lidar_manager_tests add_executable(robot_app_tests
tests/test_mission_enqueue.cpp tests/test_mission_enqueue.cpp
tests/test_mission_store.cpp tests/test_mission_store.cpp
tests/test_sensor_validator.cpp tests/test_sensor_validator.cpp
${LM_TEST_LIB_SOURCES} ${LM_TEST_LIB_SOURCES}
) )
target_include_directories(lidar_manager_tests PRIVATE target_include_directories(robot_app_tests PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/src" "${CMAKE_CURRENT_SOURCE_DIR}/src"
) )
target_include_directories(lidar_manager_tests SYSTEM PRIVATE target_include_directories(robot_app_tests SYSTEM PRIVATE
"${nlohmann_json_SOURCE_DIR}/single_include" "${nlohmann_json_SOURCE_DIR}/single_include"
) )
target_compile_definitions(lidar_manager_tests PRIVATE target_compile_definitions(robot_app_tests PRIVATE
TEST_FIXTURE_DIR="${CMAKE_CURRENT_SOURCE_DIR}/tests/fixtures/data" TEST_FIXTURE_DIR="${CMAKE_CURRENT_SOURCE_DIR}/tests/fixtures/data"
) )
target_link_libraries(lidar_manager_tests PRIVATE GTest::gtest_main SQLite::SQLite3) target_link_libraries(robot_app_tests PRIVATE GTest::gtest_main SQLite::SQLite3)
include(GoogleTest) include(GoogleTest)
gtest_discover_tests(lidar_manager_tests WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) gtest_discover_tests(robot_app_tests WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
add_test(NAME unit COMMAND lidar_manager_tests) add_test(NAME unit COMMAND robot_app_tests)
endif() endif()

View File

@@ -30,12 +30,12 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
WORKDIR /app WORKDIR /app
COPY --from=build /src/build/lidar_manager_web /app/lidar_manager_web COPY --from=build /src/build/robot_app /app/robot_app
COPY www ./www COPY www ./www
RUN mkdir -p data/maps data/sounds data/recordings RUN mkdir -p data/maps data/sounds data/recordings
EXPOSE 8080 EXPOSE 8080
ENTRYPOINT ["/app/lidar_manager_web"] ENTRYPOINT ["/app/robot_app"]
CMD ["8080", "/app/www", "/app/data/RBS.db"] CMD ["8080", "/app/www", "/app/data/RBS.db"]

221
README.md
View File

@@ -1,60 +1,174 @@
# Robot App Web (RBS) # Robot App Web (RBS)
Chức năng: Giao diện web quản lý robot: mission, map, dashboard, user, Modbus/REST tích hợp.
Tài liệu UI/UX và trạng thái tính năng: [`docs/Reference_guide.md`](docs/Reference_guide.md).
**Backend:** C++ executable `robot_app` (`src/app/robot_app.cpp`, class `RobotApp`).
**Frontend:** static `www/` (vanilla JS).
Chức năng chính:
- Đăng ký danh sách cảm biến LiDAR (tên, ip, port) - Đăng ký danh sách cảm biến LiDAR (tên, ip, port)
- Đăng ký IMU (tên, frame_id, topic, nguồn) và pose trên robot - Đăng ký IMU (tên, frame_id, topic, nguồn) và pose trên robot
- Kéo thả icon LiDAR/IMU trên canvas để set vị trí (robot frame) - Kéo thả icon LiDAR/IMU trên canvas để set vị trí (robot frame)
- Nhiều layout — mỗi layout lưu profile trong SQLite (`layout_profiles`); catalog trong document `state` - Nhiều layout — mỗi layout lưu profile trong SQLite (`layout_profiles`); catalog trong document `state`
- Database SQLite: `data/RBS.db` (WAL mode). Thư mục media: `data/maps/`, `data/sounds/`, `data/recordings/` - Mission editor, map editor, dashboard, transitions, paths, path guides, I/O modules
## Dữ liệu
| Thành phần | Vị trí |
|------------|--------|
| Database chính | `data/RBS.db` (SQLite, WAL) — auth, users, missions, queue, maps, dashboards, … |
| Media map | `data/maps/{map_id}/` |
| Media sound | `data/sounds/{sound_id}/` |
| Recordings (stub) | `data/recordings/` |
| Layout catalog | document `state` trong DB + `data/state.json` (legacy) |
Lần khởi động đầu, server **import** các file JSON cũ (nếu có) vào SQLite: `auth.json`, `missions.json`, `mission_queue.json`, `robot_runtime.json`.
**Site import/export** (Setup → Maps): bundle JSON gồm `maps`, `io_modules`, `transitions`, `paths``POST /api/sites/{site_id}/import`.
## Build ## Build
```bash ```bash
cd /home/robotics/RD/RBS # Ubuntu/Debian: sudo apt install libsqlite3-dev cmake build-essential
# Ubuntu/Debian: sudo apt install libsqlite3-dev
cmake -S . -B build cmake -S . -B build
cmake --build build -j cmake --build build -j
``` ```
Binary: `build/robot_app`
## Run ## Run
Chạy mặc định port 8080, phục vụ static từ `www/`, dữ liệu SQLite tại `data/RBS.db`: Chạy mặc định port 8080, phục vụ static từ `www/`, database tại `data/RBS.db`:
```bash ```bash
./build/lidar_manager_web ./build/robot_app
``` ```
Hoặc chỉ định: Hoặc chỉ định đủ tham số:
```bash ```bash
./build/lidar_manager_web 8080 ./www ./data/RBS.db ./build/robot_app <port> <www_dir> <db_path>
# ví dụ:
./build/robot_app 8080 ./www ./data/RBS.db
``` ```
Mở trình duyệt: `http://localhost:8080/` Mở trình duyệt: `http://localhost:8080/`
### API Maps & Sounds (SQLite) Tắt auth cho dev/test:
```bash
LM_AUTH_DISABLED=1 ./build/robot_app
```
## Docker (giới hạn 2 CPU, 4 GB RAM)
Mô phỏng cấu hình controller tối thiểu (Dual-Core, 4 GB) trên máy dev:
| Mục | Giá trị |
|-----|---------|
| Compose service | `robot-app` |
| Image | `robot-app:RBS` |
| Container | `robot-app-limited` |
| Port | `8080` |
```bash
./scripts/lm.sh docker up
# hoặc:
sudo docker compose up --build -d
```
Sau khi đổi tên service/container, nếu port 8080 bị chiếm bởi container cũ:
```bash
sudo docker compose down --remove-orphans
sudo docker compose up --build -d
```
Kiểm tra / dừng:
```bash
./scripts/lm.sh docker stats
./scripts/lm.sh docker down
```
Dữ liệu lưu trên host qua volume `./data:/app/data`.
```bash
./scripts/lm.sh docker shell # shell trong container
./scripts/lm.sh docker htop
```
## Biến môi trường
| Biến | Mặc định | Mô tả |
|------|----------|--------|
| `LM_AUTH_DISABLED` | — | `1` = tắt xác thực API (dev/test) |
| `LM_URL` | `http://127.0.0.1:8080` | URL khi test container |
| `LM_CONTAINER` | `robot-app-limited` | Tên container Docker |
| `LM_TEST_PORT` | `18080` | Port server tạm khi `test run` |
## API (tóm tắt)
### Maps, sounds, dashboards
| Method | Endpoint | Mô tả | | Method | Endpoint | Mô tả |
|--------|----------|-------| |--------|----------|-------|
| GET | `/api/maps` | Danh sách map | | GET/POST | `/api/maps` | Danh sách / tạo map |
| POST | `/api/maps` | Tạo map (JSON metadata) |
| GET/PUT/DELETE | `/api/maps/{id}` | CRUD map | | GET/PUT/DELETE | `/api/maps/{id}` | CRUD map |
| GET/POST | `/api/maps/{id}/image` | Tải/xem ảnh map (file trong `data/maps/{id}/`) | | GET/POST | `/api/maps/{id}/image` | Ảnh map (`data/maps/{id}/`) |
| GET | `/api/sounds` | Danh sách sound | | GET/POST | `/api/sounds` | Danh sách / tạo sound |
| POST | `/api/sounds` | Tạo sound |
| GET/PUT/DELETE | `/api/sounds/{id}` | CRUD sound | | GET/PUT/DELETE | `/api/sounds/{id}` | CRUD sound |
| GET/POST | `/api/sounds/{id}/file` | Tải/upload file âm thanh | | GET/POST | `/api/sounds/{id}/file` | Upload/tải file âm thanh |
| POST | `/api/sounds/{id}/play` | Phát sound trên robot (volume 0100) | | POST | `/api/sounds/{id}/play` | Phát trên robot (volume 0100) |
| GET/POST | `/api/transitions` | Danh sách / tạo transition (`?site_id=`) | | GET/PUT | `/api/dashboards` | Dashboard server-side |
| GET/PUT/DELETE | `/api/transitions/{id}` | CRUD transition |
| GET/PUT | `/api/dashboards` | Dashboard (server-side, thay localStorage) |
| GET | `/api/recordings` | Stub — trả về `[]` (Phase sau) |
**Transitions (MiR §4.4):** Setup → Transitions — cấu hình chuyển map (from/to, start/goal position, mission có `switch_map`). Khi mission chạy `move_to_position` hoặc `adjust_localization` tới position trên map khác `active_map_id`, runner tự chèn: di chuyển tới start position → chạy transition mission → chuyển map → di chuyển tới goal position → tiếp tục bước gốc. Position trong mission editor lấy từ zones `type: position` trên từng map. ### Missions & queue
### Đăng nhập (Signing in — MiR §2.1) | Method | Endpoint | Mô tả |
|--------|----------|-------|
| GET/PUT | `/api/missions` | Danh sách / lưu missions |
| GET | `/api/mission_queue` | Queue + runner status |
| POST | `/api/mission_queue` | Enqueue mission |
| DELETE | `/api/mission_queue` | Xóa toàn bộ queue |
| DELETE | `/api/mission_queue/{id}` | Xóa một entry |
| PUT | `/api/mission_queue/reorder` | Sắp xếp lại queue |
| POST | `/api/mission_queue/pause` | Tạm dừng runner |
| POST | `/api/mission_queue/continue` | Tiếp tục runner |
| POST | `/api/mission_queue/cancel` | Hủy mission đang chạy |
Trang web **bắt buộc đăng nhập**. Hai tab: tên/mật khẩu hoặc **Mã PIN** (keypad 4 số). Tài khoản mặc định (trong `data/RBS.db`, seed lần đầu): REST tương thích: `GET/POST/DELETE /api/v2.0.0/mission_queue`
### Transitions, paths, I/O
| Method | Endpoint | Mô tả |
|--------|----------|-------|
| GET/POST | `/api/transitions` | CRUD transition (`?site_id=`) |
| GET/DELETE | `/api/paths`, `/api/paths/{id}` | Path cache (auto-create; xóa thủ công) |
| GET/POST/PUT/DELETE | `/api/path_guides` | Path guides |
| GET/POST/PUT/DELETE | `/api/io_modules` | I/O modules (Bluetooth / WISE) |
| POST | `/api/io_modules/test` | Kiểm tra kết nối TCP |
**Transitions:** Setup → Transitions — cấu hình chuyển map (from/to map, start/goal position, mission liên kết). Khi mission chạy `move_to_position` hoặc `adjust_localization` tới position trên map khác `active_map_id`, runner tự chèn: đi tới start position → chạy transition mission → chuyển map → đi tới goal position → tiếp tục bước gốc.
### Robot & tích hợp
| Method | Endpoint | Mô tả |
|--------|----------|-------|
| GET | `/api/robot/status` | Trạng thái robot (pin, pose, mission strip) |
| POST | `/api/robot/start`, `/api/robot/pause` | Start / pause |
| POST | `/api/robot/errors/reset` | Xóa lỗi |
| POST | `/api/robot/active_map` | Đặt map đang hoạt động |
| GET/POST/DELETE | `/api/triggers` | Modbus mission triggers (coil 10012000) |
| GET/POST/DELETE | `/api/fleet/schedules` | Lịch fleet (stub scheduler) |
| GET | `/api/recordings` | Stub — trả về `[]` |
Modbus TCP server: port **5502** (mission triggers + action coils 16).
### Đăng nhập
Trang web **bắt buộc đăng nhập** (password hoặc PIN 4 số). Tài khoản mặc định:
| User | Password | Nhóm | | User | Password | Nhóm |
|------|----------|------| |------|----------|------|
@@ -62,60 +176,15 @@ Trang web **bắt buộc đăng nhập**. Hai tab: tên/mật khẩu hoặc **M
| User | user | Users (dashboard write, còn lại read) | | User | user | Users (dashboard write, còn lại read) |
| Distributor | distributor | Distributors (full quyền) | | Distributor | distributor | Distributors (full quyền) |
PIN 4 chữ số chỉ dùng được với user thuộc nhóm **Users** sau khi admin gán PIN (`PUT /api/users/:id`). PIN chỉ dùng với nhóm **Users** sau khi admin gán (`PUT /api/users/:id`).
Tắt auth cho dev/test: `LM_AUTH_DISABLED=1 ./build/lidar_manager_web …` Chi tiết auth & permissions: [`docs/Reference_guide.md` §2](docs/Reference_guide.md#2-đăng-nhập-và-phân-quyền).
Tài liệu đầy đủ: [`docs/Reference_guide.md` §2.1](docs/Reference_guide.md#21-signing-in).
## Docker (giới hạn 2 CPU, 4 GB RAM)
Mô phỏng cấu hình controller tối thiểu SICK (Dual-Core, 4 GB) trên máy dev:
```bash
cd /home/robotics/RD/RBS
./scripts/lm.sh docker up
# hoặc: sudo docker compose up --build -d
```
Kiểm tra giới hạn:
```bash
./scripts/lm.sh docker stats
```
Dừng:
```bash
./scripts/lm.sh docker down
```
Dữ liệu layout vẫn lưu tại `data/` trên host (volume mount).
Kiểm tra tài nguyên trong container:
```bash
# Vào shell container
./scripts/lm.sh docker shell
# Trong container, thử:
htop # CPU/RAM (q để thoát)
free -h # RAM
nproc # số CPU nhìn thấy
ps aux # process
cat /proc/meminfo | head
```
```bash
./scripts/lm.sh docker htop
./scripts/lm.sh docker stats
```
## Test tự động ## Test tự động
Chạy toàn bộ: unit C++ (GTest), API smoke (`curl`), pytest integration. Chạy toàn bộ: unit C++ (GTest), API smoke (`curl`), pytest integration.
```bash ```bash
cd /home/robotics/RD/RBS
chmod +x scripts/lm.sh scripts/test/*.sh chmod +x scripts/lm.sh scripts/test/*.sh
./scripts/lm.sh test run ./scripts/lm.sh test run
``` ```
@@ -125,24 +194,24 @@ Chỉ unit test C++:
```bash ```bash
cmake -S . -B build -DBUILD_TESTING=ON cmake -S . -B build -DBUILD_TESTING=ON
cmake --build build -j cmake --build build -j
ctest --test-dir build --output-on-failure ./build/robot_app_tests
# hoặc: ctest --test-dir build --output-on-failure
``` ```
Chỉ API smoke (server đang chạy, dùng fixture `tests/fixtures/data/`): Chỉ API smoke (server đang chạy, fixture `tests/fixtures/data/`):
```bash ```bash
./build/lidar_manager_web 18080 www tests/fixtures/data/state.json & ./build/robot_app 18080 www tests/fixtures/data/state.json &
./scripts/lm.sh test smoke http://127.0.0.1:18080 ./scripts/lm.sh test smoke http://127.0.0.1:18080
``` ```
Fixture mission id mặc định: `testmission00001` (`tests/fixtures/data/missions.json`). Fixture mission id mặc định: `testmission00001` (`tests/fixtures/data/missions.json`).
Benchmark hiệu năng trong container (cần `docker compose up -d`): Benchmark trong container (cần `docker compose up -d`):
```bash ```bash
./scripts/lm.sh docker bench ./scripts/lm.sh docker bench
# hoặc chỉ HTTP: ./scripts/lm.sh bench http # hoặc: ./scripts/lm.sh bench http
``` ```
CI: GitHub Actions workflow `.github/workflows/test.yml`. CI: GitHub Actions workflow `.github/workflows/test.yml`.

View File

@@ -1,10 +1,10 @@
name: rbs name: rbs
services: services:
lidar-manager: robot-app:
build: . build: .
image: lidar-manager-web:RBS image: robot-app:RBS
container_name: lidar-manager-limited container_name: robot-app-limited
ports: ports:
- "8080:8080" - "8080:8080"
volumes: volumes:

View File

@@ -1,154 +1,84 @@
# MiR Robot Reference Guide — Tóm tắt # RBS Web Interface — Tài liệu tham chiếu
> Nguồn: `docs/Reference guide.pdf` > Ứng dụng `robot_app` — giao diện web quản lý robot, mission, map và tích hợp.
> **MiR robot Reference guide (en), rev. 1.9, 03/2019**
> Mô tả giao diện web trên robot MiR (không phải User Guide phần cứng MiR250). **Chú thích trạng thái:** ✅ đầy đủ · 🔶 một phần · ⏳ placeholder · ❌ chưa có
--- ---
## 1. Giới thiệu ## 1. Giới thiệu
Tài liệu dành cho **administrator** và người cấu hình hệ thống: tạo mission, map, user, dashboard, Modbus trigger. Tài liệu mô tả giao diện web RBS cho **administrator**, kỹ sư cấu hình và operator: đăng nhập, dashboard, mission, map, user, Modbus/REST tích hợp.
Tài liệu liên quan khác (Distributor site / Support Portal): **Stack:** frontend `www/` (vanilla JS), backend C++ (`src/server/`, `src/mission/`, …), dữ liệu SQLite `data/RBS.db` + `data/auth.json`.
| Loại | Nội dung |
|------|----------|
| Quick Start | Vận hành nhanh (in trong hộp robot) |
| User Guide | Vận hành & bảo trì robot (MiR250 có bản riêng) |
| Commissioning / Risk Analysis | Đưa robot vào sản xuất an toàn |
| REST API Reference | Robot, Hook, Fleet |
| Network & WiFi Guide | Yêu cầu mạng |
- Fleet (scheduler, robot groups): tài liệu riêng *MiR Fleet Reference Guide*.
--- ---
## 2. MiR robot interface (ch. 2) ## 2. Đăng nhập và phân quyền
Giao diện web trên robot: **responsive** (PC, tablet, portrait/landscape). Truy cập qua WiFi AP robot hoặc LAN (`http://<robot_ip>` / `mir.com`). ### 2.1 Luồng đăng nhập
### 2.1 Signing in
> **RBS:** tính năng đã triển khai — xem [RBS — Signing in](#RBS--signing-in-đã-triển-khai).
#### Luồng truy cập (MiR)
```
Thiết bị → kết nối mạng robot → trình duyệt → trang Sign in → shell app (Dashboard / Setup / …)
```
Toàn bộ UI bị chặn cho đến khi đăng nhập thành công.
#### Hai cách đăng nhập
| Cách | Đối tượng | Giao diện |
|------|-----------|-----------|
| **Username + password** | Distributor, Administrator, kỹ sư | Tab form username + password |
| **PIN 4 chữ số** | Operator sàn (quyền thấp) | Tab PIN; **không có PIN mặc định** |
#### Ba cấp truy cập mặc định
| Role | Username | Password mặc định | Vai trò |
|------|----------|-------------------|---------|
| **Distributor** | `Distributor` | Liên hệ MiR Support | Đại lý; full quyền; quản lý quyền Admin/User |
| **Administrator** | `Admin` | `admin` | Kỹ sư khách hàng; full read/write |
| **User** | `User` | `user` | Operator hàng ngày |
> *MiR250 Quick Start:* đổi password mặc định ngay; mỗi người một tài khoản; chỉ operator cấp thấp dùng PIN; Admin/Distributor dùng password mạnh.
#### Tách credentials và permissions
| Lớp | Gắn với | Nội dung |
|-----|---------|----------|
| **Credentials** | **User** (cá nhân) | username, password, PIN |
| **Permissions** | **User group** (nhóm) | module nào được xem / sửa |
Mỗi user thuộc **một** user group. Mục không có quyền write: **vẫn hiển thị nhưng không chỉnh sửa được**.
#### User groups mặc định (mục 4.6)
| Nhóm | Quyền mặc định |
|------|----------------|
| **Distributors** | Full R/W; quản lý quyền Administrators và Users |
| **Administrators** | Full R/W; quản lý quyền Users |
| **Users** | Xem toàn UI; tạo/sửa **dashboard** |
Admin có thể tạo thêm user group (ví dụ `Operators`) và gán quyền từng module (Maps, Missions, System…).
#### Sau khi đăng nhập
- **Góc phải trên:** tên user → đổi password, Sign out.
- Admin tạo user tại **Setup → Users**; nhóm tại **Setup → User groups** (tạo group **trước** user).
- Dashboard gán quyền theo group qua nút **Permissions** khi tạo/sửa dashboard.
- Widget **Log-out button** trên dashboard (hữu ích trên tablet).
#### Bảo mật (Quick Start + SW mới)
- MiR **không** ép password policy phức tạp trên robot đơn lẻ.
- Không nên nhiều người dùng chung một account.
- SW mới (~2023): **auto sign-out** theo user group; MiR Fleet hỗ trợ **OAuth 2.0 / OpenID Connect**.
#### RBS — Signing in (đã triển khai)
Tính năng đăng nhập theo MiR §2.1 đã tích hợp vào `lidar_manager_web`. Toàn bộ API (trừ health/login/logout) yêu cầu session; UI bị chặn cho đến khi đăng nhập thành công.
##### Luồng người dùng
``` ```
Trình duyệt → / (trang Sign in) Trình duyệt → / (trang Sign in)
→ POST /api/auth/login (password hoặc PIN) → POST /api/auth/login (password hoặc PIN)
→ Cookie lm_session + shell app (Dashboard / Cấu hình / Missions / Tích hợp) → Cookie lm_session + shell app (Dashboard / Setup / Monitoring / System / Help)
→ Menu user (góc phải): đổi mật khẩu, đăng xuất → Menu user (góc phải): đổi mật khẩu, đăng xuất
``` ```
- Static (`www/`) phục vụ công khai để tải trang login. - Toàn bộ API (trừ health/login/logout) yêu cầu session; UI bị chặn cho đến khi đăng nhập.
- `auth.js` gọi `GET /api/auth/me` khi mở trang; session hợp lệ thì vào app ngay. - `auth.js` gọi `GET /api/auth/me` khi mở trang; session hợp lệ thì vào app ngay.
- `app.js`, `missions.js`, `dashboard.js`, `integrations.js` chỉ khởi động sau sự kiện `lm:auth-ready`. - Các module JS (`app.js`, `missions.js`, `dashboard.js`, …) khởi động sau sự kiện `lm:auth-ready`.
- API mission queue và các endpoint khác **không** được gọi trước khi đăng nhập.
##### Giao diện web (MiR-style) ### 2.2 Giao diện Sign in
| Thành phần | Mô tả | | Thành phần | Mô tả |
|------------|--------| |------------|--------|
| Nền | Xanh `#3d6cb3`, full-screen | | Tab **Tên đăng nhập và mật khẩu** | Form username + password |
| Header | Tên robot (`RobotApp`) + «Chọn cách đăng nhập» + 2 tab | | Tab **Mã PIN** | Keypad 4 chữ số; tự đăng nhập khi đủ 4 số |
| Tab **Tên đăng nhập và mật khẩu** | 2 cột: hướng dẫn trái, form phải; nút xanh «Đăng nhập» | | Sau login | Menu user topbar; ẩn/vô hiệu hóa theo quyền read-only |
| Tab **Mã PIN** | Trái: hướng dẫn + 4 ô vuông (•); phải: keypad 19, 0, ✕ |
| PIN | Tự đăng nhập khi đủ 4 số; hỗ trợ bàn phím vật lý |
| Sau login | Menu user topbar; ẩn/vô hiệu menu theo quyền read-only |
File: `www/index.html`, `www/auth.js`, `www/style.css`. File: `www/index.html`, `www/auth.js`, `www/style.css`.
##### Tài khoản mặc định ### 2.3 Tài khoản mặc định
Tự tạo lần đầu trong `data/auth.json` (cùng thư mục `state.json`): Tự tạo lần đầu trong `data/auth.json`:
| Username | Password | User group | Ghi chú | | Username | Password | User group |
|----------|----------|------------|---------| |----------|----------|------------|
| `Admin` | `admin` | Administrators | Full quyền | | `Admin` | `admin` | Administrators |
| `User` | `user` | Users | Dashboard write; phần còn lại read | | `User` | `user` | Users |
| `Distributor` | `distributor` | Distributors | Full quyền | | `Distributor` | `distributor` | Distributors |
- Username đăng nhập **không phân biệt hoa thường** (`admin` = `Admin`). - Username **không phân biệt hoa thường**.
- **PIN:** không có mã mặc định (giống MiR). Chỉ nhóm **Users** (`allow_pin: true`); admin gán qua API. - **PIN:** không có mã mặc định; chỉ nhóm có `allow_pin: true`; admin gán qua API/UI.
##### User groups và permissions ### 2.4 User groups và permissions
Credentials **user**; quyền **group**. Module: `dashboard`, `config`, `missions`, `integrations`, `users` — giá trị `none` | `read` | `write`. Credentials gắn **user**; quyền gắn **group**. Mỗi user thuộc một nhóm.
| Group | PIN | dashboard | config | missions | integrations | users | **7 resource:** `dashboard`, `config`, `maps`, `missions`, `sounds`, `integrations`, `users` — giá trị `none` | `read` | `write`.
|-------|-----|-----------|--------|----------|--------------|-------|
| Distributors | Không | write | write | write | write | write |
| Administrators | Không | write | write | write | write | write |
| Users | Sau khi gán | write | read | read | read | none |
| Group | Menu UI | | Group | PIN | dashboard | config | maps | missions | sounds | integrations | users |
|-------|---------| |-------|-----|-----------|--------|------|----------|--------|--------------|-------|
| Users | Dashboard + xem Cấu hình/Missions/Tích hợp (nút ghi read-only) | | Distributors | Không | write | write | write | write | write | write | write |
| Administrators / Distributors | Toàn bộ menu; quản lý user qua API | | Administrators | Không | write | write | write | write | write | write | write |
| Users | Sau khi gán | write | read | read | read | read | read | none |
##### Session và middleware Trang không có quyền write: **vẫn hiển thị**, nút tạo/sửa bị vô hiệu (`body.auth-readonly-*`).
**Quyền trang** (`www/auth.js`):
| Trang | Resource |
|-------|----------|
| `config` | Chỉ nhóm **Distributors** |
| `maps`, `transitions`, `paths`, `path-guides` | `maps` |
| `missions` | `missions` |
| `sounds` | `sounds` |
| `io-modules`, `integrations` | `integrations` |
| `users`, `user-groups` | `users` |
| `monitoring`, `help` | Mọi user đã đăng nhập |
### 2.5 Session và API auth
| Cơ chế | Chi tiết | | Cơ chế | Chi tiết |
|--------|----------| |--------|----------|
@@ -159,257 +89,232 @@ Credentials → **user**; quyền → **group**. Module: `dashboard`, `config`,
| Public | `GET /api/health`, `POST /api/auth/login`, `POST /api/auth/logout`, `OPTIONS` | | Public | `GET /api/health`, `POST /api/auth/login`, `POST /api/auth/logout`, `OPTIONS` |
| Dev | `LM_AUTH_DISABLED=1` tắt auth | | Dev | `LM_AUTH_DISABLED=1` tắt auth |
**API → module** (kiểm tra read/write): **API → module:**
| Module | Prefix | | Module | Prefix |
|--------|--------| |--------|--------|
| config | `/api/lidars`, `/api/imus`, `/api/layouts`, `/api/state`, … | | config | `/api/lidars`, `/api/imus`, `/api/layouts`, `/api/state`, … |
| maps | `/api/maps`, `/api/sites`, `/api/paths`, `/api/path_guides`, `/api/transitions` |
| missions | `/api/missions`, `/api/mission_queue` | | missions | `/api/missions`, `/api/mission_queue` |
| integrations | `/api/triggers`, `/api/schedules`, `/api/fleet`, `/api/modbus`, `/api/v2.0.0/` | | sounds | `/api/sounds` |
| integrations | `/api/triggers`, `/api/schedules`, `/api/fleet`, `/api/modbus`, `/api/io_modules`, `/api/v2.0.0/` |
| users | `/api/users`, `/api/user_groups` | | users | `/api/users`, `/api/user_groups` |
##### REST API **Endpoint auth chính:**
| Method | Endpoint | Auth | Mô tả | | Method | Endpoint | Mô tả |
|--------|----------|------|--------| |--------|----------|--------|
| POST | `/api/auth/login` | Public | `{ username, password }` hoặc `{ pin }` | | POST | `/api/auth/login` | `{ username, password }` hoặc `{ pin }` |
| POST | `/api/auth/logout` | Public | Xóa session + cookie | | POST | `/api/auth/logout` | Xóa session |
| GET | `/api/auth/me` | Session | User, group, permissions | | GET | `/api/auth/me` | User, group, permissions |
| PUT | `/api/auth/password` | Session | Đổi mật khẩu | | PUT | `/api/auth/password` | Đổi mật khẩu |
| GET | `/api/user_groups` | users read | Danh sách nhóm | | GET/POST/PUT/DELETE | `/api/users`, `/api/user_groups` | CRUD user và nhóm |
| GET | `/api/users` | users read | Danh sách user |
| POST | `/api/users` | users write | Tạo user |
| PUT | `/api/users/:id` | users write | Sửa user / gán PIN (`pin: null` = xóa) |
| DELETE | `/api/users/:id` | users write | Xóa user |
**Ví dụ login + gán PIN** **Mã nguồn:** `src/auth/auth_service.cpp`, `www/auth.js`, `www/users.js`, `www/user-groups.js`.
```bash **Chưa có:** auto sign-out theo nhóm, OAuth.
curl -c c.txt -X POST http://localhost:8080/api/auth/login \
-H 'Content-Type: application/json' \
-d '{"username":"Admin","password":"admin"}'
curl -b c.txt -X PUT http://localhost:8080/api/users/user_operator \
-H 'Content-Type: application/json' \
-d '{"pin":"1234"}'
```
##### Lưu trữ và mã nguồn
| Thành phần | Vị trí |
|------------|--------|
| Dữ liệu | `data/auth.json` — groups, users (hash + salt) |
| Backend | `src/auth/auth_service.cpp`, `src/util/crypto_util.cpp`, `src/app/lidar_manager_app.cpp` |
| Frontend | `www/auth.js`, `www/index.html`, `www/style.css` |
| Test | `scripts/test/smoke.sh`, `tests/test_api_integration.py` |
Hash: SHA-256 + salt (`sha256(salt:password)` / `sha256(salt:pin:pin)`).
##### Kiểm thử và vận hành
```bash
./scripts/lm.sh test run # smoke tự login Admin; pytest test_auth_*
```
- Docker: `www/` copy lúc build → `docker compose up --build -d` sau sửa UI.
- Hard refresh (`Ctrl+Shift+R`) nếu cache JS/CSS.
##### So sánh MiR ↔ RBS
| MiR §2.1 | RBS |
|----------|-------|
| Sign in bắt buộc | Có |
| Tab password \| PIN + keypad | Có |
| 3 role mặc định | Admin / User / Distributor |
| PIN không mặc định | Có — admin gán API |
| User menu, đổi password, sign out | Có |
| Credentials / permissions tách biệt | Có |
| Setup → Users (UI) | Chưa — chỉ API |
| Auto sign-out / OAuth Fleet | Chưa |
### 2.2 Navigating the MiR robot interface
- Menu chính → **tối đa một submenu** rồi vào section (ví dụ Setup → Sounds).
- **Top bar:** trạng thái robot, nút start/pause.
### 2.3 Getting started
Thiết lập user trước vận hành:
1. **Users** (Setup → Users)
2. **User groups** (Setup → User groups)
3. **Dashboards** theo vai trò (Dashboards → Create)
Thiết lập hệ thống: map → chỉnh map (positions, zones) → missions.
--- ---
## 3. Mục lục đầy đủ ## 3. Điều hướng và topbar
### 1. About this document ### 3.1 Shell 3 cột
- 1.1. Where to find more information
- 1.2. Document history
### 2. MiR robot interface Rail trái → flyout submenu → content (`www/nav.js`).
- 2.1. Signing in
- 2.2. Navigating the MiR robot interface
- 2.3. Getting started
### 3. Dashboards | Module | Flyout (section → page) | File JS | Trạng thái |
- **3.1. Dashboards** — Create / designer / edit / delete |--------|-------------------------|---------|------------|
- **3.2. Widgets** | **Dashboards** | Danh sách động → `dashboard` | `dashboard.js` | ✅ |
- 3.2.1. **Maps** — Locked map, Map | **Setup** | missions, maps, sounds, transitions, users, user-groups, io-modules, paths, path-guides, build-robot → `config` | `*.js` | 🔶 |
- 3.2.2. **Missions** — Mission button, Pause/Continue, Mission queue, Mission action log, Mission group | **Monitoring** | monitoring-log → `monitoring` | — | ⏳ |
- 3.2.3. **PLC registers** — PLC button/display | **System** | integrations → `integrations` | `integrations.js` | 🔶 |
- 3.2.4. **I/O module** — Connect, configuration, status | **Help** | help-api → `help` | — | ⏳ |
- 3.2.5. **Hook** — Cart actions (Pick up / Place cart)
- 3.2.6. **Miscellaneous** — Joystick, Robot summary, Distributor, Log-out button
### 4. Setup ### 3.2 Topbar (`www/topbar.js`)
- **4.1. Missions** — Start, Create, Editor, Actions (xem §4 bên dưới)
- **4.2. Maps** — Site, mapping, object types (walls, zones…), delete
- **4.3. Sounds** — Edit sound
- **4.4. Transitions** — Chuyển map tự động
- **4.5. Users** — CRUD user
- **4.6. User groups** — CRUD nhóm
- **4.7. Shelf types**
- **4.8. I/O modules** — Kết nối Modbus/TCP I/O
- **4.9. Paths**
- **4.10. Path guides**
### 5. Monitoring | Thành phần | API |
- Analytics, System log, Error logs, Hardware health, Safety system |------------|-----|
- **Mission log** / Mission action log | Start / Pause robot | `POST /api/robot/start`, `POST /api/robot/pause` |
| Strip mission, queue hint | `GET /api/robot/status` (~1.5s) |
| Panel lỗi + RESET | `POST /api/robot/errors/reset` |
| Pin, locale vi/en | từ `/api/robot/status` |
| Joystick overlay | `POST /api/robot/joystick`, `POST /api/robot/cmd_vel` |
| Menu user | `GET /api/auth/me` |
### 6. System Ẩn topbar nếu user không có quyền trang `missions`.
- Settings (WiFi, date/time), Processes, PLC registers, Software versions, Backups
- **Robot setup** — bật Modbus, cấu hình robot
- **Triggers** — gắn coil Modbus → mission_id
### 7. Help
- Robot & Hook info, **API documentation**, Remote access, Service book, Manual
### 8. Hook
- Manual control, Carts (type, calibration), Settings, Setup
### 9. Modbus register reference
- 9.1. Status messages (registers 4001+)
- 9.2. PLC triggers (int/float)
- 9.3. Mission triggers (coil **10012000**)
- 9.4. Action commands (coil **16**)
--- ---
## 4. Ba cách chạy Mission (mục 4.1.1) ## 4. Mục lục tính năng
### 4.1 Dashboards — ✅ / 🔶
- **Quản lý:** list, filter, phân trang, tạo, xóa, designer (kéo thả grid, resize), **Permissions** theo user group, chế độ edit/operate.
- API: `GET/PUT /api/dashboards`.
**Widget:**
| Widget | Trạng thái | Ghi chú |
|--------|------------|---------|
| `mission_button` | ✅ | Queue mission cố định |
| `mission_group` | ✅ | Nút theo nhóm mission |
| `mission_queue` | ✅ | Xem + xóa queue |
| `pause_continue` | ✅ | Pause/continue (+ hủy mission) |
| `mission_action_log` | 🔶 | Log mission đang chạy (~10 dòng) |
| `map_locked` | 🔶 | Robot-centered, không pan/zoom |
| `map` | 🔶 | Pose marker |
| `io_connect` | ✅ | Connect/disconnect I/O |
| `io_status` | ✅ | LED cổng digital |
| `io_configuration` | ✅ | Bật/tắt output |
| `logout_button` | ✅ | |
| `robot_summary` | ⏳ | Chỉ tên robot |
| PLC tab | ⏳ | «Coming soon» |
| Hook / Joystick / Distributor widget | ❌ | Joystick chỉ trên topbar |
File: `www/dashboard.js`.
### 4.2 Setup — Missions — 🔶
| UI | API |
|----|-----|
| Danh sách, tạo, sửa, xóa, Save, Save as | `GET/PUT /api/missions` |
| Editor kéo-thả, If/While/Loop, embed mission con | |
| Queue từ list (dialog biến) | `POST /api/mission_queue` |
| Panel queue: sắp xếp, xóa, clear, pause/continue/cancel | `/api/mission_queue/*` |
**Action types (22):**
| Nhóm | Types |
|------|-------|
| Move | `move_to_position`, `move_to_marker`, `adjust_localization`, `switch_map`, `wait`, `set_speed` |
| Logic | `if`, `while`, `loop`, `break`, `continue`, `pause` |
| I/O | `set_digital_output`, `wait_digital_input`, `connect_bluetooth`, `disconnect_bluetooth`, `set_plc_register` |
| Cart | `pick_cart`, `drop_cart` |
| Misc | `user_log`, `play_sound` |
**Ba cách chạy mission:**
| Cách | Mô tả | | Cách | Mô tả |
|------|--------| |------|--------|
| **Dashboard** | Widget Mission button — một mission cố định | | Dashboard | Widget mission button |
| **Setup → Missions** | Bấm icon **queue** → thêm vào mission queue | | Setup → Missions | Icon queue → thêm vào queue |
| **Tích hợp ngoài** | Modbus trigger (coil), REST API (xem Help → API) | | Tích hợp ngoài | Modbus trigger, `POST /api/v2.0.0/mission_queue` |
**Mission queue:** robot chạy tuần tự từ trên xuống; operator có thể sắp xếp lại. Queue chạy tuần tự; biến mission (`*_var`) hỏi operator khi enqueue.
**Biến (variables):** nếu mission có tham số biến (ví dụ position), operator chọn giá trị khi enqueue — hiển thị **màu xanh** trong queue. File: `www/missions.js`, `src/mission/mission_queue.cpp`.
**Chưa có:** Prompt User, Try/Catch, Email, shelf actions, điều kiện If đầy đủ.
### 4.3 Setup — Maps — 🔶
| UI | API |
|----|-----|
| List theo site, tạo, xóa, import site bundle | `/api/maps`, `/api/sites`, `…/import` |
| Editor: pan/zoom, wall/floor/position, zones | `PUT /api/maps` |
| Upload ảnh, YAML, occupancy, undo | `/api/maps/…/image`, `…/yaml` |
| Path preview (từ Paths → View) | overlay trên map editor |
| Cảnh báo preferred zone khi có path cache | confirm trước save |
**Zone types:** wall, floor, position, forbidden, preferred, unpreferred, speed, sound, directional, planner, I/O.
**Chưa có:** markers, evacuation/limit-robots zones; mapping live đầy đủ.
File: `www/maps.js`, `www/map-editor.js`.
### 4.4 Setup — Sounds — ✅
List, upload, nghe, play trên robot, CRUD (không xóa system sound). API: `/api/sounds`. File: `www/sounds.js`.
### 4.5 Setup — Transitions — ✅
List, filter, pager, CRUD dialog (site, from/to map, start/goal position, mission). API: `/api/transitions`. File: `www/transitions.js`.
### 4.6 Setup — Users — ✅
List, filter, CRUD, PIN 4 số. API: `/api/users`. File: `www/users.js`.
### 4.7 Setup — User groups — ✅
List, CRUD, ma trận quyền 7 resource, `allow_pin`. API: `/api/user_groups`. File: `www/user-groups.js`.
### 4.8 Setup — I/O modules — 🔶
List, filter, CRUD; loại Bluetooth / WISE; test TCP từ dialog. API: `/api/io_modules`, `…/test`. Connect runtime qua dashboard widgets.
File: `www/io-modules.js`.
### 4.9 Setup — Paths — 🔶
**Không có Create** — path cache tự tạo khi robot chạy giữa hai position.
| UI | API |
|----|-----|
| List, filter, pager | `GET /api/paths` |
| View trên map | `MapsApp.openEditorWithPath` |
| Delete | `DELETE /api/paths/:id` |
Backend: `PathStore`, `PathPlanner`, `PathService`; invalidate khi đổi position; export/import trong site bundle.
File: `www/paths.js`.
### 4.10 Setup — Path guides — ✅
List, wizard tạo, sửa starts/vias/goals, xóa. API: `/api/path_guides`. File: `www/path-guides.js`.
### 4.11 Setup — Build robot — 🔶
Chỉ **Distributor**. Layout đa cấu hình, LiDAR/IMU CRUD, canvas robot diff.
API: `/api/layouts`, `/api/lidars`, `/api/imus`, `/api/state`. File: `www/app.js` (`pageConfig`).
### 4.12 Chưa triển khai (Setup)
| Mục | Trạng thái |
|-----|------------|
| Shelf types | ❌ |
--- ---
## 5. Mission editor ## 5. Monitoring — ⏳
- Mission = chuỗi **actions** (Move, Logic, Battery, I/O, Cart…). Trang `pageMonitoring`: placeholder «System log — đang phát triển».
- Action có thể dùng **giá trị cố định** hoặc **biến** (hỏi operator mỗi lần enqueue).
- Kéo thả ↕ để sắp xếp; thực thi **từ trên xuống dưới**.
- Có thể **embed mission con** (icon ◎) trong mission lớn.
- **Save** / **Save as** / đổi tên & nhóm qua ⚙.
### 4.1.4. Mission actions — các nhóm **Chưa có:** Analytics, Error logs, Hardware health, Safety system, Mission log browser.
#### Variables (4.1.4.12)
- Khai báo biến dùng chung trong mission.
#### Move (4.1.4.3)
| Action | Mục đích |
|--------|----------|
| Adjust localization | Hiệu chỉnh vị trí trên map |
| Check position status | Kiểm tra position free/occupied (timeout) |
| Docking | Dock vào marker / trạm sạc |
| Move | Đi tới position (retries, distance threshold) |
| Move to entry position | Đi tới entry position trước khi dock/pick |
| Move to coordinate | X, Y, orientation tuyệt đối trên map |
| Planner settings | Desired speed, path deviation, path timeout |
| Relative Move | Dịch chuyển tương đối X/Y/yaw |
| Set footprint | Đổi footprint (top module, cart) |
| Switch Map | Chuyển map trong mission (cần overlap vật lý) |
#### Battery (4.1.4.4)
- **Charging** — đi dock + sạc theo thời gian tối thiểu hoặc % pin; có thể giữ sạc đến khi có mission mới.
#### Logic (4.1.4.5)
| Action | Mục đích |
|--------|----------|
| **Break** | Thoát vòng **Loop** |
| **Continue** | Bỏ phần còn lại của vòng loop, sang vòng tiếp theo |
| **If** | Điều kiện: pin %, pending missions, PLC register, I/O input → nhánh True/False |
| **Loop** | Lặp N lần hoặc **endlessly** (đến khi operator dừng); kéo action vào body loop |
| **Pause** | Dừng mission đến khi operator bấm Continue |
| **Prompt User** | Hỏi Yes/No/Timeout |
| **Return** | **Abort mission** (thường trong Try/Catch) |
| **Wait** | Chờ N giây |
| **While** | Lặp action khi điều kiện còn đúng |
#### Error handling (4.1.4.6)
- **Try/Catch** — Try thất bại → chạy Catch (ví dụ Return).
#### Sound/Light, PLC, Email, I/O module, Cart, Shelf, UR
- Set/wait I/O, PLC register, pick/drop cart, shelf, tích hợp UR cobot, v.v.
--- ---
## 6. Maps ## 6. System — Integrations — 🔶
- **Site** — nhóm nhiều map (tầng/khu vực); robot chuyển map qua Transition hoặc Switch Map action. File: `www/integrations.js`.
- **Object types:** Walls, Floors, Positions, Markers, Directional zones, Preferred/Unpreferred/Forbidden/Critical zones, Speed zones, Sound/light zones, Planner zones, I/O zones, Limit-robots (Fleet), Evacuation zones (Fleet).
| UI | API |
|----|-----|
| Modbus mission triggers (tạo, xóa, fire coil) | `/api/triggers`, `/api/modbus/coils` |
| REST v2 — ví dụ enqueue | `POST /api/v2.0.0/mission_queue` |
| Fleet schedules (tạo, xóa, run now) | `/api/fleet/schedules` |
**Modbus (tương thích tích hợp):**
- Mission triggers: coil 10012000 → enqueue mission.
- Action commands: coil 16 (continue, pause, cancel mission, clear queue, clear error).
- Server Modbus TCP `:5502`.
**Chưa có:** Settings, Backups, PLC registers UI, Processes, Software versions; sửa trigger/schedule (chỉ add/delete).
--- ---
## 7. Dashboard widgets ## 7. Help — ⏳
| Widget MiR | RBS (Cách B) | Trang `pageHelp`: text trỏ tới System → Integrations và tài liệu API.
|------------|----------------|
| Mission button | `dashboard.js` — mission_button | **Chưa có:** API browser nhúng, service book.
| Mission group | mission_group |
| Mission queue | mission_queue |
| Pause/Continue | pause_continue (+ **Hủy mission** bổ sung trong RBS) |
--- ---
## 8. Modbus ## 8. REST API robot
Robot là **Modbus TCP server**. Bật tại **System → Robot setup**, cấu hình trigger tại **System → Triggers**. Base tương thích: `http://<host>/api/v2.0.0/`
### Mission triggers (coil 10012000)
Rising edge coil → enqueue mission đã gắn `mission_id`.
### Action commands (coil 16)
| Coil | Chức năng |
|------|-----------|
| 1 | Continue robot |
| 2 | Pause robot |
| 3 | **Cancel current mission** |
| 4 | Clear mission queue |
| 5 | Clear error |
| 6 | Continue robot |
### Status registers (ví dụ)
Software version, mode, state, error code, battery %, uptime… (registers 4001+).
---
## 9. REST API
Tài liệu API đầy đủ: **Help → API documentation → Launch** trên giao diện robot.
Base URL: `http://<robot_ip>/api/v2.0.0/`
| Endpoint | Mô tả | | Endpoint | Mô tả |
|----------|--------| |----------|--------|
@@ -419,28 +324,31 @@ Base URL: `http://<robot_ip>/api/v2.0.0/`
| `POST /mission_queue` | Enqueue (`mission_id`) | | `POST /mission_queue` | Enqueue (`mission_id`) |
| `DELETE /mission_queue` | Xóa queue | | `DELETE /mission_queue` | Xóa queue |
Xác thực: HTTP Basic (user/password robot). Xác thực: session cookie hoặc Bearer (ưu tiên session web); tích hợp ngoài có thể dùng Basic tùy cấu hình.
**Robot runtime:** `GET /api/robot/status`, start/pause, joystick, active map, sound play.
--- ---
## 10. Mapping sang dự án RBS ## 9. Tóm tắt triển khai
| Khái niệm MiR Reference Guide | RBS | ```
|------------------------------|--------| ✅ Hoàn thiện tốt: Sign in, Users, User groups, Sounds, Transitions, Path guides
| Setup → Missions → queue | **Cách A**`www/missions.js` | 🔶 Đang dùng được: Dashboard, Missions, Maps, I/O, Paths, Integrations, Topbar, Build robot
| Dashboard widgets | **Cách B**`www/dashboard.js` | ⏳ Placeholder: Monitoring, Help, Robot summary widget, PLC tab
| Modbus triggers 10012000 | **Cách C**`:5502`, `integrations.js` | ❌ Chưa bắt đầu: Shelf types, Analytics/Error logs/Hardware/Safety, System Settings/Backups
| REST v2 mission_queue | `POST /api/v2.0.0/mission_queue` | ```
| MiR Fleet schedule | `/api/fleet/schedules` |
| Loop / Break / Continue | `www/missions.js` + `mission_queue.cpp` | **File frontend chính:** `index.html`, `nav.js`, `topbar.js`, `auth.js`, `app.js`, `dashboard.js`, `missions.js`, `maps.js`, `map-editor.js`, `sounds.js`, `transitions.js`, `users.js`, `user-groups.js`, `io-modules.js`, `paths.js`, `path-guides.js`, `integrations.js`, `style.css`, `i18n.js`.
| Pause / Continue | `/api/mission_queue/pause`, `/continue` |
| Cancel (Modbus coil 3) | `/api/mission_queue/cancel` |
| Sign in / User groups | **Đã triển khai** — §2.1 (`AuthService`, UI MiR, `data/auth.json`) |
--- ---
## 11. Ghi chú ## 10. Vận hành và kiểm thử
- Rev. 1.9 (2019) — firmware mới có thể khác; đối chiếu bản API trên robot thực tế. ```bash
- Phần cứng MiR250: xem `docs/mir250_user_guide_11_en.pdf`. ./scripts/lm.sh test run # smoke + pytest
- Fleet (scheduler, robot groups): tài liệu riêng *MiR Fleet Reference Guide*. docker compose up --build -d # sau sửa www/
```
- Dữ liệu: `data/RBS.db`, `data/auth.json`, `data/state.json`.
- Hard refresh (`Ctrl+Shift+R`) nếu cache JS/CSS.

View File

@@ -38,6 +38,6 @@ scripts/
|------|----------|---------| |------|----------|---------|
| `LM_URL` | `http://127.0.0.1:8080` | URL container | | `LM_URL` | `http://127.0.0.1:8080` | URL container |
| `LM_TEST_PORT` | `18080` | Port server tạm khi `test run` | | `LM_TEST_PORT` | `18080` | Port server tạm khi `test run` |
| `LM_CONTAINER` | `lidar-manager-limited` | Tên container | | `LM_CONTAINER` | `robot-app-limited` | Tên container |
| `TEST_BASE_URL` | — | Base URL cho pytest | | `TEST_BASE_URL` | — | Base URL cho pytest |
| `BENCH_REQUESTS` | `100` | Số request mỗi endpoint benchmark | | `BENCH_REQUESTS` | `100` | Số request mỗi endpoint benchmark |

View File

@@ -13,5 +13,5 @@ echo
bench_http_suite "$BASE" bench_http_suite "$BASE"
echo echo
echo "=== Process ===" echo "=== Process ==="
ps -C lidar_manager_web -o pid,rss,vsz,pcpu,pmem,etime,cmd 2>/dev/null \ ps -C robot_app -o pid,rss,vsz,pcpu,pmem,etime,cmd 2>/dev/null \
|| pgrep -af '[./]lidar_manager_web' | grep -v pgrep || true || pgrep -af '[./]robot_app' | grep -v pgrep || true

View File

@@ -4,7 +4,7 @@
_lm_lib_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" _lm_lib_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
LM_ROOT="$(cd "$_lm_lib_dir/../.." && pwd)" LM_ROOT="$(cd "$_lm_lib_dir/../.." && pwd)"
LM_SCRIPTS="$(cd "$_lm_lib_dir/.." && pwd)" LM_SCRIPTS="$(cd "$_lm_lib_dir/.." && pwd)"
LM_CONTAINER="${LM_CONTAINER:-lidar-manager-limited}" LM_CONTAINER="${LM_CONTAINER:-robot-app-limited}"
LM_URL="${LM_URL:-http://127.0.0.1:8080}" LM_URL="${LM_URL:-http://127.0.0.1:8080}"
LM_TEST_PORT="${LM_TEST_PORT:-18080}" LM_TEST_PORT="${LM_TEST_PORT:-18080}"

View File

@@ -7,7 +7,7 @@ source "$(dirname "$0")/../lib/common.sh"
cd "$LM_ROOT" cd "$LM_ROOT"
PORT="${TEST_PORT:-$LM_TEST_PORT}" PORT="${TEST_PORT:-$LM_TEST_PORT}"
BASE="http://127.0.0.1:${PORT}" BASE="http://127.0.0.1:${PORT}"
BIN="${LM_ROOT}/build/lidar_manager_web" BIN="${LM_ROOT}/build/robot_app"
DATA_DIR="$(mktemp -d)" DATA_DIR="$(mktemp -d)"
SERVER_PID="" SERVER_PID=""
@@ -28,7 +28,7 @@ cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON
cmake --build build -j cmake --build build -j
echo "==> C++ unit tests (GTest)" echo "==> C++ unit tests (GTest)"
./build/lidar_manager_tests ./build/robot_app_tests
echo "==> Prepare isolated data directory" echo "==> Prepare isolated data directory"
cp -a tests/fixtures/data/. "$DATA_DIR/" cp -a tests/fixtures/data/. "$DATA_DIR/"

View File

@@ -1,4 +1,4 @@
#include "app/lidar_manager_app.hpp" #include "app/robot_app.hpp"
#include "auth/auth_service.hpp" #include "auth/auth_service.hpp"
#include "io/io_module_service.hpp" #include "io/io_module_service.hpp"
@@ -46,14 +46,12 @@ std::filesystem::path resolveDataPath(std::filesystem::path data_path)
} // namespace } // namespace
LidarManagerApp::LidarManagerApp(int port, RobotApp::RobotApp(int port, std::filesystem::path www_root, std::filesystem::path data_path)
std::filesystem::path www_root,
std::filesystem::path data_path)
: port_(port), www_root_(std::move(www_root)), data_path_(std::move(data_path)) : port_(port), www_root_(std::move(www_root)), data_path_(std::move(data_path))
{ {
} }
int LidarManagerApp::run() int RobotApp::run()
{ {
data_path_ = resolveDataPath(data_path_); data_path_ = resolveDataPath(data_path_);
const std::filesystem::path data_dir = data_path_.parent_path(); const std::filesystem::path data_dir = data_path_.parent_path();
@@ -128,7 +126,7 @@ int LidarManagerApp::run()
StaticFileServer::mount(svr, www_root_); StaticFileServer::mount(svr, www_root_);
std::fprintf(stderr, std::fprintf(stderr,
"lidar_manager_web listening on http://0.0.0.0:%d (www=%s, db=%s, maps=%s, sounds=%s)\n", "robot_app listening on http://0.0.0.0:%d (www=%s, db=%s, maps=%s, sounds=%s)\n",
port_, port_,
www_root_.string().c_str(), www_root_.string().c_str(),
database.dbPath().string().c_str(), database.dbPath().string().c_str(),

View File

@@ -4,10 +4,10 @@
namespace lm { namespace lm {
class LidarManagerApp class RobotApp
{ {
public: public:
LidarManagerApp(int port, std::filesystem::path www_root, std::filesystem::path data_path); RobotApp(int port, std::filesystem::path www_root, std::filesystem::path data_path);
int run(); int run();

View File

@@ -1,4 +1,4 @@
#include "app/lidar_manager_app.hpp" #include "app/robot_app.hpp"
#include <cstdlib> #include <cstdlib>
#include <filesystem> #include <filesystem>
@@ -10,6 +10,6 @@ int main(int argc, char** argv)
const std::filesystem::path data_path = const std::filesystem::path data_path =
(argc >= 4) ? std::filesystem::path(argv[3]) : std::filesystem::path("data/RBS.db"); (argc >= 4) ? std::filesystem::path(argv[3]) : std::filesystem::path("data/RBS.db");
lm::LidarManagerApp app(port, www_root, data_path); lm::RobotApp app(port, www_root, data_path);
return app.run(); return app.run();
} }

View File

@@ -1,4 +1,4 @@
"""Integration tests for lidar_manager_web REST API.""" """Integration tests for robot_app REST API."""
from __future__ import annotations from __future__ import annotations