chrono::ros::ChROSLidarHandler Class Reference

Description

Handler for publishing Lidar data to ROS via IPC communication.

PUBLISHER PATTERN (Chrono → ROS):

  • Main process: Extracts point cloud or laser scan data from ChLidarSensor
  • Main process: Serializes metadata + raw data into byte vector
  • Subprocess: Deserializes and publishes as sensor_msgs::msg::PointCloud2 or LaserScan

Data flow: ChLidarSensor → Main process → IPC → Subprocess → ROS topic

Implementation files:

  • ChROSLidarHandler.cpp: Main process logic (extract and serialize)
  • ChROSLidarHandler_ros.cpp: Subprocess ROS publisher
  • ChROSLidarHandler_ipc.h: IPC data structure definition

#include <ChROSLidarHandler.h>

Inheritance diagram for chrono::ros::ChROSLidarHandler:
Collaboration diagram for chrono::ros::ChROSLidarHandler:

Public Member Functions

 ChROSLidarHandler (std::shared_ptr< chrono::sensor::ChLidarSensor > lidar, const std::string &topic_name, ChROSLidarHandlerMessageType msg_type=ChROSLidarHandlerMessageType::POINT_CLOUD2)
 Constructor. More...
 
 ChROSLidarHandler (double update_rate, std::shared_ptr< chrono::sensor::ChLidarSensor > lidar, const std::string &topic_name, ChROSLidarHandlerMessageType msg_type=ChROSLidarHandlerMessageType::POINT_CLOUD2)
 Full constructor. More...
 
virtual bool Initialize (std::shared_ptr< ChROSInterface > interface) override
 Initializes the handler. More...
 
virtual std::vector< uint8_t > GetSerializedData (double time) override
 Extract and serialize lidar data for IPC transmission. More...
 
virtual ipc::MessageType GetMessageType () const override
 Get the message type of this handler.
 
- Public Member Functions inherited from chrono::ros::ChROSHandler
virtual ~ChROSHandler ()=default
 Destructor for the ChROSHandler.
 
const double GetUpdateRate () const
 Get the period which this handler operates at.
 
const uint64_t GetTickCount () const
 Get the number of times Tick() has been called.
 
virtual bool IsPublisher () const
 Check if this handler is a publisher (data flows from Chrono to ROS) Default is true. More...
 
virtual void PublishFromSerialized (const std::vector< uint8_t > &data, std::shared_ptr< ChROSInterface > interface)
 Publish data to ROS from serialized bytes. More...
 
virtual void ApplyFromSerialized (const std::vector< uint8_t > &data)
 Apply data to Chrono from serialized bytes. More...
 
virtual void SubscribeAndForward (std::shared_ptr< ChROSInterface > interface, std::function< void(const std::vector< uint8_t > &)> callback)
 Setup subscriber in subprocess to send data back to main process. More...
 
virtual void HandleIncomingMessage (const ipc::Message &msg)
 Handle incoming IPC message from ROS subscriber (bidirectional communication). More...
 
virtual bool SupportsIncomingMessages () const
 Returns true if this handler processes incoming IPC messages. More...
 

Additional Inherited Members

- Public Types inherited from chrono::ros::ChROSHandler
typedef chrono::ros::ipc::MessageType MessageType
 Get the message type of this handler. More...
 
- Protected Member Functions inherited from chrono::ros::ChROSHandler
 ChROSHandler (double update_rate)
 Constructor for the ChROSHandler. More...
 
void IncrementTickCount ()
 Increment the tick count.
 

Constructor & Destructor Documentation

◆ ChROSLidarHandler() [1/2]

chrono::ros::ChROSLidarHandler::ChROSLidarHandler ( std::shared_ptr< chrono::sensor::ChLidarSensor lidar,
const std::string &  topic_name,
ChROSLidarHandlerMessageType  msg_type = ChROSLidarHandlerMessageType::POINT_CLOUD2 
)

Constructor.

The update rate is set to lidar->GetUpdateRate().

Parameters
lidarLidar sensor to publish data from
topic_nameROS topic to publish data to
msg_typeType of ROS message to publish (POINT_CLOUD2 or LASER_SCAN)

◆ ChROSLidarHandler() [2/2]

chrono::ros::ChROSLidarHandler::ChROSLidarHandler ( double  update_rate,
std::shared_ptr< chrono::sensor::ChLidarSensor lidar,
const std::string &  topic_name,
ChROSLidarHandlerMessageType  msg_type = ChROSLidarHandlerMessageType::POINT_CLOUD2 
)

Full constructor.

Takes a ChLidarSensor, update rate, and topic name.

Parameters
update_rateRate at which to publish data (Hz)
lidarLidar sensor to publish data from
topic_nameROS topic to publish data to
msg_typeType of ROS message to publish (POINT_CLOUD2 or LASER_SCAN)

Member Function Documentation

◆ GetSerializedData()

std::vector< uint8_t > chrono::ros::ChROSLidarHandler::GetSerializedData ( double  time)
overridevirtual

Extract and serialize lidar data for IPC transmission.

Called in main process at update_rate frequency. Returns metadata + raw data as byte vector.

Parameters
timeCurrent simulation time
Returns
Serialized lidar data (header + data)

Reimplemented from chrono::ros::ChROSHandler.

◆ Initialize()

bool chrono::ros::ChROSLidarHandler::Initialize ( std::shared_ptr< ChROSInterface interface)
overridevirtual

Initializes the handler.

In IPC mode, validates sensor has required filter, but doesn't create ROS publisher.

Implements chrono::ros::ChROSHandler.


The documentation for this class was generated from the following files:
  • /builds/uwsbel/chrono/src/chrono_ros/handlers/sensor/ChROSLidarHandler.h
  • /builds/uwsbel/chrono/src/chrono_ros/handlers/sensor/ChROSLidarHandler.cpp