acres_core#
acres_core is the Python module of ACRES Core. It gives a batch of Polaris environments on the ACRE world. One call steps all environments 0.1 s on the CPU cores. The inputs and the outputs are NumPy arrays.
Source: Game/Core/Python/acres_core_module.cpp. The C++ class is FAcresBatch in Game/Core/Source/AcresCoreBatch.h.
Import#
Game/Core/build.sh --no-tests
export PYTHONPATH=$PWD/Game/Core/Build
python -c "import acres_core as ac; print(ac.STATE_COLUMNS[:4])"
The module is Game/Core/Build/acres_core*.so. It is built for the Python interpreter that Game/Core/build.sh used (the variable PYTHON).
Example#
Run this example from the root of the repository.
import numpy as np
import acres_core as ac
batch = ac.Batch(".", num_envs=4) # the root of the repository
batch.reset(None, np.tile([-585.0, 75.0, np.pi / 2, 0.0], (4, 1)))
for _ in range(50): # 5 s
state = batch.step_curvature_speed(np.full(4, 0.05), np.full(4, 2.0))
print(state[:, ac.STATE_COLUMNS.index("speed")])
ranges, material = batch.lidar(pattern="helios") # (4, 57600): 1800 columns x 32 rings
Batch#
Batch(root, num_envs=1, threads=0, flat=False, flat_surface="asphalt", crop_season="2026", initial_growth=1.0, farm=True, scene=True, polaris_overrides={}, occupants=-1, substeps=12, resend_steps=6, content_dir="", farm_water=True, drive_region=False, region_crops=True, crop_date="")-
Makes
num_envsenvironments on one shared world. The world files come fromroot:Game/Content/Simulation(orcontent_dir) andGame/Core/Data.Argument Meaning rootThe repository folder. threadsThe worker threads. 0: one for each hardware thread. flat,flat_surfaceA plane with one surface in place of the ACRE tile: a surface of tractor.json, orbench_asphalt,bench_grass,bench_gravel.crop_season,initial_growth,crop_dateThe crop season and a fixed start growth from 0 to 1. A date YYYY-MM-DDincrop_dategives each field the degree days from its planting date.farmThe crops, the ruts and the field marks. sceneThe scene geometry for the LiDAR and the obstacles. polaris_overridesPolaris parameters by the dotted keys of polaris.json.occupantsThe persons in the vehicle. -1: the value of polaris.json.substepsThe physics steps of 1/120 s in one call. resend_stepsThe physics steps between two sends of the same command. farm_waterThe wheels read the 4 m soil-water grid of the farm. False: the water of the surface templates of tractor.json.drive_region,region_cropsThe surveyed ground around the tile with the fields RF001 to RF100 (ids 101 to 200), and their crops. num_envs- The number of environments.
reset(indices, poses, settled=True, gear=5, drive_mode=2)- Puts environments at poses.
poseshas the shape(len(indices), 4): x, y (ENU m), yaw (rad from east) and speed (m/s) ofbase_footprint.indices=Noneselects all. Gear 5 is L. Drive mode 2 is AWD. step(commands=None)- Advances 0.1 s.
commandshas the shape(num_envs, len(COMMAND_COLUMNS)): one drive-by-wire row for each environment. A NaN mode sends no message.Noneholds the commands. Returnsstate. step_curvature_speed(curvature, speed, gear=None, limit_accel=0, limit_decel=0, steer_rate=0, steer_accel=0)-
Advances 0.1 s with a curvature command (1/m) and a ULC speed command (m/s) for each environment. Returns
state.gearisNone(no gear command) or one gear code ofGEARSfor each environment. In reverse the speed is negative. A shift occurs only belowdbw.gear.max_speed_mpsofpolaris.json.limit_accelandlimit_decelare the ULC limits (m/s2).steer_rateandsteer_accelare the steering limits (deg/s, deg/s2). A value of 0 gives the default ofpolaris.json. The vehicle node sends 0.8 and 2.0 m/s2 and the steering limits ofConfig/scouting.json. state,wheels,energy,energy_step- Copies of the outputs.
stateis(num_envs, len(STATE_COLUMNS)).wheelsis(num_envs, 4, len(WHEEL_COLUMNS)).energyandenergy_stepare(num_envs, len(ENERGY_COLUMNS)): joules since the reset and in the last step. zone_crushed,zone_crushed_step- The crushed area for each zone of
set_zones, or for each class ofGROUND_CLASSES, m². crushed_by_field- The crop area crushed since the reset for each field id, m²:
(num_envs, FIELD_ID_LIMIT). set_conditions(indices=None, global_fraction=nan, field_fractions=None, surface_film=0.0, max_fraction=1.3)-
The soil water of environments.
field_fractionshas the shape(len(indices), 60). NaN keeps the global fraction.A fraction is 0 at the wilting point, 1 at field capacity and 2 at saturation. A soil cell takes at most
max_fraction(0 to 2). The default 1.3 is the limit of the menu of the game. A value of 2 gives the full scale of the measured wetness index. set_winter(indices=None, snow_depth_m=0.0, snow_density=250.0, ice_share=0.0, frozen_soil=False)- The winter of environments, as for
TractorBatch. set_weather(indices=None, rain_mm_h=0.0, evaporation_mm_day=0.0, time_scale=1.0, on=True)- Turns on the soil-water columns of the regional ground and gives the rain and the evaporation. It needs
farmanddrive_region. region_water(index, x, y)- The soil-water column of the regional ground below a point: the water content of the two layers, the pond and the water ledgers.
Nonewithout columns.
The farm stamps function follows.
farm_stamps(index, stamps)- Applies farm stamps to one environment. A stamp is a row of 13 values, as the records of
/sim/farm_stampsof an episode log. Returns the area of each stamp, m². farm_state(index)- The farm of one environment:
state_digest(16 hexadecimal digits), and the crushed and harvested areas for each field. Also the harvest mass and the worked areas for each field, the counts of rut cells and worked cells, andrut_volume_m3.rut_volume_m3is the depth of each 25 cm rut cell times its area, summed since the reset. set_parameters(indices, overrides)- Changes Polaris parameters of environments.
start_log(index, path, metadata={}, agent="polaris"),stop_log(index)- Starts and stops the episode log (MCAP) of one environment.
The LiDAR functions follow.
lidar(indices=None, pattern="planar", noise=False, seed=0, objects="auto", intensity=False, crops=False, sweep=False, twist=None)-
A scan. Returns
(ranges, material): float32 and uint8 arrays(K, beams). A NaN range is no return.patternisplanarorhelios.objectsisauto,shape,columnornone.intensity=Trueadds a third array with the reflectivity byte.crops=Trueadds the crops and the grass cover.sweep=Truetraces each column from the pose at its firing time. Withsweep,twist(K, 6)gives a constant motion. set_lidar_crops(height_scale=None, fill=None, cover_height_m=None, cover_fill=None, top_stretch=None, cover_calibrated=None, plants_fill_scale=None, top_relief=None)- The parameters of the crop returns of
lidar(crops=True).Nonekeeps a value. lidar_crops()- The parameters of the crop returns and the number of crop patches that the LiDAR sees.
set_lidar_crop_state(path)- Gives the crops of the LiDAR the state of one day from a file. An empty path restores the state of the map.
set_lidar_radiometry(foliage_echo=None, micro_slope_deg=None, crop_echo=None, ground_echo=None)- Changes the radiometry of the pattern
heliosfor a study. Returns the values in use. set_objects(index, objects, ids=None),objects(index),object_contact- The objects on the path of one environment: rows of
OBJECT_COLUMNS. An object moves with its velocity in each physics step.object_contactgives the first object that the plan box of each vehicle touches, or -1. set_zones(zones, x0, y0, cell_m)- A uint8 raster of zones for
zone_crushed. The rows run north. scene_material(name)- The code of a material of the scene in the material array of
lidar(), for exampletree_foliage. -1 if the scene does not have it. height_at(x, y),surface_class_at(x, y),field_at(x, y),field_growth(field),nearest_obstacle(x, y, max_m=30.0)- Lookups on the world. They give the terrain height, the surface class (an index of
SURFACE_CLASSES), the field id, the growth fraction of a field and the distance to the nearest obstacle. A field id is 1 to 59 on the tile, 101 to 200 on the regional ground and 0 for no field. field_name(id),field_id(name)- Static functions: the name of a field id (
F01,RF001) and the id of a name. places()- The named places:
(id, name, x, y, heading_deg). num_crop_patches,crop_patches(),crushed_patches(index)- The crop patches of the tile (
xyzh,field,kind: 0 corn, 1 soybean, 2 potato) and the crushed sample masks of one environment. num_region_crop_patches,region_patch(ordinal)- The crop patches of the regional ground.
TractorBatch#
TractorBatch(root, num_envs=1, threads=0, implement="", flat=False, flat_surface="asphalt", crop_season="2026", initial_growth=1.0, farm=True, vehicle_overrides={}, implement_overrides={}, substeps=12, content_dir="", farm_water=True, drive_region=False, region_crops=True)- N environments of the Case IH Maxxum 150 with one implement on the shared world (
Game/Core/Source/AcresCoreTractor.h, Tractor Physics Audit). The tractor and implement models are the game's (AcresVehicleModel.h,AcresImplementModel.h).implementis""(theimplement_model.idoftractor.json),none, an implement id (cultivator,chisel_plow,disc_harrow,seed_drill,mounted_sprayer,loader_bale_fork,backhoe_attachment,square_baler,round_baler,grain_cart,mower_conditioner) orharvester(the header offarm.json, or the potato digger whenimplement.typeoftractor.jsonispotato_digger).vehicle_overridesare keys of thevehicleblock oftractor.json.implement_overridesare keys ofimplements/<id>.jsonand the settings ofimplement_model(for exampleworking_depth_m,spray_rate_l_ha,windrow_kg_m,bale_mass_kg). reset(indices, poses, settled=True, keep_farm=False)- Puts environments at
poses(K, 4): base_footprint x, y, yaw, speed. The controls go to the start: brake on, the start gear, the start controls of the implement.keep_farm=Truekeeps the farm marks (crush, ruts, work flags): a season of several passes on one farm (the benchmark task T6). step(controls=None)- Advances
substepsphysics steps.controlsis(num_envs, len(TRACTOR_CONTROL_COLUMNS)). A NaN value keeps the last value of its column.Nonekeeps all. Returns the state. set_conditions(indices=None, global_fraction=nan, field_fractions=None, surface_film=0.0, max_fraction=1.3)- The soil-water scenario, as for
Batch. set_ground(indices=None, active=True, soil=True, soil_class="silt_loam", theta=0.25, wetness=0.0, density_mg_m3=0.0, water_depth_m=0.0, traffic_compaction=0.0, root_cohesion_pa=0.0, surface_index=4, friction=0.8, rolling=0.015, rear_in_front_ruts=False)- A test-stand ground under each wheel and tool in place of the world's ground, as the ground of the game's vehicle bench (
Tests/Game/Vehicle/VehicleBench.h).active=Falsegives the world's ground again. set_winter(indices=None, snow_depth_m=0.0, snow_density=250.0, ice_share=0.0, frozen_soil=False)-
The winter of environments (
AcresSim::ApplyWinter, the weather of the game). It stays until the next call. The values are the snow depth (m) and density (kg/m³) on the ground, the share of the surface that glaze ice covers (0 to 1) and frozen soil.Each wheel gets the winter of its surface class. Roads and yards are plowed to a film of 2 mm. Grass lanes and dirt tracks have packed snow. The other surfaces have undisturbed snow (CRREL Report 95-1). The ground of a test stand (
set_ground) and the flat world are not plowed. All zero andFalsegive the surfaces with no winter. set_wet_spots(index, spots)- Wet spots of the soil-water scenario of one environment:
spots(k, 4)of x, y (ENU m), radius (m) and fraction (0 wilting point, 1 field capacity, 2 saturation),kat most 8. A soil cell of the tile's 4 m water grid whose centre is inside a spot takes the larger of its fraction and the spot's (then the clamp atmax_fraction). The wheels and the tools read the grid bilinearly, so the edge of a spot is a ramp of 4 m.set_conditionsmakes a new scenario without spots: give the spots after it.(0, 4)removes them. Not on the regional ground. farm_state(index),farm_stamps(index, stamps)- As for
Batch.farm_stampswrites no log. farm_cells(index, x0, y0, nx, ny)- The 25 cm cells of a window of the farm of one environment, east and north from the south-west corner
(x0, y0). For the farm's cell under the centre of each cell: the rut depth(ny, nx)(float32, m) and the work flags(ny, nx)(uint8: 1 tilled, 2 seeded, 4 sprayed, 8 mowed). copy_farm(index, source, source_index)- The farm of environment
source_indexof the batchsourcebecomes the farm of environmentindex. The two batches must have the same world. With it, one farm takes the passes of several machines (one batch for each implement). soil_class_at(x, y),field_at(x, y)- The soil class of the soil library that the map's texture gives at a point (fine:
silty_clay_loam, medium:silt_loam, coarse:sandy_loam), and the field id at a point (0: none). lever_for_depth(depth_m)- The hitch lever (0 to 1) that puts the tines at
depth_mon level ground without sinkage (AcresSim::ImplementControlsForDepth). The control columndepth_msets the same lever. Under a draft the rear tyres sink and squat and the chassis pitches, so the tines go deeper than this depth. sensed_draft_for_depth(depth_m, soil_class="silt_loam", speed_mps=nan)- Returns
(draft_n, sensed_draft_n, depth_m). The implement is in position control at the lever ofdepth_mon level ground (AcresSim::ImplementSteadyState). The soil class is at field capacity and at its firm density: the reference state of the fit of the tines to ASAE D497.5. The speed isspeed_mps(NaN: the design speed). The sensed draft is the load on the lower links (the columnsensed_draft_n). Use it as the set point of draft control for that work. surface_at(index, x, y)- The ground that a wheel of environment
indextouches at a point (FAcresWorld::SurfaceAtwith the soil water and the farm of the environment). It changes nothing. Returns a dict:soil(bool),soil_class(assoil_class_at),theta(the water content, m³/m³),wetness(the rain film),rut_m(the rut of the 25 cm cell),tilled(the tillage flag of the cell) andsurface_class. The fast simulator uses it for the profiles of the tractor tasks (Benchmark/acres_bench/t2/fast.py). sensed_draft_for_depth(depth_m, soil_class="silt_loam", speed_mps=nan)- Returns
(draft_n, sensed_draft_n, depth_m). The implement is in position control at the lever ofdepth_mon level ground (AcresSim::ImplementSteadyState). The soil class is at field capacity and at its firm density: the reference state of the fit of the tines to ASAE D497.5. The speed isspeed_mps(NaN: the design speed). The sensed draft is the load on the lower links (the columnsensed_draft_n). Use it as the set point of draft control for that work. surface_at(index, x, y)- The ground that a wheel of environment
indextouches at a point (FAcresWorld::SurfaceAtwith the soil water and the farm of the environment). It changes nothing. Returns a dict:soil(bool),soil_class(assoil_class_at),theta(the water content, m³/m³),wetness(the rain film),rut_m(the rut of the 25 cm cell),tilled(the tillage flag of the cell) andsurface_class. The fast simulator uses it for the profiles of the tractor tasks (Benchmark/acres_bench/t2/fast.py). state,wheels,energy,energy_step- The arrays after the last call:
(num_envs, len(TRACTOR_STATE_COLUMNS)),(num_envs, 4, len(WHEEL_COLUMNS))and the energy ledger(num_envs, len(ENERGY_COLUMNS)). config- A dictionary of the tractor and its implement: the masses with the implement at rest, the inertia, the centre of mass and the geometry. It also has the gears, the working width, the bale mass and the bunker capacity.
The control column drawbar_n is a test-stand pull at the hitch (as the drawbar of the vehicle bench). It is not a load of the game.
An example: the Maxxum with the round baler on a test stand of silt loam, then a steady drawbar pull without an implement.
import numpy as np
import acres_core as ac
C = {n: i for i, n in enumerate(ac.TRACTOR_CONTROL_COLUMNS)}
S = {n: i for i, n in enumerate(ac.TRACTOR_STATE_COLUMNS)}
W = {n: i for i, n in enumerate(ac.WHEEL_COLUMNS)}
b = ac.TractorBatch("/path/to/ACRES", num_envs=1, implement="round_baler", flat=True, flat_surface="dry_soil")
b.set_ground(soil_class="silt_loam", theta=0.30) # the test stand's ground under every wheel and tool
b.reset(None, np.zeros((1, 4))) # x, y, yaw, speed
u = np.full((1, len(C)), np.nan) # NaN keeps a column
u[0, [C["brake"], C["throttle"], C["gear"], C["pto"], C["pickup"], C["raise"], C["windrow_kg_m"]]] = [0, 1, 7, 1, 1, 0, 3]
s = b.step(u)
for _ in range(1200): # 120 s: a bale every 78 s
s = b.step()
print(s[0, S["pto_kw"]], s[0, S["intake_kg_s"]], s[0, S["bales_dropped"]], s[0, S["round_phase"]])
t = ac.TractorBatch("/path/to/ACRES", implement="none", flat=True, flat_surface="dry_soil", substeps=120)
t.set_ground(soil_class="silt_loam", theta=0.30, density_mg_m3=0.0)
t.reset(None, np.zeros((1, 4)))
u = np.full((1, len(C)), np.nan)
u[0, [C["brake"], C["throttle"], C["gear"], C["drawbar_n"], C["drawbar_height_m"]]] = [0, 1, 7, 20000, 0.5]
for _ in range(12): # 12 s: settled at the pull
s = t.step(u)
print(s[0, S["rear_slip"]], s[0, S["fuel_rate_lph"]], t.wheels[0, 2, W["sinkage_m"]], s[0, S["front_axle_n"]])
The outputs to read: rear_slip and front_slip (travel reduction of each axle), draft_n, fuel_rate_lph, rpm, front_axle_n and rear_axle_n, tractive_efficiency. The implement's pto_kw, hydraulic_kw, implement_depth_m, payload_kg, intake_kg_s, bales_dropped, round_phase, unload_kg_s, tank_l. Per wheel sinkage_m, slip, fx_n, normal_n. The tractor uses tractor.json. vehicle_overrides changes a key of its vehicle block (for example {"pto_efficiency": 1.0, "rut_pass_d497": 0} gives the values before the audit's fixes). Game/Core/Tools/tractor_audit.cpp and Tests/Core/tractor_tests.cpp are C++ examples of the same test stand.
Module Constants#
| Name | Value |
|---|---|
COMMAND_COLUMNS |
enable, steer_mode, steer_value, steer_rate, steer_accel, throttle_mode, throttle_value, brake_mode, brake_value, gear, ulc_mode, ulc_value, ulc_limit_accel, ulc_limit_decel, ulc_jerk_throttle, ulc_jerk_brake, ulc_coast, drive_mode |
STATE_COLUMNS |
49 names. They start with time_s and the pose (x, y, z, qw to qz, yaw, pitch, roll). Then come the velocities, the accelerations, speed, the actuator values, rpm, cvt_ratio and the fuel. The last are the enable flags, grounded, rear_slip, the crushed areas, off_map, collision, field_under and surface_under. |
WHEEL_COLUMNS |
omega, slip, normal_n, fx_n, fy_n, sinkage_m, contact, surface_class, field, steer_rad, drive_torque_nm, suspension_m, pressure_pa |
ENERGY_COLUMNS |
24 terms of the energy ledger, from fuel to ground_loss |
GEARS |
The gear codes of a gear command and of the state column gear: none 0, park 1, reverse 2, neutral 3, high 4, low 5 |
SURFACE_CLASSES |
field, asphalt, concrete, gravel, grass_lane, grass, dirt |
GROUND_CLASSES |
crop, lane, verge, edge_band, obstacle, other |
OBJECT_COLUMNS |
kind, x, y, yaw, length_m, width_m, height_m, vx, vy |
OBJECT_KINDS |
truck, person |
LIDAR_MATERIALS |
The codes of a return that is not a scene material. no_return 255, terrain 254, vehicle_box 253, self 252, person 251. crop_potato 250, crop_soybean 249, crop_corn 248, ground_cover 247, plants 246. |
TRACTOR_CONTROL_COLUMNS |
throttle, brake, steer_rad, direction, gear (1 to 16), diff_lock, hand_throttle, park_brake. Then raise, pto, transport, depth_m, hitch_mode, draft_setpoint_n, spray, boom_fold, pickup, windrow_kg_m. Then loader_lift, loader_curl, bale_on_fork, harvest, unload, cart_fill_kg_s, drawbar_n, drawbar_height_m. Then mower_side (the mower-conditioner's work position: -1 right, +1 left) and crop_kg_m2 (the dry matter of the standing crop under its cutterbar). Then wing_left and wing_right (the rotary cutter's wings: 0 down, 1 raised, 2 folded), and cut_height_m (the cut height of the rotary cutter and the flail shredder). Then hitch_lever: the lever itself, from 0 (lowest) to 1 (highest), the depth limit in draft mode, applied after depth_m in the same row. Last, draft_mix: the draft-position mix of the hitch control in draft mode, 0 position and 1 draft (the game's control is 1). |
TRACTOR_STATE_COLUMNS |
69 names. First the pose and the motion as in STATE_COLUMNS, then steer_rad, rpm, gear, the engine and the fuel. Then rear_slip, front_slip, the axle loads, mass_kg, draft_n, and the PTO and hydraulic power. Then the state of the implement (depth, lift, tank, sprayed area, bales, intake, baler yaw, round_phase 0 forming / 1 wrapping / 2 ejecting, unload_kg_s). Then bunker_kg, the farm changes of the last step, off_map, field_under and surface_under. The mower-conditioner: mower_swing (-1 right .. 0 straight .. +1 left), mowed_m2, swath_kg. The rotary cutter and the flail shredder: wing_left_rad, wing_right_rad, deck_height_m, cut_width_m, machine_width_m. Last, sensed_draft_n and tool_x_m. sensed_draft_n is the draft that the lower-link pins sense, before the filter of the hitch control. It is more than draft_n, because the top link pushes. tool_x_m is the tool zone of a three-point implement, x in the frame of the rear axle: the point whose depth is implement_depth_m (0 without an implement). |
PHYSICS_DT |
1/120 s |
TILE_FIELD_LIMIT, REGION_FIELD_BASE, FIELD_ID_LIMIT, REGION_PATCH_BASE |
60, 100, 201, 1073741824 |
To see a full list, print it in Python, for example print(ac.STATE_COLUMNS).