mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-04 03:11:43 +00:00
[sim] Update WebSockets API Specification (#6664)
Also update AddressableLED data to be output instead of input.
This commit is contained in:
@@ -77,13 +77,17 @@ The “hardware“ (which might be a full-fledged 3D simulation engine, a physic
|
||||
| Type value | Description | Device value |
|
||||
| ----------------------- | -------------------------- | ------------------------- |
|
||||
| [``"Accel"``][] | Accelerometer | Arbitrary device name |
|
||||
| [``"AddressableLED"``][]| Addressable LED Strip | Arbitrary device number |
|
||||
| [``"AI"``][] | Analog input | Port index, e.g. "1", "2" |
|
||||
| [``"AO"``][] | Analog output | Port index, e.g. "1", "2" |
|
||||
| [``"CTREPCM"``][] | PCM | Module number, e.g. "1", "2" |
|
||||
| [``"DIO"``][] | Digital input/output | Port index, e.g. "1", "2" |
|
||||
| [``"dPWM"``][] | Duty cycle output | Arbitrary device number |
|
||||
| [``"DriverStation"``][] | Driver station / FMS state | Blank |
|
||||
| [``"DutyCycle"``][] | Duty cycle input | Arbitrary device name |
|
||||
| [``"Encoder"``][] | Quadrature encoder | Arbitrary device number |
|
||||
| [``"Gyro"``][] | Gyro | Arbitrary device name |
|
||||
| [``"HAL"``][] | HAL data | ``"HAL"`` |
|
||||
| [``"Joystick"``][] | Joystick data | Joystick number |
|
||||
| [``"PWM"``][] | PWM output | Port index, e.g. "1", "2" |
|
||||
| [``"Relay"``][] | Relay output | Port index, e.g. "1", "2" |
|
||||
@@ -105,16 +109,46 @@ C++/Java implementation note: these are created as either BuiltInAccelerometer o
|
||||
| ``">y"`` | Float | Acceleration in G’s |
|
||||
| ``">z"`` | Float | Acceleration in G’s |
|
||||
|
||||
#### Addressable LED Strip ("AddressableLED")
|
||||
|
||||
[``"AddressableLED"``]:#addressable-led-strip-addressableled
|
||||
|
||||
| Data Key | Type | Description |
|
||||
| ------------------ | ------- | ---------------------------------------------------- |
|
||||
| ``"<init"`` | Boolean | If the led strip is initialized in the robot program |
|
||||
| ``"<output_port"`` | Integer | DIO pin number |
|
||||
| ``"<length"`` | Integer | The number of leds in the strip |
|
||||
| ``"<running"`` | Boolean | Whether the strip is outputting data |
|
||||
| ``"<data"`` | Array (See Below) | One value per led; value is an object with ``"r"``, ``"g"``, and ``"b"`` keys, representing the rgb (0-255) components of the color |
|
||||
|
||||
#### Analog Input ("AI")
|
||||
|
||||
[``"AI"``]:#analog-input-ai
|
||||
|
||||
The basic analog input just reads a voltage.
|
||||
The basic analog input just reads a voltage. An analog input can also be configured to use an averaging and oversampling engine.
|
||||
|
||||
| Data Key | Type | Description |
|
||||
| -------------- | ------- | --------------------------------------------------- |
|
||||
| ``"<init"`` | Boolean | If analog input is initialized in the robot program |
|
||||
| ``">voltage"`` | Float | Input voltage, in volts |
|
||||
| Data Key | Type | Description |
|
||||
| --------------------- | ------- | --------------------------------------------------- |
|
||||
| ``"<init"`` | Boolean | If analog input is initialized in the robot program |
|
||||
| ``"<avg_bits"`` | Integer | The number of averaging bits |
|
||||
| ``"<oversample_bits"` | Integer | The number of oversampling bits |
|
||||
| ``">voltage"`` | Float | Input voltage, in volts |
|
||||
| ``"<accum_init"`` | Boolean | If the accumulator is initialized in the robot program |
|
||||
| ``">accum_value"`` | Integer | The accumulated value |
|
||||
| ``">accum_count"`` | Integer | The number of accumulated values |
|
||||
| ``"<accum_center"`` | Integer | The center value of the accumulator |
|
||||
| ``"<accum_deadband"`` | Integer | The accumulator's deadband |
|
||||
|
||||
#### Analog Output ("AO")
|
||||
|
||||
[``"AO"``]:#analog-output-ao
|
||||
|
||||
The basic analog output just sends a voltage.
|
||||
|
||||
| Data Key | Type | Description |
|
||||
| --------------------- | ------- | ---------------------------------------------------- |
|
||||
| ``"<init"`` | Boolean | If analog output is initialized in the robot program |
|
||||
| ``"<voltage"`` | Float | Output voltage, in volts |
|
||||
|
||||
#### Digital Input/Output ("DIO")
|
||||
|
||||
@@ -125,6 +159,7 @@ The basic analog input just reads a voltage.
|
||||
| ``"<init"`` | Boolean | If DIO is initialized in the robot program |
|
||||
| ``"<input"`` | Boolean | True if input, false if output |
|
||||
| ``"<>value"`` | Boolean | Input or output state |
|
||||
| ``"<pulse_length"`` | Float | Reserved for future use |
|
||||
|
||||
#### Duty Cycle Output ("dPWM")
|
||||
|
||||
@@ -172,14 +207,15 @@ C++/Java implementation note: these are created as SimDevice nodes where the dev
|
||||
|
||||
A relative encoder. For absolute encoders, use ``"DutyCycle"``.
|
||||
|
||||
| Data Key | Type | Description |
|
||||
| --------------------- | ------- | --------------------------------------------------- |
|
||||
| ``"<init"`` | Boolean | If encoder is initialized in the robot program |
|
||||
| ``"<channel_a"`` | Integer | Digital channel number for “A” phase |
|
||||
| ``"<channel_b"`` | Integer | Digital channel number for “B” phase |
|
||||
| ``"<samples_to_avg"`` | Integer | Number of samples to average for period measurement |
|
||||
| ``">count"`` | Integer | Accumulated count (pulses) |
|
||||
| ``">period"`` | Float | Period between pulses in seconds |
|
||||
| Data Key | Type | Description |
|
||||
| ------------------------ | ------- | --------------------------------------------------- |
|
||||
| ``"<init"`` | Boolean | If encoder is initialized in the robot program |
|
||||
| ``"<channel_a"`` | Integer | Digital channel number for “A” phase |
|
||||
| ``"<channel_b"`` | Integer | Digital channel number for “B” phase |
|
||||
| ``"<samples_to_avg"`` | Integer | Number of samples to average for period measurement |
|
||||
| ``">count"`` | Integer | Accumulated count (pulses) |
|
||||
| ``">period"`` | Float | Period between pulses in seconds |
|
||||
| ``"<reverse_direction"`` | Boolean | If the encoder direction should be inverted |
|
||||
|
||||
#### Gyro ("Gyro")
|
||||
|
||||
@@ -201,6 +237,19 @@ C++/Java implementation note: these are created as SimDevice nodes where the dev
|
||||
| ``">rate_y"`` | Float | The current gyro angular rate of change in degrees/second |
|
||||
| ``">rate_z"`` | Float | The current gyro angular rate of change in degrees/second |
|
||||
|
||||
#### HAL Data ("HAL")
|
||||
|
||||
[``"HAL"``]:#hal-data-hal
|
||||
|
||||
Only sent in XRP mode.
|
||||
|
||||
Only one of ``">sim_periodic_before"`` or ``">sim_periodic_after"`` should be sent in a single message.
|
||||
|
||||
| Data Key | Type | Description |
|
||||
| -------------------------- | ------- | -------------------------------------------------------------- |
|
||||
| ``">sim_periodic_before"`` | Boolean | Sent by the robot before running periodic simulation functions |
|
||||
| ``">sim_periodic_after"`` | Boolean | Sent by the robot after running periodic simulation functions |
|
||||
|
||||
#### Joystick Data ("Joystick")
|
||||
|
||||
[``"Joystick"``]:#joystick-data-joystick
|
||||
@@ -215,17 +264,34 @@ Joystick data is an input to the robot program and should be updated for each in
|
||||
| ``"<rumble_left"`` | Float | Left rumble, value is 0-1 range |
|
||||
| ``"<rumble_right"`` | Float | Right rumble, value is 0-1 range |
|
||||
|
||||
#### PCM Data ("CTREPCM")
|
||||
|
||||
[``"CTREPCM"``]#pcm-data-ctrepcm
|
||||
|
||||
A pneumatic control module is used to regulate the pressure in a pneumatic system by switching a compressor on or off.
|
||||
|
||||
| Data Key | Type | Description |
|
||||
| ---------------------- | ------- | ------------------------------------------ |
|
||||
| ``"<init"`` | Boolean | If PCM is initialized in the robot program |
|
||||
| ``">on"`` | Boolean | Whether the compressor is running |
|
||||
| ``"<closed_loop"`` | Boolean | Whether closed-loop control is enabled |
|
||||
| ``">pressure_switch"`` | Boolean | The value of the pressure switch |
|
||||
| ``">current"`` | Float | The amount of current being drawn by the compressor, in Amps |
|
||||
|
||||
#### PWM Output ("PWM")
|
||||
|
||||
[``"PWM"``]:#pwm-output-pwm
|
||||
|
||||
PWMs may be used to control either motor controllers or servos. Typically only one of either ``"<speed"`` (for a motor controller) or ``"<position"`` (for a servo) is used for a given PWM.
|
||||
PWMs may be used to control either motor controllers or servos. Typically only one of either ``"<speed"`` (for a motor controller) ``"<position"`` (for a servo), or ``"raw"`` is used for a given PWM.
|
||||
|
||||
| Data Key | Type | Description |
|
||||
| --------------- | ------- | ------------------------------------------ |
|
||||
| ``"<init"`` | Boolean | If PWM is initialized in the robot program |
|
||||
| ``"<speed"`` | Float | Speed, -1.0 to 1.0 range |
|
||||
| ``"<position"`` | Float | Servo position, 0.0 to 1.0 range |
|
||||
| Data Key | Type | Description |
|
||||
| ------------------- | ------- | ------------------------------------------ |
|
||||
| ``"<init"`` | Boolean | If PWM is initialized in the robot program |
|
||||
| ``"<speed"`` | Float | Speed, -1.0 to 1.0 range |
|
||||
| ``"<position"`` | Float | Servo position, 0.0 to 1.0 range |
|
||||
| ``"<raw"`` | Integer | The pulse time in microseconds |
|
||||
| ``"<period_scale"`` | Integer | Scales the PWM signal by squelching setting a 2-bit mask of outputs to squelch (ex. `1` -> squelch every other value; `3` -> squelch 3 of 4 values) |
|
||||
| ``"<zero_latch"`` | Boolean | Whether the PWM should be latched to 0 |
|
||||
|
||||
#### Relay Output ("Relay")
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
asyncapi: 2.0.0
|
||||
info:
|
||||
title: WPILib WebSocket Remote Endpoint API
|
||||
version: "1.0.0"
|
||||
version: "1.1.0"
|
||||
description: |
|
||||
API to route WPILib HAL calls over WebSockets.
|
||||
license:
|
||||
@@ -40,14 +40,18 @@ components:
|
||||
type: object
|
||||
oneOf:
|
||||
- $ref: "#/components/schemas/accelData"
|
||||
- $ref: "#/components/schemas/addressableLEDData"
|
||||
- $ref: "#/components/schemas/aiData"
|
||||
- $ref: "#/components/schemas/aoData"
|
||||
- $ref: "#/components/schemas/dioData"
|
||||
- $ref: "#/components/schemas/dpwmData"
|
||||
- $ref: "#/components/schemas/driverstationData"
|
||||
- $ref: "#/components/schemas/dutycycleData"
|
||||
- $ref: "#/components/schemas/encoderData"
|
||||
- $ref: "#/components/schemas/gyroData"
|
||||
- $ref: "#/components/schemas/halData"
|
||||
- $ref: "#/components/schemas/joystickData"
|
||||
- $ref: "#/components/schemas/pcmData"
|
||||
- $ref: "#/components/schemas/pwmData"
|
||||
- $ref: "#/components/schemas/relayData"
|
||||
- $ref: "#/components/schemas/solenoidData"
|
||||
@@ -88,6 +92,49 @@ components:
|
||||
type: number
|
||||
description: "Acceleration in G’s "
|
||||
|
||||
addressableLEDData:
|
||||
type: object
|
||||
required:
|
||||
- type
|
||||
- device
|
||||
properties:
|
||||
type:
|
||||
type: string
|
||||
description: Device Type (e.g. DIO/AI/PWM/Encoder etc)
|
||||
const: AddressableLED
|
||||
device:
|
||||
type: string
|
||||
description: Arbitrary device number
|
||||
data:
|
||||
type: object
|
||||
description: "Addressable LED Data (type: AddressableLED, device: arbitrary)"
|
||||
properties:
|
||||
<init:
|
||||
type: boolean
|
||||
description: "If the led strip is initialized in the robot program"
|
||||
"<output_port":
|
||||
type: integer
|
||||
description: "DIO pin number"
|
||||
"<length":
|
||||
type: integer
|
||||
description: "The number of leds in the strip"
|
||||
"<running":
|
||||
type: boolean
|
||||
description: "Whether the strip is outputting data"
|
||||
"<data":
|
||||
type: array
|
||||
description: "One value per led"
|
||||
items:
|
||||
type: object
|
||||
description: "An object with \"r\", \"g\", and \"b\" keys, representing the rgb (0-255) components of the color"
|
||||
properties:
|
||||
r:
|
||||
type: integer
|
||||
g:
|
||||
type: integer
|
||||
b:
|
||||
type: integer
|
||||
|
||||
aiData:
|
||||
type: object
|
||||
required:
|
||||
@@ -108,9 +155,54 @@ components:
|
||||
<init:
|
||||
type: boolean
|
||||
description: "If analog input is initialized in the robot program"
|
||||
"<avg_bits":
|
||||
type: integer
|
||||
description: "The number of averaging bits"
|
||||
"<oversample_bits":
|
||||
type: integer
|
||||
description: "The number of oversampling bits"
|
||||
">voltage":
|
||||
type: number
|
||||
description: "Input voltage, in volts"
|
||||
"<accum_init":
|
||||
type: boolean
|
||||
description: "If the accumulator is initialized in the robot program"
|
||||
">accum_value":
|
||||
type: integer
|
||||
description: "The accumulated value"
|
||||
">accum_count":
|
||||
type: integer
|
||||
description: "The number of accumulated values"
|
||||
"<accum_center":
|
||||
type: integer
|
||||
description: "The center value of the accumulator"
|
||||
"<accum_deadband":
|
||||
type: integer
|
||||
description: "The accumulator's deadband"
|
||||
|
||||
aoData:
|
||||
type: object
|
||||
required:
|
||||
- type
|
||||
- device
|
||||
properties:
|
||||
type:
|
||||
type: string
|
||||
description: Device Type (e.g. DIO/AI/PWM/Encoder etc)
|
||||
const: AO
|
||||
device:
|
||||
type: string
|
||||
description: Device Identifier (usually channel)
|
||||
data:
|
||||
type: object
|
||||
description: "Analog Output Data (type: AO, device: channel number)"
|
||||
properties:
|
||||
<init:
|
||||
type: boolean
|
||||
description: "If analog output is initialized in the robot program"
|
||||
"<voltage":
|
||||
type: number
|
||||
description: "Output voltage, in volts"
|
||||
|
||||
dioData:
|
||||
type: object
|
||||
@@ -138,6 +230,9 @@ components:
|
||||
<>value:
|
||||
type: boolean
|
||||
description: "Input or output state"
|
||||
"<pulse_length":
|
||||
type: number
|
||||
description: "Reserved for future use"
|
||||
|
||||
dpwmData:
|
||||
type: object
|
||||
@@ -275,6 +370,9 @@ components:
|
||||
">period":
|
||||
type: number
|
||||
description: "Period between pulses in seconds"
|
||||
"<reverse_direction":
|
||||
type: boolean
|
||||
description: "If the encoder direction should be inverted"
|
||||
|
||||
gyroData:
|
||||
type: object
|
||||
@@ -321,6 +419,31 @@ components:
|
||||
type: number
|
||||
description: "The current gyro angular rate of change in degrees/second"
|
||||
|
||||
halData:
|
||||
type: object
|
||||
required:
|
||||
- type
|
||||
- device
|
||||
properties:
|
||||
type:
|
||||
type: string
|
||||
description: Device Type (e.g. DIO/AI/PWM/Encoder etc)
|
||||
const: HAL
|
||||
device:
|
||||
type: string
|
||||
description: "\"HAL\""
|
||||
const: HAL
|
||||
data:
|
||||
type: object
|
||||
description: "HAL Data (type: HAL, device: HAL)"
|
||||
properties:
|
||||
">sim_periodic_before":
|
||||
type: boolean
|
||||
description: "Sent by the robot before running periodic simulation functions"
|
||||
">sim_periodic_after":
|
||||
type: boolean
|
||||
description: "Sent by the robot after running periodic simulation functions"
|
||||
|
||||
joystickData:
|
||||
type: object
|
||||
required:
|
||||
@@ -368,6 +491,36 @@ components:
|
||||
minimum: 0.0
|
||||
maximum: 1.0
|
||||
|
||||
pcmData:
|
||||
type: object
|
||||
required:
|
||||
- type
|
||||
- device
|
||||
properties:
|
||||
type:
|
||||
type: string
|
||||
description: Device Type (e.g. DIO/AI/PWM/Encoder etc)
|
||||
const: CTREPCM
|
||||
device:
|
||||
type: string
|
||||
description: Device Identifier (usually channel)
|
||||
data:
|
||||
<init:
|
||||
type: boolean
|
||||
description: "If PCM is initialized in the robot program"
|
||||
">on":
|
||||
type: boolean
|
||||
description: "Whether the compressor is running"
|
||||
"<closed_loop":
|
||||
type: boolean
|
||||
description: "Whether closed-loop control is enabled"
|
||||
">pressure_switch":
|
||||
type: boolean
|
||||
description: "The value of the pressure switch"
|
||||
">current":
|
||||
type: number
|
||||
description: "The amount of current being drawn by the compressor, in Amps"
|
||||
|
||||
pwmData:
|
||||
type: object
|
||||
required:
|
||||
@@ -398,6 +551,15 @@ components:
|
||||
description: "Servo position"
|
||||
minimum: 0.0
|
||||
maximum: 1.0
|
||||
"<raw":
|
||||
type: integer
|
||||
description: "The pulse time in microseconds"
|
||||
"<period_scale":
|
||||
type: integer
|
||||
description: "Scales the PWM signal by squelching setting a 2-bit mask of outputs to squelch (ex. `1` -> squelch every other value; `3` -> squelch 3 of 4 values)"
|
||||
"<zero_latch":
|
||||
type: boolean
|
||||
description: "Whether the PWM should be latched to 0"
|
||||
|
||||
relayData:
|
||||
type: object
|
||||
|
||||
@@ -51,7 +51,7 @@ void HALSimWSProviderAddressableLED::RegisterCallbacks() {
|
||||
}
|
||||
|
||||
wpi::json payload;
|
||||
payload[">data"] = jsonData;
|
||||
payload["<data"] = jsonData;
|
||||
|
||||
provider->ProcessHalCallback(payload);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user