Files
Lab505/phenikaa-api.yaml
2026-10-12 15:24:08 +07:00

1012 lines
34 KiB
YAML

openapi: "3.0.0"
info:
title: Phenikaa Fleet Manager API
description: >
HTTP API implemented by Phenikaa's fleet manager and called by RoboLab.
Part of the Lab505 teaching materials bundle.
Covers order dispatch, map export, vehicle discovery, vehicle state polling,
simulation mode switching, and workflow lock management.
version: "0.1.0"
contact:
name: RoboLab / Phenikaa-X Integration
servers:
- url: http://{host}:7222
description: Phenikaa fleet manager
variables:
host:
default: "192.168.0.5"
description: Fleet manager hostname or IP
security:
- ApiKeyAuth: []
components:
securitySchemes:
ApiKeyAuth:
type: apiKey
in: header
name: X-Api-Key
description: API key for authenticating RoboLab to Phenikaa's fleet manager
schemas:
# ── Error ──────────────────────────────────────────────
ErrorResponse:
type: object
description: >
Error body for every non-validation error, used by both the fleet manager and RoboLab.
required: [errors]
properties:
errors:
type: array
minItems: 1
items:
$ref: "#/components/schemas/ErrorEntry"
ErrorEntry:
type: object
required: [code, message]
properties:
code:
type: string
description: Machine-readable error code (SCREAMING_SNAKE_CASE)
example: "VEHICLE_OFFLINE"
message:
type: string
description: Developer-facing error description (English; not for display to end users)
example: "Vehicle IMR-01 is offline and cannot accept orders"
args:
type: object
additionalProperties:
type: string
description: Parameter values for localisation
ValidationErrorResponse:
type: object
description: >
Error body RoboLab returns when a request body fails validation. Keyed by the
offending field; each entry carries a code and optional localisation args (no message).
required: [fieldErrors]
properties:
fieldErrors:
type: object
additionalProperties:
type: array
items:
type: object
required: [code]
properties:
code:
type: string
example: "FIELD_REQUIRED"
args:
type: object
additionalProperties:
type: string
# ── Order ──────────────────────────────────────────────
OrderRequest:
type: object
required: [serialNumber, orderId, nodes]
properties:
serialNumber:
type: string
description: Vehicle serial number
example: "IMR-01"
orderId:
type: string
format: uuid
description: RoboLab-generated order identifier
example: "3fa85f64-5717-4562-b3fc-2c963f66afa6"
nodes:
type: array
minItems: 1
items:
$ref: "#/components/schemas/OrderNode"
OrderNode:
type: object
required: [nodeCode, sequenceId]
properties:
nodeCode:
type: string
description: Node code from the shared topological map
example: "Bt1"
sequenceId:
type: integer
minimum: 0
description: Monotonically increasing sequence number
actions:
type: array
items:
$ref: "#/components/schemas/OrderAction"
OrderAction:
type: object
required: [actionType, actionId]
properties:
actionType:
type: string
description: >
Action type. Expressed as methods of two base actions (Load, Unload).
Supported action types are defined by each Vehicle.
example: "PickUp"
actionId:
type: string
description: Unique action identifier within the order
example: "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
blockingType:
type: string
enum: [NONE, SOFT, HARD]
description: >
Whether the action blocks vehicle movement at the node.
NONE — non-blocking; vehicle continues driving while action executes.
SOFT — vehicle may continue once the action enters RUNNING state.
HARD — vehicle must stop and wait for the action to reach FINISHED.
RoboLab's current dispatcher always sends HARD; NONE and SOFT are
accepted by the fleet manager but not currently produced by RoboLab.
actionParameters:
type: array
items:
$ref: "#/components/schemas/ActionParameter"
ActionParameter:
type: object
required: [key, value]
properties:
key:
type: string
example: "goodsType"
value:
type: string
example: "OK"
description: >
Key-value parameters attached to an action. Used for payload types
(OK/NG), quantity, station endpoint addresses, and other vendor-specific data.
# ── Map ────────────────────────────────────────────────
MapResponse:
type: object
required: [nodes, edges, xOffset, yOffset, thetaOffset]
properties:
nodes:
type: array
items:
$ref: "#/components/schemas/MapNode"
edges:
type: array
items:
$ref: "#/components/schemas/MapEdge"
xOffset:
type: number
format: double
description: X of the background image's origin (its top-left corner) in the fleet manager's coordinate system (metres)
yOffset:
type: number
format: double
description: Y of the background image's origin in the fleet manager's coordinate system (metres)
thetaOffset:
type: number
format: double
description: Rotation of the background image's axes relative to the fleet manager's axes (radians)
MapNode:
type: object
required: [nodeCode]
properties:
nodeCode:
type: string
description: Node code from the shared topological map
example: "Bt1"
x:
type: number
format: double
description: X coordinate in the map reference frame (metres)
y:
type: number
format: double
description: Y coordinate in the map reference frame (metres)
MapEdge:
type: object
required: [startNodeCode, endNodeCode]
properties:
startNodeCode:
type: string
description: Source node code
endNodeCode:
type: string
description: Target node code
# ── Vehicles ───────────────────────────────────────────
VehicleListResponse:
type: object
additionalProperties:
$ref: "#/components/schemas/VehicleEntry"
VehicleEntry:
type: object
required: [loadCapabilities, unloadCapabilities]
properties:
model:
type: string
description: Vehicle model or type
example: "IMR"
loadCapabilities:
type: object
additionalProperties:
type: object
unloadCapabilities:
type: object
additionalProperties:
type: object
# ── Mode ───────────────────────────────────────────────
ModeResponse:
type: object
required: [mode]
properties:
mode:
type: string
enum: [SIM, REAL]
workflowLock:
$ref: "#/components/schemas/WorkflowLock"
ModeSwitchRequest:
type: object
required: [mode]
properties:
mode:
type: string
enum: [SIM, REAL]
# ── Control ────────────────────────────────────────────
ControlResponse:
type: object
required: [held]
properties:
held:
type: boolean
description: Whether the calling API key holds the workflow lock
workflowLock:
$ref: "#/components/schemas/WorkflowLock"
WorkflowLock:
type: object
nullable: true
properties:
holder:
type: string
description: Name of the client holding the lock
example: "RoboLab"
expiresAt:
type: string
format: date-time
description: Lock expiration timestamp (UTC)
# ── Vehicle State ──────────────────────────────────────
VehicleStateResponse:
type: object
description: Full snapshot of all vehicles keyed by serial number, each with combined state and position.
additionalProperties:
$ref: "#/components/schemas/VehicleState"
VehicleState:
type: object
description: >
Combined state and position snapshot for a single vehicle.
Merges VDA5050 states and visualization data into one object.
properties:
x:
type: number
format: double
description: X position in the map reference frame (metres)
y:
type: number
format: double
description: Y position in the map reference frame (metres)
theta:
type: number
format: double
description: Heading angle (radians)
orderId:
type: string
description: Currently active order ID (empty if idle)
lastNodeCode:
type: string
description: Last node the vehicle occupied or passed
operatingMode:
type: string
description: Current operating mode (e.g. AUTOMATIC, MANUAL)
online:
type: boolean
description: Whether the vehicle is connected to the fleet manager
ready:
type: boolean
description: Whether the vehicle is ready to accept orders
driving:
type: boolean
description: Whether the vehicle is currently in motion
paused:
type: boolean
description: Whether the vehicle's current order is paused
batteryCharge:
type: number
description: Battery level (0.0 to 1.0)
charging:
type: boolean
description: Whether the vehicle is currently charging
eStop:
type: string
enum: [NONE, AUTOACK, MANUAL, REMOTE]
description: Emergency stop status
actions:
type: array
items:
type: object
properties:
actionId:
type: string
actionType:
type: string
actionStatus:
type: string
enum: [WAITING, INITIALIZING, RUNNING, PAUSED, FINISHED, FAILED]
errors:
type: array
items:
type: object
properties:
errorType:
type: string
errorDescription:
type: string
errorLevel:
type: string
enum: [WARNING, FATAL]
# ── RoboLab ───────────────────────────────────────────
VehicleRegistrationRequest:
type: object
required: [loadCapabilities, unloadCapabilities]
properties:
model:
type: string
description: Vehicle model or type
example: "IMR"
loadCapabilities:
type: object
additionalProperties:
type: object
unloadCapabilities:
type: object
additionalProperties:
type: object
description: >
Vehicle registration payload. The serialNumber is provided in the path
only and must not be repeated in the request body.
OrderCompletedCallback:
type: object
required: [result]
properties:
result:
type: string
enum: [COMPLETED, FAILED]
VehicleResponse:
type: object
description: RoboLab's stored view of the vehicle, returned after an upsert.
required: [id, code, state, loadCapabilities, unloadCapabilities]
properties:
id:
type: string
format: uuid
description: RoboLab's surrogate identifier for the vehicle
code:
type: string
description: Vehicle natural key (matches serialNumber)
example: "IMR-01"
model:
type: string
nullable: true
loadCapabilities:
type: object
additionalProperties:
type: object
unloadCapabilities:
type: object
additionalProperties:
type: object
state:
type: string
description: RoboLab-tracked vehicle state
activeFleetOrderId:
type: string
nullable: true
description: The fleet-manager order the vehicle last reported executing (the state's orderId); null if idle
lastNodeCode:
type: string
nullable: true
positionX:
type: number
format: double
nullable: true
positionY:
type: number
format: double
nullable: true
theta:
type: number
format: double
nullable: true
# ── Reusable responses ───────────────────────────────────
responses:
BadRequest:
description: Invalid request body or parameters
content:
application/json:
schema:
$ref: "#/components/schemas/ErrorResponse"
example:
errors:
- code: "INVALID_ORDER"
message: "Order node sequenceId values must be monotonically increasing"
Conflict:
description: Resource state conflict (vehicle busy, workflow locked)
content:
application/json:
schema:
$ref: "#/components/schemas/ErrorResponse"
example:
errors:
- code: "VEHICLE_BUSY"
message: "Vehicle IMR-01 is currently executing another order"
OrderNotCancellable:
description: Order cannot be cancelled in its current state
content:
application/json:
schema:
$ref: "#/components/schemas/ErrorResponse"
example:
errors:
- code: "ORDER_NOT_CANCELLABLE"
message: "Order is already COMPLETED and cannot be cancelled"
VehicleOffline:
description: Vehicle or hardware is offline
content:
application/json:
schema:
$ref: "#/components/schemas/ErrorResponse"
example:
errors:
- code: "VEHICLE_OFFLINE"
message: "Vehicle IMR-01 is offline and cannot accept orders"
ValidationFailed:
description: Request body failed RoboLab's validation
content:
application/json:
schema:
$ref: "#/components/schemas/ValidationErrorResponse"
example:
fieldErrors:
loadCapabilities:
- code: "FIELD_REQUIRED"
Unauthorized:
description: Missing or invalid X-Api-Key
content:
application/json:
schema:
$ref: "#/components/schemas/ErrorResponse"
example:
errors:
- code: "UNAUTHORIZED"
message: "Missing or invalid X-Api-Key header."
NotFound:
description: Resource not found
content:
application/json:
schema:
$ref: "#/components/schemas/ErrorResponse"
example:
errors:
- code: "ORDER_NOT_FOUND"
message: "Order 3fa85f64-5717-4562-b3fc-2c963f66afa6 not found"
tags:
- name: Orders
description: Vehicle order dispatch and lifecycle
- name: Map
description: Topological map export
- name: Vehicles
description: Vehicle registration and discovery
- name: State
description: Polling endpoint for vehicle state and position snapshots
- name: Mode
description: Simulation / real mode switching
- name: Control
description: Workflow lock acquire / release / renew
- name: RoboLab
description: Endpoints implemented by RoboLab, called by Phenikaa
paths:
# ── Orders ──────────────────────────────────────────────
/api/share/orders:
post:
tags: [Orders]
summary: Dispatch a transport order to a vehicle
description: >
Submits a VDA5050-shaped order for a single vehicle. The order consists
of a sequence of nodes, each with zero or more actions. Phenikaa's fleet
manager handles path planning (hops between requested nodes), dock/undock
sequencing, and action lifecycle internally.
Returns immediately without waiting for completion. Completion is signalled
via the order completed callback on RoboLab. Intermediate progress can be
observed by polling `/api/share/state`.
operationId: dispatchOrder
requestBody:
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/OrderRequest"
example:
serialNumber: "IMR-01"
orderId: "3fa85f64-5717-4562-b3fc-2c963f66afa6"
nodes:
- nodeCode: "Bt1"
sequenceId: 0
actions:
- actionType: "PickUp"
actionId: "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
blockingType: "HARD"
actionParameters:
- key: "goodsType"
value: "OK"
- key: "quantity"
value: "3"
- nodeCode: "node_15"
sequenceId: 1
actions: []
- nodeCode: "Abb"
sequenceId: 2
actions:
- actionType: "UnLoad"
actionId: "b2c3d4e5-f6a7-8901-bcde-f12345678901"
blockingType: "HARD"
actionParameters:
- key: "stationOpcEndpoint"
value: "opc.tcp://192.168.0.10:4840"
responses:
"202":
description: Order accepted and dispatched
"400":
$ref: "#/components/responses/BadRequest"
"409":
$ref: "#/components/responses/Conflict"
"503":
$ref: "#/components/responses/VehicleOffline"
/api/share/orders/{orderId}:
parameters:
- name: orderId
in: path
required: true
schema:
type: string
format: uuid
delete:
tags: [Orders]
summary: Cancel an active order
description: >
Requests cancellation of an in-progress order. The fleet manager will
attempt to cancel the order and bring the vehicle to a safe state.
Cancellation completion is observable via `/api/share/state`.
operationId: cancelOrder
responses:
"202":
description: Cancellation requested
"404":
$ref: "#/components/responses/NotFound"
"409":
$ref: "#/components/responses/OrderNotCancellable"
# ── Map ─────────────────────────────────────────────────
/api/share/map:
get:
tags: [Map]
summary: Export the topological map
description: >
Returns the full topological graph (nodes and edges) known to
Phenikaa's fleet manager, together with the pose of RoboLab's
background image origin in the fleet manager's coordinate system
(`xOffset`, `yOffset`, `thetaOffset`). RoboLab imports this on startup
and periodically to populate its MaterialFlow station/route map.
Stations are a RoboLab concept — Phenikaa exports raw nodes and edges;
RoboLab maps station codes onto nodes through its own configuration.
Called by RoboLab's `GetMapAsync` (see docs/requirements/backend/vehicles.md).
operationId: exportMap
responses:
"200":
description: Topological graph
content:
application/json:
schema:
$ref: "#/components/schemas/MapResponse"
example:
nodes:
- nodeCode: "Bt1"
x: 1.5
y: 3.2
- nodeCode: "Abb"
x: 4.8
y: 1.0
- nodeCode: "node_15"
x: 3.0
y: 2.5
edges:
- startNodeCode: "Bt1"
endNodeCode: "node_15"
- startNodeCode: "node_15"
endNodeCode: "Abb"
xOffset: 0.0
yOffset: 0.0
thetaOffset: 0.0
# ── Vehicles ────────────────────────────────────────────
/api/share/vehicles:
get:
tags: [Vehicles]
summary: List registered vehicles
description: >
Returns all vehicles registered with Phenikaa's fleet manager,
including their structured capabilities. RoboLab uses this to
perform vehicle selection when dispatching orders.
operationId: listVehicles
responses:
"200":
description: Vehicle list
content:
application/json:
schema:
$ref: "#/components/schemas/VehicleListResponse"
example:
IMR-01:
model: "IMR"
loadCapabilities:
PickUp: {}
Load: {}
unloadCapabilities:
PutDown: {}
AMR-01:
model: "AMR"
loadCapabilities:
Load: {}
unloadCapabilities:
Unload: {}
# ── State ───────────────────────────────────────────────
/api/share/state:
get:
tags: [State]
summary: Get current state and position of all vehicles
description: >
Returns a snapshot of every registered vehicle, combining its operational
state (order status, action progress, safety state, errors) with its current
position and heading.
RoboLab polls this endpoint periodically to track vehicle progress and
update the fleet visualisation.
operationId: getVehicleStates
responses:
"200":
description: Snapshot of all vehicle states and positions
content:
application/json:
schema:
$ref: "#/components/schemas/VehicleStateResponse"
example:
IMR-01:
x: 1.52
y: 3.18
theta: 0.785
orderId: "3fa85f64-5717-4562-b3fc-2c963f66afa6"
lastNodeCode: "Bt1"
operatingMode: "AUTOMATIC"
online: true
ready: false
driving: false
paused: false
batteryCharge: 0.85
charging: false
eStop: "NONE"
actions:
- actionId: "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
actionType: "PickUp"
actionStatus: "RUNNING"
errors: []
AMR-02:
x: 7.40
y: 2.10
theta: 1.571
orderId: ""
lastNodeCode: "node_42"
operatingMode: "AUTOMATIC"
online: true
ready: true
driving: false
paused: false
batteryCharge: 0.92
charging: true
eStop: "NONE"
actions: []
errors: []
# ── Mode ────────────────────────────────────────────────
/api/share/mode:
get:
tags: [Mode]
summary: Get current simulation mode
description: >
Returns the current mode (sim or real) and workflow lock status.
**Not yet called by RoboLab.** The fleet manager exposes mode
switching, but RoboLab has no integration point for it yet.
operationId: getMode
responses:
"200":
description: Current mode
content:
application/json:
schema:
$ref: "#/components/schemas/ModeResponse"
example:
mode: "REAL"
workflowLock:
holder: "RoboLab"
expiresAt: "9999-12-31T23:59:59Z"
post:
tags: [Mode]
summary: Switch simulation mode
description: >
Switches between sim and real mode.
In sim mode, the fleet manager simulates robot responses.
In real mode, actual hardware is used.
operationId: switchMode
requestBody:
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/ModeSwitchRequest"
example:
mode: "SIM"
responses:
"200":
description: Mode switched
"403":
description: API key does not have permission to switch to real mode
content:
application/json:
schema:
$ref: "#/components/schemas/ErrorResponse"
example:
errors:
- code: "MODE_REAL_NOT_PERMITTED"
message: "This API key does not have permission to use real mode"
# ── Control ─────────────────────────────────────────────
/api/share/control:
get:
tags: [Control]
summary: Check workflow lock status
description: >
Returns whether the calling API key currently holds the workflow lock
and, if held, the lock expiration timestamp. While the lock is held,
Phenikaa's internal operator is blocked from running workflows.
**Not yet called by RoboLab.** The fleet manager exposes workflow lock
management, but RoboLab has no integration point for it yet.
operationId: getControl
responses:
"200":
description: Lock status
content:
application/json:
schema:
$ref: "#/components/schemas/ControlResponse"
example:
held: true
workflowLock:
holder: "RoboLab"
expiresAt: "9999-12-31T23:59:59Z"
/api/share/control/acquire:
post:
tags: [Control]
summary: Acquire workflow lock
description: >
Acquires the workflow lock for the calling API key. While held,
Phenikaa's internal operator is blocked from running workflows.
The lock persists until explicitly released or the server restarts.
operationId: acquireControl
responses:
"200":
description: Lock acquired
"423":
description: Lock held by another client
content:
application/json:
schema:
$ref: "#/components/schemas/ErrorResponse"
example:
errors:
- code: "LOCK_HELD"
message: "Workflow lock is held by another client"
/api/share/control/release:
post:
tags: [Control]
summary: Release workflow lock
description: >
Releases the workflow lock held by the calling API key.
Once released, Phenikaa's internal operator can run workflows again.
operationId: releaseControl
responses:
"200":
description: Lock released
"403":
description: Caller does not hold the lock
content:
application/json:
schema:
$ref: "#/components/schemas/ErrorResponse"
example:
errors:
- code: "LOCK_NOT_HELD"
message: "This API key does not hold the workflow lock"
/api/share/control/renew:
post:
tags: [Control]
summary: Renew workflow lock (keep-alive)
description: >
Renews the workflow lock expiration for the calling API key.
Must be called periodically to prevent lock expiry while the
RoboLab workflow is still active.
operationId: renewControl
responses:
"200":
description: Lock renewed
"403":
description: Caller does not hold the lock
content:
application/json:
schema:
$ref: "#/components/schemas/ErrorResponse"
example:
errors:
- code: "LOCK_NOT_HELD"
message: "This API key does not hold the workflow lock"
# ── RoboLab ────────────────────────────────────────────
/api/phenikaa/v1/vehicles/{code}:
parameters:
- name: code
in: path
required: true
schema:
type: string
description: Vehicle natural key (same value as Phenikaa's serialNumber)
example: "IMR-01"
put:
tags: [RoboLab]
summary: Register or update vehicle information
description: >
**Called by Phenikaa at `http://{robolabHost}:8080`.**
Implemented by RoboLab.
Called when vehicles are added, or their capabilities change.
RoboLab uses this data for vehicle selection during order dispatch.
Upserts: creates if the vehicle does not exist, updates if it does.
operationId: upsertVehicle
requestBody:
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/VehicleRegistrationRequest"
example:
model: "IMR"
loadCapabilities:
PickUp: {}
Load: {}
unloadCapabilities:
PutDown: {}
Unload: {}
responses:
"200":
description: Vehicle registered or updated
content:
application/json:
schema:
$ref: "#/components/schemas/VehicleResponse"
"400":
$ref: "#/components/responses/ValidationFailed"
"401":
$ref: "#/components/responses/Unauthorized"
delete:
tags: [RoboLab]
summary: Remove a vehicle
description: >
**Called by Phenikaa at `http://{robolabHost}:8080`.**
Implemented by RoboLab.
Removes (deregisters) a vehicle from RoboLab's vehicle registry.
operationId: removeVehicle
responses:
"204":
description: Vehicle removed
"401":
$ref: "#/components/responses/Unauthorized"
"404":
description: Vehicle not known to RoboLab
content:
application/json:
schema:
$ref: "#/components/schemas/ErrorResponse"
example:
errors:
- code: "VEHICLE_NOT_FOUND"
message: "Vehicle 'IMR-01' not found."
args:
code: "IMR-01"
/api/phenikaa/v1/orders/{orderId}/complete:
parameters:
- name: orderId
in: path
required: true
schema:
type: string
format: uuid
post:
tags: [RoboLab]
summary: Notify RoboLab that an order has completed
description: >
**Called by Phenikaa at `http://{robolabHost}:8080`.**
Implemented by RoboLab.
Called when a previously dispatched order reaches a terminal state
(COMPLETED or FAILED). Complements the polling-based `/api/share/state`
endpoint by providing a guaranteed delivery path for terminal order events.
operationId: orderCompletedCallback
requestBody:
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/OrderCompletedCallback"
responses:
"200":
description: Callback acknowledged
"400":
$ref: "#/components/responses/ValidationFailed"
"401":
$ref: "#/components/responses/Unauthorized"
"404":
description: Order not known to RoboLab
content:
application/json:
schema:
$ref: "#/components/schemas/ErrorResponse"
example:
errors:
- code: "ORDER_NOT_FOUND"
message: "No hardware order dispatched with fleet order id '3fa85f64-5717-4562-b3fc-2c963f66afa6'."
args:
orderId: "3fa85f64-5717-4562-b3fc-2c963f66afa6"