Skip to content

Sockets of a Session#

A session of the game can open three local sockets. The server core_sim of ACRES Core opens the same sockets. Thus one client, for example the ROS 2 bridge sim_bridge, operates with the two simulators.

Each socket listens on 127.0.0.1 only. A program on a different computer cannot connect.

Socket Game Option Default Port of the Launch Files Direction Content
Vehicle bridge -RlPort= 5556 Both Commands to one vehicle and reports from it. JSON lines.
Sensor stream -SensorStream= 5601 Out The clock, the INS epochs, the LiDAR clouds and the camera images of one vehicle. Binary frames.
Simulator control channel -SimControl= 5600 Both Pause, step, reset, entities, conditions, recording and replay of the session. JSON lines.

With more than one agent, -RlPorts= and -SensorStreams= give one port for each agent. There is one control channel for the session.

Vehicle Bridge#

Source: Game/Source/Acres/AcresRlBridge.h (header reference).

The bridge is newline-delimited JSON over TCP. It accepts one client at a time. The Maxxum also has a J1939 CAN transport: -RlCan=IFACE (SocketCAN) or -RlCanUdp=PORT (the same 16-byte frames over UDP).

Simulated J1939 bus of the Maxxum: the game encodes the vehicle signals into frames, the CAN transport carries them to the ROS 2 bridge or to a controller, and the command frames come back. GAME, MAXXUM Vehicle signals engine, wheels, steering, pose, slip, soil, implement each 0.1 s PGN encoder SendCan() 13 frames, 0xFF1F last To the controller: EEC1, WBSD, Guidance Machine Status, Proprietary B 0xFF10 to 0xFF18, 0xFF1F. To the tractor: Guidance System Command, TSC1, XBR, Proprietary A. Vehicle controls steering, throttle, brake, differential lock, reset applied by arrival time PGN decoder HandleCanFrame() source address 0x2A only Sensor recorder 2 frames at can.hz, 20 Hz can.jsonl EEC1 and PGN 65280 CAN transport -RlCanUdp=<port> UDP on 127.0.0.1, 16-byte can_frame -RlCan=<interface> SocketCAN can/rx ROS 2 bridge sim_bridge can_msgs/Frame can/tx Controller ROS 2 node or ECU, address 0x2A In lockstep, the frame 0xFF1E ends the frames of each step request. The ROS 2 bridge counts this frame and does not publish it. A controller without ROS 2 connects directly to the UDP port or to the SocketCAN interface.
The game encodes the vehicle signals into frames. A controller sends the command frames. Open the diagram

The CAN bus sends the observation of the vehicle bridge as J1939 frames each 0.1 s. It is a simulator interface in the format of SAE J1939 and ISO 11783, not a copy of the network of a real Maxxum. It has no arbitration, no address claim and no transport protocol. The signals have no noise. The game accepts command frames only from the source address 0x2A. The codec tests are Vehicle/ROS/acres_sim/test/test_j1939.cpp and test_j1939_golden.py.

  • Game to client. While a client is connected, the game sends one observation each 0.1 s of simulation time. It has the time, the pose, the velocity, the wheel slips, the steering and the engine speed. It also has the soil water, 16 LiDAR ranges and the state of the implement. Each observation has the keys agent and vehicle.
  • Client to game, Maxxum. An object with any of the keys steer (-1 to 1), pedal (-1 to 1), difflock, gear, direction (1 forward, -1 reverse), curvature, implement, reset, env_clock, workers, cmd and hud.
  • Client to game, Polaris. The drive-by-wire messages with the field names and units of ds_dbw_msgs 2.3.11: dbw, steering_cmd, throttle_cmd, brake_cmd, gear_cmd and ulc_cmd. Send each command at 20 Hz to 100 Hz. The model drops a subsystem 0.1 s after its last message, as the vehicle does.

While a Polaris bridge has a client, it sends one line dbw_report at 50 Hz of simulation time with all reports of one instant (the fields of the report messages of ds_dbw_msgs). In lockstep, the bridge sends a barrier line {"type":"barrier","step":N} at the end of each step request. All observations and reports of the steps are before it.

A receiver thread stamps each message with its arrival time. The game then applies the message at the physics step that matches that time (Time Stepping).

Sensor Stream#

Source: Game/Source/Acres/AcresSensorStream.h (header reference).

A frame is a 32-byte header and a payload, little-endian. The header has the magic TSS1, the frame type, the flags, a sequence number and the payload size. It also has the simulation time of the data and the publish time.

Type Frame Rate Payload
1 Hello First frame of each connection JSON: the agent, the vehicle, the sensor rates, the LiDAR layout, the camera intrinsics and the mount poses
2 Clock Each physics step (120 Hz) The physics time of the vehicle
3 Ins ins.hz of the sensor file The INS values
4 Lidar Each scan An organized cloud: columns x rings x (x, y, z, intensity) float32, NaN for no return
5 Camera Each image A bgr8 image after the camera model
6 Barrier Lockstep only The world step that a step request reached

With -SensorShm, a camera frame has no pixels. The image is in /dev/shm/acres_<agent>_camera (or _camera_rear).

The stream starts the sensor recorder of the vehicle without files. Add -SensorRecord to also write the files.

Simulator Control Channel#

Source: Game/Source/Acres/AcresSimControl.cpp (header reference).

The channel is newline-delimited JSON over TCP. It accepts one client at a time. When a client connects, the simulator sends an episode event. The game disconnects a client when more than 8 MiB of replies wait.

A request is an object with the key op, an optional id and the fields of the operation. The reply has the same id, ok, result and an optional error text. The result codes are those of simulation_interfaces:

Code Meaning
0 Not supported (an unknown operation)
1 OK
2 Not found
3 Incorrect state, for example a step request while a step runs
4 Failed, for example a line that is not a JSON object

The states are 0 (stopped), 1 (playing), 2 (paused) and 3 (quitting). -Lockstep starts the session in state 2.

Operations#

Operation Function
hello The description of the session: the map, the episode and the agents.
get_state, set_state The simulation state.
step Runs steps physics steps (default 1). The simulation must be paused. The reply comes when the physics did the steps and the sensors of each agent are idle.
step_agents Gives the drive-by-wire commands of each agent, then a step. The reply has the pose of each agent.
reset Resets the world.
get_entities, get_entity_state, set_entity_state, spawn_entity, delete_entity, get_spawnables, get_named_poses The entities of the session and their poses.
set_conditions The weather, the clock, the soil water and a field restore.
set_vehicle_shift, get_vehicle_shifts The hardware shifts of the vehicles.
record Starts or stops the episode log.
replay Gives the running session the next episode log to replay.
route, objects A route on the map, and the objects on the path.
clock, observe, skill The planner support: the clock, the observation and a skill request (interface acres-interface-1, the lists of Config/schemas/skills.json).
farm_state, field_query, region_probe, region_crop_crush Queries and changes of the farm.
screenshot, view, capture, key The main view, a screenshot, a sensor capture and a key press.

The channel refuses a reset or an entity change while a step runs.

Lockstep#

Time Stepping and Determinism gives the steps of a request in lockstep and the barrier on each data channel.

Clients#

  • Tools/SimControl/sim_control.py: a Python client with only the standard library.
  • sim_bridge (package acres_sim): the ROS 2 services of ROS 2 Services and Actions.
import sys
sys.path.insert(0, "Tools/SimControl")
from sim_control import SimControl

ctl = SimControl(5600)
print(ctl.call("get_state"))