User code: - OpModeRobot used as the robot base class - LinearOpMode and PeriodicOpMode are provided opmode base classes - In Java, annotations can be used to automatically register opmode classes Additional user code functionality: - OpMode (string) is available in addition to the overall auto/teleop/test robot mode - OpMode does not indicate enable (enable/disable is still separate) - The HAL API uses integer UIDs; these are exposed at the user API level as well for faster checks - User code creates opmodes on startup (these have name, category, description, etc). DS: - DS will present opmode selection lists for auto and teleop for match/practice. During a match, the DS will automatically activate the selected opmode in the corresponding match period. - For testing, an overall mode is selected (e.g. teleop/auto/test) and a single opmode is selected Future work: - Command framework support/integration - Python annotation support - Unit tests (needs race-free DS sim updates) - Porting of examples Co-authored-by: Joseph Eng <91924258+KangarooKoala@users.noreply.github.com>
HAL XRP Client
This is an extension that provides a client version of the XRP protocol for transmitting robot hardware interface state to an XRP robot over UDP.
Configuration
The XRP client has a number of configuration options available through environment variables.
HALSIMXRP_HOST: The host to connect to. Defaults to localhost.
HALSIMXRP_PORT: The port number to connect to. Defaults to 3540.
XRP Protocol
The WPILib -> XRP protocol is binary-based to save on bandwidth due to hardware limitations of the XRP robot. The messages to/from the XRP follow a the format below:
| 2 bytes | 1 byte | n bytes |
|---|---|---|
| uint16_t sequence | uint8_t control | <Tagged Data> |
Control Byte
The control byte is used to indicate the current enabled state of the WPILib robot code. When this is set to 1, the robot is enabled, and when it is set to 0 it is disabled.
Messages originating from the XRP have an unspecified value for the control byte.
Tagged Data
The Tagged Data section can contain an arbitrary number of data blocks. Each block has the format below:
| 1 byte | 1 byte | n bytes |
|---|---|---|
| uint8_t size | uint8_t tagID | <payload> |
The size byte encodes the size of the data block, excluding itself. Thus the smallest block size is 2 bytes, with a size value of 1 (1 size byte, 1 tag byte, 0 payload bytes). Maximum size of the payload is 254 bytes.
Utilizing tagged data blocks allows us to send multiple pieces of data in a single UDP packet. The tags currently implemented for the XRP are as follows:
| Tag | Description |
|---|---|
| 0x12 | XRPMotor |
| 0x13 | XRPServo |
| 0x14 | DIO |
| 0x15 | AnalogIn |
| 0x16 | XRPGyro |
| 0x18 | Encoder |
XRPMotor
| Order | Data Type | Description |
|---|---|---|
| 0 | uint8_t | ID |
| 1 | float | Value [-1.0, 1.0] |
IDs:
| ID | Description |
|---|---|
| 0 | Left Motor |
| 1 | Right Motor |
| 2 | Motor 3 |
| 3 | Motor 4 |
XRPServo
| Order | Data Type | Description |
|---|---|---|
| 0 | uint8_t | ID |
| 1 | float | Value [0.0, 1.0] |
IDs:
| ID | Description |
|---|---|
| 4 | Servo 1 |
| 5 | Servo 2 |
DIO
| Order | Data Type | Description |
|---|---|---|
| 0 | uint8_t | ID |
| 1 | uint8_t | Value (True/False) |
AnalogIn
| Order | Data Type | Description |
|---|---|---|
| 0 | uint8_t | ID |
| 1 | float | Value |
XRPGyro
| Order | Data Type | Description |
|---|---|---|
| 0 | float | rate_x (dps) |
| 1 | float | rate_y (dps) |
| 2 | float | rate_z (dps) |
| 3 | float | angle_x (deg) |
| 4 | float | angle_y (deg) |
| 5 | float | angle_z (deg) |
Encoder
| Order | Data Type | Description |
|---|---|---|
| 0 | uint8_t | ID |
| 1 | int32_t | Count |
| 2 | uint32_t | Period Numerator |
| 3 | uint32_t | Period Denominator |
IDs:
| ID | Description |
|---|---|
| 0 | Left Motor Encoder |
| 1 | Right Motor Encoder |
| 2 | Motor 3 Encoder |
| 3 | Motor 4 Encoder |