Skip to content

AcresCoreBatch.h#

Game/Core/Source/AcresCoreBatch.h Generated

Batched environments of ACRES Core: N independent Polaris environments on one shared world, stepped together on all CPU cores. This is what the Python module (Game/Core/Python) and the learners use; Vehicle/ROS/acres_core_sim will wrap the same class.

A Step advances every environment by SubSteps physics steps (12 x 1/120 s = 0.1 s, the task's control step) under its drive-by-wire command, in parallel (a persistent thread pool; one environment is only ever stepped by one thread). Commands have ds_dbw semantics (AcresSim::FDbwCommand): a command row given to Step counts as a message arriving at the first physics step and is re-sent every CommandResendSteps physics steps while it is held (a 20 Hz publisher by default, as the lab's path follower); a NaN mode means "no message this step", so that subsystem times out after 0.1 s as on the vehicle. State, wheel and energy arrays are filled after every Step and Reset in structure-of-arrays layout, ready to be wrapped as numpy arrays.

Objects on the path: each environment has a list of objects that are not in the map (FAcresObject: a truck as a box, a person as an upright cylinder). SetObjects replaces the list, and Reset removes it. An object stands on the terrain and moves with its velocity in each physics step. The LiDAR scans see the objects, and a contact of the vehicle's plan box with an object sets the collision column. An environment without objects is as it was before the objects (Docs/Models/farm-traffic.md).

Threads: Step and Reset are called from one thread at a time (they fan out internally).

