Skip to content

conversions.hpp#

ROS/acres_sim/include/acres_sim/conversions.hpp Generated

Conversions between the game's stream frames and JSON lines and the vehicles' ROS 2 messages: the INS epoch to odometry, TF, ground truth, NavSatFix, Imu (the OxTS AV200 mounting on the Polaris) and TwistStamped; the DBW reports; the DBW and tractor commands to the RL bridge's JSON; a UTM reset pose to the game's reset command; the camera intrinsics and the Maxxum's mounts from the stream's hello. Everything here is a pure function (unit tested, test/test_conversions.cpp) and matches the Python bridge (acres_ros/sim_bridge.py) value for value.

Name Type Unit Default Description
Quat using std::array<double, 4> Quaternion x, y, z, w.
Vec3 using std::array<double, 3> Vector x, y, z.
kOxtsMount extern const Quat OxTS AV200 mounting on the Ranger (ds_localization v2b roll 0, pitch 180, yaw -90 deg; navroute.md A7): the IMU frame is the body frame rotated by Rz(-90) Ry(180), i.e. x = left, y = forward, z = down.
kPolarisCameraFrame extern const char* const Frame of the Polaris' Reolink camera (purdue_ranger URDF and polaris_ranger.urdf.xacro).

to_stamp#

A ROS time from seconds, as the Python bridge's stamp(): floor seconds, nanoseconds rounded half to even and capped at 999999999.

Argument Description
seconds Time, s.

Returns: The stamp.

builtin_interfaces::msg::Time to_stamp(double seconds);

from_stamp#

Seconds of a ROS time.

Argument Description
stamp The stamp.

Returns: Seconds.

double from_stamp(const builtin_interfaces::msg::Time& stamp);

quat_mul#

Hamilton product a * b.

Argument Description
a Left quaternion.
b Right quaternion.

Returns: The product.

Quat quat_mul(const Quat& a, const Quat& b);

quat_from_rpy#

ROS fixed-axis roll, pitch, yaw (R = Rz Ry Rx) in radians to a quaternion.

Argument Description
roll rad.
pitch rad.
yaw rad.

Returns: The quaternion.

Quat quat_from_rpy(double roll, double pitch, double yaw);

oxts_vector#

Body FLU vector to the OxTS IMU axes (x = left, y = forward, z = down).

Argument Description
v Body vector.

Returns: The vector in IMU axes.

Vec3 oxts_vector(const Vec3& v);

ins_to_messages#

Converts one INS epoch (kInsFields float64) to its messages.

Argument Description
v The payload values.
stamp_s Frame stamp, simulation time s.
frames The bridge's frames.
out The messages.
void ins_to_messages(const double* v, double stamp_s, const VehicleFrames& frames, InsMessages& out);

dbw_reports_from_json#

Converts a "dbw_report" line (AcresRlBridge.h) to the ds_dbw_msgs reports, with the constant fields the vehicle sends (ready, the steering limits 1000 deg/s and 487 deg, actuator temperatures -40 degC, NaN for the brake's torque, acceleration and input fields, infinite throttle and brake limits).

Argument Description
line The parsed line.
stamp Its world time (the report's vehicle time plus the stream's clock offset).

Returns: The reports.

DbwReports dbw_reports_from_json(const Json& line, const builtin_interfaces::msg::Time& stamp);

steering_cmd_json#

{"steering_cmd": {...}} of a SteeringCmd (ds_dbw_msgs field names and units, one to one).

Json steering_cmd_json(const ds_dbw_msgs::msg::SteeringCmd& m);

throttle_cmd_json#

{"throttle_cmd": {...}} of a ThrottleCmd.

Json throttle_cmd_json(const ds_dbw_msgs::msg::ThrottleCmd& m);

brake_cmd_json#

{"brake_cmd": {...}} of a BrakeCmd.

Json brake_cmd_json(const ds_dbw_msgs::msg::BrakeCmd& m);

gear_cmd_json#

{"gear_cmd": {"cmd": n}} of a GearCmd, or nothing for gear 0 (none), which the Python bridge did not forward.

std::optional<Json> gear_cmd_json(const ds_dbw_msgs::msg::GearCmd& m);

ulc_cmd_json#

{"ulc_cmd": {...}} of a UlcCmd.

Json ulc_cmd_json(const ds_dbw_msgs::msg::UlcCmd& m);

reset_command#

The game's reset command for a UTM pose of base_footprint (frame utm, grid heading), converted with the INS's own georeference (the latest epoch's UTM and grid ENU of the same point), so the vehicle lands where odometry will report it.

Argument Description
pose The pose (position x easting, y northing; orientation yaw counter-clockwise from UTM east).
ins The latest INS epoch (kInsFields values).
body_origin_flu_m The hello's body_origin_flu_m (the body origin seen from base_footprint), x and y.
summary Optional log text.

Returns: {"reset": {"x", "y", "yaw_deg", "speed", "restore_field"}} (world metres X east, Y south; Unreal yaw).

Json reset_command(const geometry_msgs::msg::Pose& pose, const double* ins, const std::array<double, 2>& body_origin_flu_m, std::string* summary = nullptr);

camera_info_from_hello#

Camera intrinsics from the stream's hello, when the camera is enabled and has them.

Argument Description
hello The hello JSON.
frame_id The camera's optical frame.

Returns: The CameraInfo (plumb_bob, P from K), or nothing.

std::optional<sensor_msgs::msg::CameraInfo> camera_info_from_hello(const Json& hello, const std::string& frame_id);

mount_transforms#

The Maxxum's static transforms from the hello's mounts: base_footprint to lidar, camera (and camera to camera_optical), imu_link and gnss_link.

Argument Description
hello The hello JSON.
frames The bridge's frames.
lidar_frame LiDAR frame with the prefix.
camera_optical_frame Camera optical frame with the prefix.

Returns: The transforms (stamps zero, as the Python bridge sent them).

std::vector<geometry_msgs::msg::TransformStamped> mount_transforms(const Json& hello, const VehicleFrames& frames, const std::string& lidar_frame, const std::string& camera_optical_frame);

implement_state_json#

The Maxxum's implement state string: json.dumps of the observation's implement keys, in their fixed order.

Argument Description
observation The RL observation line.

Returns: The JSON text.

std::string implement_state_json(const Json& observation);

to_can_msg#

A can_msgs/Frame as ros2_socketcan's receiver publishes it (id without the flag bits, is_extended from the EFF flag, frame_id "can").

Argument Description
frame The raw frame.
stamp Header stamp.

Returns: The message.

can_msgs::msg::Frame to_can_msg(const CanFrame& frame, const builtin_interfaces::msg::Time& stamp);

from_can_msg#

The raw frame of a can_msgs/Frame, as ros2_socketcan's sender writes it.

Argument Description
msg The message.

Returns: The frame (EFF, RTR and ERR flags from is_extended, is_rtr, is_error; dlc capped at 8).

CanFrame from_can_msg(const can_msgs::msg::Frame& msg);

VehicleFrames#

struct VehicleFrames

Frame names of one vehicle bridge.

VehicleFrames::base#

base_footprint with the prefix.

std::string base() const ;

InsMessages#

struct InsMessages

The messages of one INS epoch. The georeferenced ones (odom, tf, truth, fix) are filled only when georef is true.

DbwReports#

struct DbwReports

The Polaris' drive-by-wire reports of one "dbw_report" line.