json.hpp#
ROS/acres_sim/include/acres_sim/json.hpp Generated
JSON helpers shared by the game's line protocols (the RL / drive-by-wire bridge and the simulator control channel).
The text the bridge writes is byte for byte what the Python bridge (acres_ros, json.dumps) wrote: the same float spelling (Python's shortest repr), the same separators and the same ASCII escaping, so the game sees identical commands whichever bridge runs, and the implement state published on ROS is the same string.
| Name | Type | Unit | Default | Description |
|---|---|---|---|---|
Json |
using |
nlohmann::ordered_json |
JSON value that keeps the key order of its source (Python dicts do too). |
python_float_repr#
Python's repr() of a float: the shortest decimal that round-trips, fixed notation for exponents -4..15, with a trailing ".0" for integral values; "NaN", "Infinity" and "-Infinity" as json.dumps writes them.
| Argument | Description |
|---|---|
value |
The number. |
Returns: Its spelling, e.g. "0.1", "1.0", "1e-05", "1e+16".
python_dumps#
json.dumps(value) (compact = false: separators ", " and ": ") or json.dumps(value, separators=(",", ":")).
| Argument | Description |
|---|---|
value |
The JSON value. |
compact |
Separators without spaces. |
Returns: The text, ASCII only (other characters as \uXXXX escapes, as ensure_ascii does).
finite#
A finite number for the game's JSON parser, which has no NaN or Infinity literals: NaN becomes 0 and an infinity +-1e9 (ds_dbw_msgs uses INFINITY for "unlimited"), as acres_ros stream._finite.
| Argument | Description |
|---|---|
value |
The number. |
Returns: The finite number.
finite_message#
Applies finite() to the top-level values of a message and to the values of its nested objects, one level deep, as the Python JsonBridge.send did before writing a command.
| Argument | Description |
|---|---|
message |
A command object, e.g. {"steering_cmd": {...}}. |
Returns: The message with every such float finite.
get_number#
float(obj.get(key, fallback)) of the Python bridge: numbers and booleans convert, anything else gives fallback.
| Argument | Description |
|---|---|
object |
A JSON object (anything else gives fallback). |
key |
The key. |
fallback |
Value when the key is missing or not a number. |
Returns: The number.
get_int#
int(obj.get(key, fallback)): numbers truncate toward zero, booleans give 0 or 1.
| Argument | Description |
|---|---|
object |
A JSON object. |
key |
The key. |
fallback |
Value when the key is missing or not a number. |
Returns: The integer.
get_truthy#
bool(obj.get(key)): Python truthiness (missing or null false, numbers non-zero, strings, arrays and objects non-empty).
| Argument | Description |
|---|---|
object |
A JSON object. |
key |
The key. |
Returns: The truth value.
get_object#
obj.get(key, {}) for a nested object: a reference to the member if it is an object, else to an empty object.
| Argument | Description |
|---|---|
object |
A JSON object. |
key |
The key. |
Returns: The nested object or an empty one.