Skip to content

The Game#

The game is the full simulator. It is one Unreal Engine 5.8 project in Game/ with one C++ module, Acres. It has the farm, the two vehicles, the implements, the weather, the farm traffic and all sensors.

Folders#

Folder Content
Game/Acres.uproject The project. The default map is /Game/Maps/ACRE. The game mode is AcresShellGameMode.
Game/Source/Acres The C++ code of the module.
Game/Config The engine, game and input settings (DefaultEngine.ini and the other .ini files).
Game/Content/Simulation The parameter files and the map products (Files and Formats).
Game/Content The assets: meshes, materials, the level. Most files are in Git LFS.
Game/Shaders The shaders of the project.
Tests/Game The tests of the engine-free models, with their own builds (Tests/Game/run.sh).
Game/Raw/farm-equipment The source assets of the implements and the Polaris (Blender files).

Two Layers of Code#

The code has two layers.

  1. The engine-free models. These files contain the mathematics. They use standard C++ and SI units, and no Unreal type. The model tests and ACRES Core compile the same files (ACRES Core).
  2. The Unreal layer. It owns the actors, the threads, the rendering, the sockets and the user interface. At each physics step, it fills the inputs of the models and applies their outputs.

Chaos, the physics engine of Unreal, integrates only the chassis body. The vehicle pawn computes each tire, soil and implement force itself and gives Chaos the totals.

File Groups#

All game code is in Game/Source/Acres. A name without an extension is a .h file and a .cpp file. C++ Headers gives the public declarations of each file.

Group Files Function
Vehicle pawn AcresVehicle, AcresVehicleControl.cpp, AcresPolaris.cpp The pawn of a vehicle, its physics step, its controls and the Polaris branch.
Vehicle models AcresVehicleModel, AcresUtvModel, AcresSimModel, AcresPowerModel The Maxxum, the Polaris with its drive-by-wire, the engine helpers, the fuel and the energy ledger.
Soil and ground AcresSoilModel, AcresSurfaceMap The soil library, the tire on soil, the surface class at a point.
Implements AcresImplementModel, AcresImplementCoupling, AcresFieldWorkModel, AcresRig The implement forces, their path to the chassis, the marks of field work, the skeletal rigs.
Agents and places AcresAgents, AcresPlaces, AcresGeoUtm.h The vehicles of a session, the named places, the UTM projection.
Farm AcresFarmRuntime, AcresFarmModel, AcresFieldSetup, AcresSoilVisuals, AcresCrops.h, AcresDriveRegion The crops, the soil water, the ruts, the field settings, the look of the ground and the regional ground.
Weather AcresEnvironment, AcresEnvironmentModel The sun, the clouds, the temperature, the wind, the rain and the clock.
Sensors AcresSensors, AcresCameraModel, AcresLidarModel, AcresLidarPhysics.h, AcresLidarGpu, AcresGnssModel The sensor recorder and the model of each sensor.
Rendering AcresRenderTier, AcresVideoCapture The render tiers, the sensor profile and the video capture.
Bridges AcresRlBridge, AcresCommandTiming.h, AcresSensorStream, AcresSimControl, AcresPathObjects The vehicle bridge with its timestamped command queue, the sensor stream, the simulator control channel and the objects on the path.
Logs AcresSessionLog, AcresEpisodeLog, AcresEpisodeSchemas.h, AcresReplay The session log, the episode log and the replay input.
Application AcresShell, AcresMenu, AcresSession, AcresHud.cpp, AcresNpc, AcresMapData The game mode, the menu, the session configuration, the HUD, the farm traffic and the map folder.

How a Session Starts#

How a session starts: the menu prepares a session folder with configuration copies and reloads the map with flags, or the command line gives the flags directly. The vehicle pawn reads the files and writes the logs. End Simulation loads the menu again. START GAME FILES Session folder Menu New Simulation, Replay Simulation, Pilot Prepare the session examines the settings, makes the session folder FAcresSession::Prepare Configuration copies session-config.json environment.json tractor.json sensors.json field-setup.json Command line -VehicleDemo -SessionLog -VehicleOutput= Map load with flags The game mode selects the pawn from the flags. /Game/Maps/ACRE Vehicle pawn reads the files, runs the physics at 120 Hz Logs tractor.csv session-summary.json sensors/episode-NNN/ farm-state.json and more farm files Start writes the copies flags and file paths, then the map loads again flags reads the copies logs Esc, then End Simulation: the logs close and the map loads with the menu
The menu makes a session folder and loads the map with options. The command line gives the options directly. Open the diagram

The menu does not build the simulation in the running map. It writes a session folder with copies of the configuration files. Then it starts the map again with -VehicleDemo -FromMenu -SessionMode=... -EnvConfig=... -VehicleConfig=... -VehicleOutput=... -FieldSetup=.... A command line can start the same session without the menu (Game Command Line).

The game mode makes agent 0. In its BeginPlay, agent 0 reads the agent list, makes the weather and the farm runtimes, and spawns the other agents. The other agents share the farm and the weather. When the command line asks for it, agent 0 then makes the simulator control.

Each agent has its own controls, sensors, bridge ports and logs.

Two vehicles in one session

One Physics Step#

