-
Notifications
You must be signed in to change notification settings - Fork 0
Networking
Client interact with simulation via 2 different channels for video and control.
- video default port is
44209
- control default port is
44210
All packets are TCP/IP
. Data length is equal to 0 when packet doesn't have data. Data length is in little endian.
IMPORTANT Video request packet is only 1 byte long, it is just packet type byte!
Packet type | Packet flag | Data length as int32 | Data |
---|---|---|---|
1 byte | 1 byte | 4 bytes | n bytes |
Value | Abbreviation | Description |
---|---|---|
0 |
NONE | No flags |
1 |
SERVER_ECHO | If client packet has this flag, server will respond with additional ACK packet |
2 |
DO_NOT_LOG_PACKET | Information that the packet should not be logged (for very repetitive packets like GET_SENS. Server will not log this packet in log file |
128 |
TEST | Test flag |
This channel is responsible for controlling simulation: steering the robot, recording data etc. Not all packets include data so see packets structure. All non-binary data is in ASCII JSON format. All packets types are listed in the table below.
Packet types bytes are groped by activity they are connected with:
-
0x00
to0x9F
unused -
0xA0
to0xAF
motors -
0xB0
to0xBF
sensors -
0xC0
to0xCF
simulation -
0xD0
to0xDF
data (e.g. getting object detection) -
0xE0
to0xEF
unused -
0xF0
to0xFF
unused
If packet is GET_*
client cannot change the parameter.
If packet is SET_*
client can request the current value (with data length equals to zero) apart from changing it.
If packet is send without data, server will respond with current values e.g.
response to SET_CONTROL_MODE request without data will be the current mode.
Byte | Abbreviation | Description | JSON from client | JSON from server | Working |
---|---|---|---|---|---|
0xA0 |
SET_MTR | Sets motor power | {FLH, FLV, BLV, BLH, FRH, FRV, BRV, BRH} |
Yes | |
0xA1 |
ARM_MTR | Arms motors | Yes | ||
0xA2 |
DISARM_MTR | Disarms motors | Yes | ||
0xA3 |
SET_CONTROL_MODE | Sets control mode | mode |
Yes | |
0xA4 |
SET_ACRO | Sets Acro mode values | {rotSpeed, vel} |
||
0xA5 |
SET_STABLE | Sets Stable mode values | {rot, vel, depth} |
Yes | |
0xA6 |
SET_PID | Sets motors PIDs | {roll, pitch, yaw, depth, rollSpeed, pitchSpeed, yawSpeed} |
Yes | |
0xB0 |
GET_SENS | Gets sensors read outs | {rot, rotSpeed, accel, rotAccel, baro} |
Yes | |
0xB1 |
GET_DEPTH | Requests depth texture | depth |
Yes | |
0xB2 |
GET_DEPTH_BYTES | Requests depth texture | binary data |
Yes | |
0xB3 |
GET_VIDEO_BYTES | Requests video frame | binary data |
Yes | |
0xB4 |
GET_VIDEO | Requests video frame | frame |
||
0xC0 |
SET_SIM | Sets simulation options | quality |
||
0xC1 |
ACK | Acknowledgement | Yes | ||
0xC3 |
SET_ORIEN | Sets Okon’s orientation | {pos, rot} |
Yes | |
0xC4 |
RST_SIM | Resets simulation | Yes | ||
0xC5 |
PING | Sends ping to server | {timestamp, ping} |
{timestamp, ping} |
Yes |
0xC6 |
GET_CPS | Requests checkpoints state | [{id,reached}, ...] |
Yes | |
0xC7 |
HIT_NGZ | Transmits when Okon hits NGZ | id |
Yes | |
0xC8 |
HIT_FZ | Transmits when Okon hits FZ | id |
Yes | |
0xC9 |
CHK_AP | Checks actionpoint state | id |
active |
Yes |
0xCA |
ERROR | Informs about server side error | {info, jsonFromClient} |
Yes | |
0xDE |
GET_DETE | Gets object detection | [{visibleInFrame, min, max, fill, className, distance, colorPercentVisible}, ...] |
Yes | |
0xFF |
0xFF | Illegal packet. Breaks connection | Yes |
Packet sets thrusters power and direction. FLH, FLV, BLV, BLH, FRH, FRV, BRV, BRH
are abbreviations e.g. FLH
FrontLeftHorizontal
thruster ([H]orizontal, [V]ertical). Values are in range from -1.0f
to 1.0f
.
JSON structure:
- FLH
- FLV
- BLV
- BLH
- FRH
- FRV
- BRV
- BRH
Example request {"FLH":0.0,"FLV":0.0,"BLV":0.0,"BLH":0.0,"FRH":0.0,"FRV":0.0,"BRV":0.0,"BRH":0.0}
Packet arms motors. Without being armed, motors will not spin.
Packet disarms motors. Without being armed, motors will not spin.
Packet sets robots control mode:
-
stable
- robot will keep set rotation -
acro
- robot will keep set rotation speed -
manual
- robot will not correct its rotation
Packet sets desired rotation speed and velocity in local coordinate system.
JSON structure:
- rotSpeed
- x
- y
- z
- vel
- x
- y
- z
Example request {"rotSpeed":{"x":0,"y":0,"z":0},"vel":{"x":0,"y":0,"z":0}}
Packet sets desired rotation and velocity in local coordinate system.
JSON structure:
- rot
- x
- y
- z
- vel
- x
- y
- z
- depth
Example request {"rot":{"x":0,"y":0,"z":0},"vel":{"x":0,"y":0,"z":0},"depth":1.0}
Packet sets motors PIDs. WindupCapt limits max integral value. Limit limits max PID output from -limit to limit. Variables in each PID has the same structure.
JSON structure:
- roll
- p
- i
- d
- windupCap
- gain
- limit
- pitch
- ...
- yaw
- ...
- depth
- ...
- rollSpeed
- ...
- pitchSpeed
- ...
- yawSpeed
- ...
Example request {"roll":{"p":0.4,"i":0,"d":0.03,"windupCap":1,"gain":1,"limit":0.5},"pitch":{"p":0.7,"i":0,"d":0.1,"windupCap":1,"gain":1,"limit":0.5},"yaw":{"p":0.3,"i":0,"d":0.04,"windupCap":1,"gain":1,"limit":0.5},"depth":{"p":10,"i":0,"d":4,"windupCap":1,"gain":1,"limit":0.5},"rollSpeed":{"p":0,"i":0,"d":0,"windupCap":0,"gain":0,"limit":0},"pitchSpeed":{"p":0,"i":0,"d":0,"windupCap":0,"gain":0,"limit":0},"yawSpeed":{"p":0,"i":0,"d":0,"windupCap":0,"gain":0,"limit":0}}
Packet requests current values of on-board sensors (gyroscope, accelerometer and barometer). Values x, y, z
for rot
are in degrees.
JSON structure:
- rot
- x
- y
- z
- rotSpeed
- x
- y
- z
- accel
- x
- y
- z
- rotAccel
- x
- y
- z
- baro
- pressure
Example response {"rot":{"x":-9.81e-16,"y":180.0,"z":5.269e-7},"rotSpeed":{"x":1.2e-9,"y":1.41e-11,"z":2.282e-11},"accel":{"x":4.0e-16,"y":0.084,"z":-5.37e-17},"rotAccel":{"x":6.2e-11,"y":7.024e-13,"z":1.13e-12},"baro":{"pressure":11115.315}}
Packet requests depth map.
Example response BASE64_DEPTH_IMAGE_STRING
Packet requests depth map.
binary data containing JPG/PNG encoded image
Packet requests video frame.
binary data containing JPG/PNG encoded image
Packet requests video frame.
Example response BASE64_VIDEO_FRAME_STRING
This packet allows to set the compression level of the frame. Value of the quality is in range from 0
to 100
(see settings file).
JSON structure
- quality
Packet checks if the connection is still working. Server sends ACK each second of inactivity. If client send ACK server will respond with some dummy JSON.
Packet allows to set position and rotation of the robot in simulation's world space. Rotation values are in degrees.
JSON structure:
- rot
- x
- y
- z
- pos
- x
- y
- z
Example request {"rot":{"x":0.0,"y":0.0,"z":0.0},"pos":{"x":1.0900000095367432,"y":-0.89980505108833314,"z":-2.7100000381469728}}
Packet restart mission by randomizing Okons orientation and reseting all checkpoints. Packet is broadcasted to all connected clients.
Packet allows to measure ping between client and simulation. Server sends back the exact copy of clients packet.
Packet allows to retrive all checkpoints state. JSON structure:
- Array
- Object
- id
- reached
- ...
- Object
Example response [{"id":"chk1","reached":true},{"id":"chk2","reached":false}]
Packet send to all clients when Okon swims into No Go Zone.
Example response "NGZ1"
Packet send to all clients when Okon swims into Finish Zone. JSON structure:
- id
Example response {"id":"FZ1"}
Packet allows to checks if Okon is in a given actionpoint. If no data in request server will respond with ids of all action points. JSON structure:
- active
Example request {"id":"AP1"}
Example response true
Packet is send e.g. when client sends to server unknown packet.
JSON structure:
- info
- fromClient
Example response {"info":"Unknown dataframe type","fromClient":"someGarbageFromClient"}
Packet requests detection info. Array of all objects in simulation is send. Each object info will have information if it is in frame and visible. Min and max variables define bounding box around the object. Fill tells how much space on the image the bounding box uses. JSON structure:
- Array
- Object
- visibleInFrame
- min
- x
- y
- max
- x
- y
- fill
- className
- distance
- colorPercentVisible
- ...
- Object
If client sends this packet type, server will close the connection. Do not send this packet type.