Skip to content

vehicle_bridge.hpp#

ROS/acres_sim/include/acres_sim/vehicle_bridge.hpp Generated

One vehicle of the running game on the topics its real counterpart uses (the C++ successor of acres_ros sim_bridge.py, topic for topic, frame for frame and value for value).

Polaris (the Purdue Ranger's topics, relative to the bridge's namespace): vehicle/odom and /tf (utm -> base_footprint), oxts/imu (OxTS mounting: x left, y forward, z down), oxts/velocity (angular deg/s), oxts/fix, lidar/points (1800 x 32 organized, x y z intensity float32, NaN where no return), camera/image_raw (bgr8) and camera/camera_info, vehicle/{steering,throttle,brake,gear,ulc}/report, vehicle/vehicle_velocity, vehicle/dbw_enabled, sim/ground_truth/odom and /clock; commands vehicle/{steering,throttle,brake,gear,ulc}/cmd, vehicle/enable, vehicle/disable, and sim/reset (a UTM pose).

Maxxum: odom, ground_truth/odom, imu/data, gnss/fix, lidar/points, camera/*, engine_rpm, steering_angle, implement/state (JSON) and static TF from the game's mounts; commands cmd_vel, guidance/curvature_cmd + speed_cmd (a PI speed loop on the pedal, run on simulation time), hitch/lever_cmd, hitch/raise_cmd, pto/cmd, hand_throttle_cmd, implement/cmd; with can_udp_port the tractor's J1939 bus on can/rx and can/tx (can_msgs/Frame, as ros2_socketcan's receiver and sender with from_can_bus:=can/rx, to_can_bus:=can/tx).

Threads: the sensor stream reader publishes the clock, the INS messages and the Maxxum's guidance commands itself, and hands LiDAR clouds and camera images to a publisher thread through a small bounded queue (dropped and counted when full), so a slow subscriber never delays odometry or /clock; the JSON reader publishes the DBW reports; the executor runs the command callbacks, which forward each command to the game at once.

Lockstep: the game ends every step request with a barrier on each channel (sensor-stream frame type 6, JSON line {"type": "barrier", "step": N}, and on the CAN bus a frame of PGN 0xFF1E from 0x80 with the step, which is not published on can/rx). A barrier counts as reached here only once everything that came before it on its channel has been published (the stream's barrier passes through the publisher queue behind the clouds and images), so the control client (sim_control.hpp) can answer a step request after wait_barrier().

vehicle_qos#

Reliable, volatile, depth 10: the QoS of every vehicle topic, as the vehicle's recorders saw them.

rclcpp::QoS vehicle_qos();

BridgeConfig#

struct BridgeConfig

Parameters of one vehicle bridge (the node parameters of the same names).

VehicleBridge#

class VehicleBridge

The bridge of one vehicle.

VehicleBridge::VehicleBridge#

Creates the publishers and subscriptions (at once for a known vehicle, at the stream's hello for "auto").

Argument Description
node The bridge's node: publishers, TF, parameters, logging, namespace.
command_node The node that owns command_group; command subscriptions are created on it with names resolved in node's namespace (the same node for a single vehicle).
command_group The mutually exclusive group shared with the lockstep step service and action.
config Ports, vehicle, frames.
label Name for the log (the agent name, or "sim_bridge").
VehicleBridge(rclcpp::Node::SharedPtr node, rclcpp::Node::SharedPtr command_node, rclcpp::CallbackGroup::SharedPtr command_group, BridgeConfig config, std::string label);

VehicleBridge::~VehicleBridge#

Stops the threads.

~VehicleBridge();

VehicleBridge::start#

Starts the stream, publisher, JSON and CAN threads.

void start();

VehicleBridge::stop#

Stops every thread and wakes barrier waits.

void stop();

VehicleBridge::drain_commands#

Forwards the commands that wait in the subscriptions' queues now (lockstep: before a step is requested). Call from the command group only.

Returns: Commands forwarded.

size_t drain_commands();

VehicleBridge::barrier_mark#

The channels' barrier state now (before sending a step request).

BarrierMark barrier_mark() const;

VehicleBridge::wait_barrier#

Waits until every channel required by mark has published its barrier for step (or a later one).

Argument Description
mark From barrier_mark() before the request.
step The barrier step of the reply.
deadline Give up then.
missing What is missing on failure.

Returns: True when every required barrier arrived.

bool wait_barrier(const BarrierMark& mark, uint64_t step, std::chrono::steady_clock::time_point deadline, std::string* missing);

VehicleBridge::sim_time_s#

Latest simulation time seen on the stream (clock and INS stamps), s; 0 before the first.

double sim_time_s() const ;

VehicleBridge::write_stats#

Writes the statistics file (stats_file), if one was given.

void write_stats();

VehicleBridge::label#

The log label.

const std::string& label() const ;

BarrierMark#

struct BarrierMark

State of both channels when a lockstep request is sent: which barriers are awaited and from which count on.