One physics step of a vehicle: the pawn exchanges the controls, advances the weather and the farm, runs the steering and the drivetrain, examines each wheel contact, solves the driveline, sums the forces, gives them to Chaos and publishes the step. One physics step of a vehicle, 1/120 s INPUTS PHYSICS THREAD, IN THIS SEQUENCE OUTPUTS 1 Exchange the controls controls, bridge command, reset request 2 Examine the body mass properties, energy of the last step, reset 3 Advance the weather and the farm rain, soil water, crops (agent 0 only) 4 Select the control source hand throttle, park brake, automatic drivers 5 Steering and drivetrain StepSteering, StepDrivetrain 6 Each wheel: contact ray cast, surface, soil state PrepareWheel 7 Driveline solve SolveDriveline wheel speeds, clutch, fuel 8 Each wheel: forces and marks tyre forces, water drag, ruts, crushed crop 9 Air drag and implement implement forces, mass and engine loads 10 Forces to Chaos AddForce, AddTorque 11 Publish the step telemetry, logs, sensor sample The Polaris runs the same step. Its own functions replace the drivetrain parts of steps 5 to 7. Game thread keyboard controls Vehicle bridge command queue Weather and farm models shared by all agents Automatic drivers scripted test, replay, drive script Ground collision mesh, surface map, soil class, soil water, ruts Farm state ruts and tread prints crushed crop field-work marks Chaos rigid body integrates the chassis Telemetry HUD, vehicle bridge Session log, episode log one row for each step Sensor recorder sensor stream, sensor files
The sequence of operations in one physics step of 1/120 s on the physics thread. Open the diagram

Time#

Item Value Source
Physics step 1/120 s, on the physics thread (bTickPhysicsAsync=True) Game/Config/DefaultEngine.ini
Longest physics time of one frame 0.1 s (12 steps) MaxPhysicsDeltaTime=0.1 in DefaultEngine.ini
Control period of the bridge observations 0.1 s Game/Source/Acres/AcresRlBridge.h

A frame that is longer than 0.1 s makes the simulation slower than real time. Time Stepping gives the rules.

Threads#

The threads of the game and the data that moves between them: physics, game and render threads in the centre, worker threads at the sides. Water thread AcresWater soil water on its own clock flow, infiltration, drains Physics thread fixed step, 120 Hz Vehicle step: commands, models, wheel forces, forces to Chaos, farm marks, log row, sensor samples at exact step numbers. Sensor writer AcresSensorWriter writes JSONL rows, images and point clouds moisture rain, ruts rows controls and timed commands telemetry: a struct copy under a lock Bridge receiver AcresRlReceiver reads the vehicle bridge and stamps each message Game thread each frame Actors, UI, visuals, keyboard, sockets, sensor schedule (camera captures, LiDAR scans), lockstep control. Sensor stream AcresSensorStream sends sensor frames to the ROS 2 bridge messages frames render commands images and scans Thread pool camera sensor model and PNG encoding, one task for each image Render thread each frame Draws the frame, reads the sensor camera image back from the GPU, runs the GPU LiDAR pass. Video writer AcresVideoWriter sends window frames to ffmpeg for a video capture pixels frames
The threads of the game and the data that moves between them. Open the diagram
Thread Work
Game thread Actors, user interface, visuals, sockets, the sensor schedule, lockstep control.
Physics thread The vehicle step at 120 Hz: models, forces, farm marks, log rows, sensor samples.
Render thread Drawing, the camera readback, the GPU LiDAR pass.
AcresWater The soil-water model.
AcresSensorWriter Writes the sensor files.
AcresSensorStream Sends the sensor frames to a client.
AcresRlReceiver Reads the vehicle bridge and stamps each message with its arrival time.
AcresVideoWriter Sends the frames of the window to ffmpeg.

Render Tiers#

The game selects a render tier at the start. Without -RenderTier=, a GPU with 11776 MiB (11.5 GiB) or more gets the tier high. A GPU with less memory gets the tier low. Source: Game/Source/Acres/AcresRenderTier.cpp.

The GPU LiDAR needs hardware ray tracing. Without it, or with -SensorCpuLidar, the game uses the CPU LiDAR.

Logs and Stop#

The game writes its log to the terminal and to Saved/Logs/Acres.log (Packaged/Linux/Game/Saved in the package). Files and Formats gives the session folder. At each important event the game writes a line with the prefix ACRES_. Use these lines in scripts.

Log Marker Event
ACRES_RENDER_TIER The render tier, the GPU memory and the sensor profile.
ACRES_MAP_DATA The map variant and the fields that are different.
ACRES_SPAWN, ACRES_VEHICLE_READY A vehicle got its start pose. A vehicle is ready.
ACRES_ENVIRONMENT_READY, ACRES_FARM_READY The weather and the farm are ready.
ACRES_SENSOR_START, ACRES_SENSOR_STOP A sensor episode started or stopped. The start line shows gpu_lidar=1 or gpu_lidar=0.
ACRES_SIM_CONTROL_READY The simulator control channel is open.
ACRES_CAPTURE_START, ACRES_CAPTURE_DONE The video recording started or stopped.

To stop a session, push Esc. Without a window, push Ctrl+C one time or use timeout -s INT.

Warning

Push Ctrl+C one time only, then wait. A second interrupt stops the game immediately. The game then does not write session-summary.json and the farm files, and the sensor episode stays open.

Keyboard#

Keyboard and Mouse gives the keys.

Build and Run#