Name Type Unit Default Description
EnergyColumnCount inline constexpr int 24 Energy ledger columns: the AcresSim::FEnergyFlows fields in declaration order, then GroundLoss = Slip + Lateral + Soil (E_ground of the scouting task).
Command AcresSim::FDbwCommand The command held (and its re-send clock), the raw last command row.
EnergyAtStep AcresSim::FEnergyFlows Energy at the start of the last Step (for the deltas) and crop at its start.
Log std::unique_ptr<FAcresEpisodeLog> Episode log (null when not recording), its agent id and name; physics steps since the environment was created (the log's step and clock), resets so far and the step of the last reset.
Objects std::vector<FAcresObject> The objects on the path (empty: none). Reset removes them.
LoggedObjects std::vector<AcresLog::FPathObject> The objects as the log wrote them at the last physics step (the leave events of the next step).
GivenStamps std::vector<AcresLog::FFarmStamp> The farm stamps that a caller gave since the last physics step (FAcresBatch::ApplyFarmStamps), for the log record of the next step. Empty when the environment does not record.
SweepHistory static constexpr int 16 The pose of base_footprint after each of the last physics steps and at the reset, for the motion in one LiDAR sweep (FAcresScanOptions::bSweep): a ring of SweepHistory poses with the world step of each. A sweep of 0.1 s is 12 steps. The dynamics do not read this.

PlanBoxTouchesObject#

The plan box of the vehicle (0.5 m behind the rear axle to 0.55 m ahead of the front axle, 1.6 m wide, 0.3 m to 2.0 m above the ground) touches an object on the path: the contact rule of ACRES Core, which the game repeats.

Argument Description
WheelbaseM The wheelbase. BaseZ: The ground under the centre of the object, m. Kind, X, Y, ObjectYaw, LengthM, WidthM, HeightM: The object (EObjectKind; a person is a circle of WidthM).
bool PlanBoxTouchesObject(double FootX, double FootY, double FootZ, double Yaw, double WheelbaseM, double BaseZ, int Kind, double X, double Y, double ObjectYaw, double LengthM, double WidthM, double HeightM);

SetScenario#

A new soil-water scenario of an environment (SetConditions): the global antecedent fraction, the 60 per-field fractions (null: none), the rain film and the largest fraction; the weather of the columns stays.

void SetScenario(FAcresConditions& C, double GlobalFraction, const double* FieldFractions, double SurfaceFilm, double MaxFraction);

WheelRow#

The wheel row of a wheel state (WheelColumnCount values, EWheelColumn) with its surface class and field.

void WheelRow(const AcresSim::FWheelState& W, int SurfaceClass, int Field, double* Out);

EnergyRow#

The energy ledger row of FEnergyFlows (EnergyColumnCount values: the fields in declaration order, then GroundLoss).

void EnergyRow(const AcresSim::FEnergyFlows& F, double* Out);

CommandColumnName#

Column names (for the Python dictionaries and the docs).

const char* CommandColumnName(int Column);

ApplyFarmStamp#

One environment. Gives one farm stamp to a farm (the dispatch of FAcresBatch::ApplyFarmStamps, without the log): Row has the FAcresBatch::FarmStampColumnCount values of a stamp. Out (may be null) receives the stamp as applied. Returns the crop area that it crushed or harvested, or the area that got a new work flag, m2.

double ApplyFarmStamp(const FAcresWorld& World, FAcresFarmState& Farm, const double* Row, FAcresFarmStamp* Out = nullptr);

ECommandColumn#

enum ECommandColumn : int

Columns of the command array (one row per environment, double).

Value Description
CmdEnable System enable (/vehicle/enable), 0 / 1.
CmdSteerMode SteeringCmd cmd_type: 0 none, 2 angle (deg), 3 curvature (1/m), 4 yaw rate (rad/s), 14 %.
CmdSteerValue SteeringCmd cmd.
CmdSteerRate SteeringCmd cmd_rate, deg/s (0 default).
CmdSteerAccel SteeringCmd cmd_accel, deg/s2 (0 default).
CmdThrottleMode ThrottleCmd cmd_type: 0 none, 13 raw %, 14 %.
CmdThrottleValue ThrottleCmd cmd.
CmdBrakeMode BrakeCmd cmd_type: 0 none, 1 pressure (bar), 14 %.
CmdBrakeValue BrakeCmd cmd.
CmdGear GearCmd: 0 none, 1 P, 2 R, 3 N, 4 H, 5 L.
CmdUlcMode UlcCmd cmd_type: 0 none, 1 velocity (m/s), 2 acceleration (m/s2).
CmdUlcValue UlcCmd cmd.
CmdUlcLimitAccel UlcCmd limit_accel, m/s2 (0 default).
CmdUlcLimitDecel UlcCmd limit_decel, m/s2 (0 default).
CmdUlcJerkThrottle UlcCmd limit_jerk_throttle, m/s3 (0 default).
CmdUlcJerkBrake UlcCmd limit_jerk_brake, m/s3 (0 default).
CmdUlcCoast UlcCmd coast_decel, 0 / 1.
CmdDriveMode AWD switch: 0 Turf, 1 2WD, 2 AWD.
CommandColumnCount

EStateColumn#

enum EStateColumn : int

Columns of the state array (one row per environment, double). Positions are base_footprint in ENU m.

Value Description
StTime
StX
StY
StZ
StQw
StQx
StQy
StQz
StYaw
StPitch
StRoll
StVx
StVy
StVz
StWx
StWy
StWz
StAx
StAy
StAz
StSpeed
StSteeringWheelDeg
StSteerRefDeg
StRoadWheelRad
StThrottlePct
StBrakeBar
StGear
StUlcVelRef
StUlcAccelRef
StSpeedMeasured
StRpm
StCvtRatio
StFuelRateLph
StFuelUsedL
StDbwEnabled
StSteerEnabled
StThrottleEnabled
StBrakeEnabled
StUlcEnabled
StGrounded
StRearSlip
StCropCrushedM2
StCropCrushedStepM2
StCrushedWheelsStepM2
StCrushedBodyStepM2
StOffMap
StCollision
StFieldUnder
StSurfaceUnder
StateColumnCount

EWheelColumn#

enum EWheelColumn : int

Columns of the wheel array ([environment][wheel 0..3][column], double; wheels FL, FR, RL, RR).

Value Description
WhOmega
WhSlip
WhNormalN
WhFxN
WhFyN
WhSinkageM
WhContact
WhSurfaceClass
WhField
WhSteerRad
WhDriveTorqueNm
WhSuspensionM
WhPressurePa
WheelColumnCount

EObjectKind#

enum EObjectKind : int

Kinds of an object on the path (FAcresObject::Kind).

Value Description
ObjectTruck A box: LengthM along its yaw, WidthM across, HeightM high.
ObjectPerson An upright cylinder: the diameter WidthM, HeightM high (LengthM is not read).
ObjectKindCount

EObjectColumn#

enum EObjectColumn : int

Columns of an object row (double): the layout of FAcresBatch::SetObjects and of the Python module's objects().

Value Description
ObjKind EObjectKind.
ObjX Centre, ENU m.
ObjY
ObjYaw Heading, rad counter-clockwise from east.
ObjLengthM Size, m.
ObjWidthM
ObjHeightM
ObjVx Velocity in the world, m/s.
ObjVy
ObjectColumnCount

FAcresObject#

struct FAcresObject

An object on the path of an environment. Its base is on the terrain at its centre, and it stays upright.

Name Type Unit Default Description
Id int 0 The number of the object in its episode (the episode log names it; SetObjects' Ids, else the row index).
bContact bool false The plan box of the vehicle touched the object at the last physics step (the log's collision event is the first step of a contact).

EObjectScan#

enum EObjectScan : int

How a scan sees the objects of an environment (FAcresBatch::Scan).

Value Description
ObjectScanAuto The planar pattern: ObjectScanColumn. Each other pattern: ObjectScanShape.
ObjectScanNone The scan does not see the objects.
ObjectScanShape The shape of the object with its height.
ObjectScanColumn The plan of the object at each height. The planar scan is the nearest obstacle of the height band of the vehicle body in each beam, but its one ray is level at the height of the sensor (2.04 m): with the shape, an object lower than the sensor (a person) is below the ray.

FAcresBatchOptions#

struct FAcresBatchOptions

Options of FAcresBatch::Init.

Name Type Unit Default Description
World FAcresWorldOptions The world (its ContentDir must be set).
PolarisConfig std::string polaris.json (empty: <ContentDir>/polaris.json), parameter overrides (dotted keys) and occupants (-1: file).
NumEnvs, Threads int Environments; worker threads (0: all hardware threads).
PhysicsDt double 1. / 120 Physics step, s; physics steps per Step; re-send period of held commands, physics steps (0: never re-send).
bFarm bool true Keep crop and rut marks (the farm); off saves the stamp work in RL that does not score crop.
OffMapMarginM double m 10 Distance from the tile edge at which an environment counts as off the map, m.

FAcresScanOptions#

struct FAcresScanOptions

Options of FAcresBatch::ScanCloud.

Name Type Unit Default Description
bNoise bool false Range and signal noise (deterministic from the seed, the environment and the physics step).
ObjectScan int -1 How the scan sees the objects of the environment (EObjectScan; -1: ObjectScanAuto).
bCrops bool false Crops and grass ground cover (the FAcresLidarCanopy of the world, with the crushed and the harvested samples of the environment), and the ground material from the surface class at the hit. False: the scan of FAcresBatch::Scan.
bSweep bool false The motion in one sweep: each column from the pose of base_footprint at its firing time. The poses come from the physics steps of the environment (FAcresEnv::SweepPoses; the pose of the reset is held before the first step), or from Twists.
Twists const double* nullptr With bSweep, optional Count x 6 rows: the velocity of base_footprint along its axes (x forward, y left, z up), m/s, and its angular velocity about them, rad/s. The sweep then has this constant motion and ends at the pose of the environment (for a scan at a pose that no drive made). Null: the poses of the physics steps.

FAcresBatch#

class FAcresBatch

The batch. See the file comment.

Name Type Unit Default Description
FarmStampColumnCount static constexpr int 13 Gives farm stamps to the farm of one environment, in sequence: tyre and body contacts, cuts of the harvester and strips of field work, as the episode log of the game holds them (/sim/farm_stamps). ACRES Core has no tractor: this is how a replay of a game log, or a task with field work, changes the farm of Core. When the environment records, the stamps go into the log record of the next physics step, before its contacts.
State std::vector&lt;double> Output arrays, refreshed by Step and Reset.
ObjectContact std::vector&lt;int> Size(): the index of the first object of the environment that the plan box of the vehicle touches, -1: none. The collision column of the state is 1 for a contact with the scene or with an object.
World FAcresWorld The world and the environments (read-only use from outside between calls).
LidarCrops FAcresLidarCropModel Parameters of the crop returns of ScanCloud, and the height of the grass ground cover on the surface classes grass and grass lane, m (0: none). Set them between scans, not during one.

FAcresBatch::Init#

Loads the world and the Polaris parameters, creates the environments (each at the origin until reset) and the thread pool. False with Error on a load failure.

bool Init(const FAcresBatchOptions& Options, std::string* Error = nullptr);

FAcresBatch::Size#

Number of environments.

int Size() const ;

FAcresBatch::Reset#

Places environments and clears their farm marks, commands and logs' clocks.

Argument Description
Poses Count x 4: base_footprint x, y (ENU m), yaw (rad counter-clockwise from east), forward speed (m/s).
bSettled On the terrain at the static ride height (true), or dropped level from 0.2 m as the game does. Gear, DriveMode: Start gear (EUtvGear) and AWD switch position.
void Reset(const int* Indices, int Count, const double* Poses, bool bSettled = true, int Gear = AcresSim::UtvGearLow, int DriveMode = AcresSim::UtvDriveAllWheel);

FAcresBatch::Step#

Advances every environment by SubSteps physics steps.

Argument Description
Commands Size() x CommandColumnCount rows (ECommandColumn), or null to keep holding the last commands (and re-sending them). A NaN mode (or a NaN enable) in a row: no new message for that subsystem.
void Step(const double* Commands);

FAcresBatch::StepPhysics#

Advances every environment by ONE physics step under a fully formed drive-by-wire command each: the caller has already applied ds_dbw semantics (the ...Fresh flags mark a message arriving this step, the driver fields are set). This is the game's own command path (AcresPolaris.cpp StepPolarisControls), which Vehicle/ROS/acres_core_sim runs per physics step; Step's command rows and re-send clock are not used.

Argument Description
Commands Size() commands, one per environment.
void StepPhysics(const AcresSim::FDbwCommand* Commands);

FAcresBatch::SetConditions#

Sets the soil-water scenario of environments (FAcresConditions): a global antecedent fraction (NaN: farm.json), per-field fractions (Count x 60, NaN entries keep the global one; null: none), the rain film and the largest fraction of a soil cell (FAcresConditions::MaxFraction: 1.3 by default, at most 2).

void SetConditions(const int* Indices, int Count, double GlobalFraction, const double* FieldFractions, double SurfaceFilm, double MaxFraction = 1.3);

FAcresBatch::SetWinter#

Sets the winter of environments (FAcresConditions::SnowDepthM, SnowDensity, IceShare, bFrozenSoil): the snow depth (m, 0 to 2) and density (kg/m3, 50 to 550), the share of glaze ice (0 to 1), frozen soil.

void SetWinter(const int* Indices, int Count, double SnowDepthM, double SnowDensity, double IceShare, bool bFrozenSoil);

FAcresBatch::SetWeather#

Sets the weather of environments and turns their soil-water columns of the regional ground on or off (FAcresConditions::bWeather, FAcresFarmState::StartWater). The columns step in each physics step with the rain and the evaporation, in steps of 10 s of environment time (the code of the game, AcresFarm::FieldColumns). A wheel on regional soil gets the column where rain made it wetter than at the start: without rain an environment with columns gives the same bytes as one without. The call that turns the columns on gives them the start state; a later call changes the rates only. Reset and SetConditions give the start state again. The columns need the farm (FAcresBatchOptions::bFarm) and the regional fields. The default is off.

Argument Description
bOn Columns on.
RainMmH Rain rate, mm/h (0 to 200). EvapMmDay: Potential evaporation, mm/day (0 to 20; the columns lose the share evaporation_factor of farm.json). TimeScale: Environment seconds for each simulation second.
void SetWeather(const int* Indices, int Count, bool bOn, double RainMmH, double EvapMmDay, double TimeScale = 1);

FAcresBatch::SetParameters#

Replaces the Polaris parameters of environments: the batch's base parameters with these dotted-key overrides (hardware shifts, domain randomisation). Takes effect immediately (the vehicle is re-initialised; reset it).

bool SetParameters(const int* Indices, int Count, const std::map<std::string, double>& Overrides, std::string* Error = nullptr);

FAcresBatch::SetObjects#

Replaces the objects on the path of an environment (Count 0: none). The objects stay until the next call or the next Reset of the environment, and each one moves with its velocity in each physics step. The call also refreshes the collision column and ObjectContact of the environment.

Argument Description
Index The environment.
Rows Count x ObjectColumnCount (EObjectColumn).
Count The number of objects.
Ids Count numbers of the objects in their episode, for the episode log (null: the row index). An object that keeps its id over calls keeps its contact state, thus the log has one collision event for one contact.

Returns: False with Error for an index, a kind or a size that is not usable (the objects then do not change).

bool SetObjects(int Index, const double* Rows, int Count, std::string* Error = nullptr, const int* Ids = nullptr);

FAcresBatch::StartLog#

Starts recording an environment into an MCAP episode log (Docs/Design/architecture.md, "Episode Log").

bool StartLog(int Index, const std::string& Path, const std::map<std::string, std::string>& Metadata, const std::string& AgentName = "polaris", std::string* Error = nullptr);

FAcresBatch::StopLog#

Stops and closes an environment's log.

void StopLog(int Index);

FAcresBatch::FlushLog#

Writes the chunk in progress of an environment's log now and flushes its file (no log: no effect), so a reader that follows the file has each step so far. It does not change a state or a message.

void FlushLog(int Index);

FAcresBatch::AgentInfo#

An environment as the episode log describes it: its agent entry (/sim/agents), its soil-water conditions (/sim/conditions), and its state after the last physics step (/sim/agent_states) with that step's farm contacts (/sim/farm_stamps). For a caller that writes several environments into one log as the agents of one world (Vehicle/ROS/acres_core_sim); StartLog's per-environment logs use the same.

AcresLog::FAgentInfo AgentInfo(const FAcresEnv& E) const;

FAcresBatch::Scan#

Scans environments' LiDAR against the terrain and the obstacle scene, in parallel.

Argument Description
Pattern ELidarPattern.
OutRanges Count x beams ranges from the lens, m, NaN without a return (Helios: organized as the game's PCD, column x 32 + ring; planar: beam k at k deg counter-clockwise from forward). bNoise, Seed: Range noise (deterministic from the seed, the environment and the physics step).
OutMaterial Optional Count x beams hit codes (AcresCoreLidar.h EAcresLidarMaterial or a scene material).
ObjectScan How the scan sees the objects of the environment (EObjectScan). A truck has the code LidarVehicleBox and a person the code LidarPerson.
void Scan(const int* Indices, int Count, int Pattern, float* OutRanges, bool bNoise = false, uint64_t Seed = 0, uint8_t* OutMaterial = nullptr, int ObjectScan = ObjectScanAuto);

FAcresBatch::ScanCloud#

Scans with the crop model, the intensity and the motion in one sweep (FAcresScanOptions). Without bCrops and without bSweep the ranges and the materials are those of Scan.

Argument Description
Scan The options.
OutRanges Count x beams ranges, m.
OutMaterial Optional Count x beams hit codes; a crop has LidarCropCorn, LidarCropSoybean or LidarCropPotato and the grass cover has LidarGroundCover.
OutIntensity Optional Count x beams intensity bytes: the calibrated reflectivity 0-255 of the intensity field of the Helios, as the game writes it (0 without a return).
void ScanCloud(const int* Indices, int Count, int Pattern, const FAcresScanOptions& Scan, float* OutRanges, uint8_t* OutMaterial = nullptr, uint8_t* OutIntensity = nullptr);

FAcresBatch::LidarCanopy#

The crop patches of the world for the LiDAR (made at the first use; safe from many threads).

const FAcresLidarCanopy& LidarCanopy() const;

FAcresBatch::SetLidarCropState#

Gives the crops of the LiDAR the state of one day (a crop state file of the Polaris calibration: the measured height of the canopy in cells of the map, and one height for each field). A patch gets the height of its cell; with no value there, the height of its field; with no value for the field, the state of the map. The crop kind of a patch and the map do not change. Call it when no scan runs.

A file with the block "plants" also gives the plants of the places with no crop of the map (verges, strips, stubble, a field that the map has as grass): each measured cell that holds no crop patch, that is not paved and that has no object of the scene above it, with a height of plants.min_height_m or more, becomes patches of the kind FAcresLidarCanopy::KindPlants with the measured height and the measured fill of the cell. These plants are for the LiDAR only: no contact, no farm state.

Argument Description
JsonPath The file (its record file is beside it). An empty path: the state of the map again.
Error Why it failed (may be null).

Returns: True on success.

bool SetLidarCropState(const std::string& JsonPath, std::string* Error = nullptr);

FAcresBatch::LidarPattern#

The LiDAR pattern of ScanCloud with the index Pattern (LidarHelios), to change a value of its radiometry for a study (null for an index that is not a pattern). Change it between scans, not during one.

FAcresLidarPattern* LidarPattern(int Pattern) ;

FAcresBatch::LidarCropOptions#

Fills the crop part of the options of a scan as ScanCloud does with bCrops: the canopy, LidarCrops, the ground material and the grass cover from the surface class, and the crushed and the harvested samples of an environment (null: a farm without marks). For a tool that scans from a pose of its own.

void LidarCropOptions(const FAcresEnv* Env, FAcresLidarOptions& Out) const;

FAcresBatch::StepEnv#

One control step of one environment under the command row Row (CommandColumnCount values; null: no new message). Step calls it for each environment on the pool. Public for a caller that steps environments in tasks of its own (the fleet of the run-time library): one thread for one environment at a time, and the result of an environment does not depend on the others.

void StepEnv(int Index, const double* Row);

FAcresBatch::ParallelFor#

Runs Fn(i) for i in [0, Count) on the pool (blocking). Public for the LiDAR and tools.

void ParallelFor(int Count, const std::function<void(int)>& Fn);

ELidarPattern#

enum ELidarPattern : int

LiDAR patterns: LidarHelios (sensors_polaris.json, 1800 x 32) and LidarPlanar (the scouting task's 360 beams, 1 deg apart, level, 30 m) at the Helios mount.

Value Description
LidarHelios
LidarPlanar