|
| 1 | +# HAL XRP Client |
| 2 | + |
| 3 | +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. |
| 4 | + |
| 5 | +## Configuration |
| 6 | + |
| 7 | +The XRP client has a number of configuration options available through environment variables. |
| 8 | + |
| 9 | +``HALSIMXRP_HOST``: The host to connect to. Defaults to localhost. |
| 10 | + |
| 11 | +``HALSIMXRP_PORT``: The port number to connect to. Defaults to 3540. |
| 12 | + |
| 13 | +## XRP Protocol |
| 14 | + |
| 15 | +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: |
| 16 | + |
| 17 | +| 2 bytes | 1 byte | n bytes | |
| 18 | +|---------------------|-------------------|-------------------------------------| |
| 19 | +| _uint16_t_ sequence | _uint8_t_ control | [<Tagged Data>](#tagged-data) | |
| 20 | + |
| 21 | +### Control Byte |
| 22 | + |
| 23 | +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. |
| 24 | + |
| 25 | +Messages originating from the XRP have an unspecified value for the control byte. |
| 26 | + |
| 27 | +### Tagged Data |
| 28 | + |
| 29 | +The `Tagged Data` section can contain an arbitrary number of data blocks. Each block has the format below: |
| 30 | + |
| 31 | +| 1 byte | 1 byte | n bytes | |
| 32 | +|----------------|-----------------|-----------------| |
| 33 | +| _uint8_t_ size | _uint8_t_ tagID | <payload> | |
| 34 | + |
| 35 | +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. |
| 36 | + |
| 37 | + |
| 38 | +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: |
| 39 | + |
| 40 | +| Tag | Description | |
| 41 | +|------|-------------------------------| |
| 42 | +| 0x12 | [XRPMotor](#xrpmotor) | |
| 43 | +| 0x13 | [XRPServo](#xrpservo) | |
| 44 | +| 0x14 | [DIO](#dio) | |
| 45 | +| 0x15 | [AnalogIn](#analogin) | |
| 46 | +| 0x16 | [XRPGyro](#xrpgyro) | |
| 47 | +| 0x17 | [BuiltInAccel](#builtinaccel) | |
| 48 | +| 0x18 | [Encoder](#encoder) | |
| 49 | + |
| 50 | + |
| 51 | +#### XRPMotor |
| 52 | + |
| 53 | +| Order | Data Type | Description | |
| 54 | +|-------|-----------|-------------------| |
| 55 | +| 0 | _uint8_t_ | ID | |
| 56 | +| 1 | _float_ | Value [-1.0, 1.0] | |
| 57 | + |
| 58 | +IDs: |
| 59 | +| ID | Description | |
| 60 | +|----|-------------| |
| 61 | +| 0 | Left Motor | |
| 62 | +| 1 | Right Motor | |
| 63 | +| 2 | Motor 3 | |
| 64 | +| 3 | Motor 4 | |
| 65 | + |
| 66 | +#### XRPServo |
| 67 | + |
| 68 | +| Order | Data Type | Description | |
| 69 | +|-------|-----------|------------------| |
| 70 | +| 0 | _uint8_t_ | ID | |
| 71 | +| 1 | _float_ | Value [0.0, 1.0] | |
| 72 | + |
| 73 | +IDs: |
| 74 | +| ID | Description | |
| 75 | +|----|-------------| |
| 76 | +| 4 | Servo 1 | |
| 77 | +| 5 | Servo 2 | |
| 78 | + |
| 79 | +#### DIO |
| 80 | + |
| 81 | +| Order | Data Type | Description | |
| 82 | +|-------|-----------|--------------------| |
| 83 | +| 0 | _uint8_t_ | ID | |
| 84 | +| 1 | _uint8_t_ | Value (True/False) | |
| 85 | + |
| 86 | +#### AnalogIn |
| 87 | + |
| 88 | +| Order | Data Type | Description | |
| 89 | +|-------|-----------|-------------| |
| 90 | +| 0 | _uint8_t_ | ID | |
| 91 | +| 1 | _float_ | Value | |
| 92 | + |
| 93 | +#### XRPGyro |
| 94 | + |
| 95 | +| Order | Data Type | Description | |
| 96 | +|-------|-----------|---------------| |
| 97 | +| 0 | _float_ | rate_x (dps) | |
| 98 | +| 1 | _float_ | rate_y (dps) | |
| 99 | +| 2 | _float_ | rate_z (dps) | |
| 100 | +| 3 | _float_ | angle_x (deg) | |
| 101 | +| 4 | _float_ | angle_y (deg) | |
| 102 | +| 5 | _float_ | angle_z (deg) | |
| 103 | + |
| 104 | +#### BuiltInAccel |
| 105 | + |
| 106 | +| Order | Data Type | Description | |
| 107 | +|-------|-----------|-------------| |
| 108 | +| 0 | _float_ | accel_x (g) | |
| 109 | +| 1 | _float_ | accel_y (g) | |
| 110 | +| 2 | _float_ | accel_z (g) | |
| 111 | + |
| 112 | +#### Encoder |
| 113 | + |
| 114 | +| Order | Data Type | Description | |
| 115 | +|-------|-----------|-------------| |
| 116 | +| 0 | _uint8_t_ | ID | |
| 117 | +| 1 | _int32_t_ | Value | |
| 118 | + |
| 119 | +IDs: |
| 120 | +| ID | Description | |
| 121 | +|----|---------------------| |
| 122 | +| 0 | Left Motor Encoder | |
| 123 | +| 1 | Right Motor Encoder | |
| 124 | +| 2 | Motor 3 Encoder | |
| 125 | +| 3 | Motor 4 Encoder | |
0 commit comments