translate Velodyne LiDAR plugin code to ros2

asked 2021-02-24 06:12:47 -0500

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

Hi I want to translate the Velodyne LiDAR plugin script from ros1 to ros2.: there is three blocks of code which are added to plugin code to create a node and a topic and subscribe to it:


private: std::unique_ptr<ros::NodeHandle> rosNode;
private: ros::Subscriber rosSub;
private: ros::CallbackQueue rosQueue;
private: std::thread rosQueueThread;


// Initialize ros, if it has not already bee initialized.
if (!ros::isInitialized())
  int argc = 0;
  char **argv = NULL;

      ros::init(argc, argv, "gazebo_client",

// Create our ROS node. This acts in a similar manner to
// the Gazebo node
this->rosNode.reset(new ros::NodeHandle("gazebo_client"));

// Create a named topic, and subscribe to it.
ros::SubscribeOptions so =
      "/" + this->model->GetName() + "/vel_cmd",
      boost::bind(&VelodynePlugin::OnRosMsg, this, _1),
      ros::VoidPtr(), &this->rosQueue);
      this->rosSub = this->rosNode->subscribe(so);

// Spin up the queue helper thread.
this->rosQueueThread =
  std::thread(std::bind(&VelodynePlugin::QueueThread, this));


public: void OnRosMsg(const std_msgs::Float32ConstPtr &_msg)

/// \brief ROS helper function that processes messages
private: void QueueThread()
  static const double timeout = 0.01;
  while (this->rosNode->ok())

i have tried common methods which are used to create a ros2 node but i get many errors like other people:

I really appreciate any help to solve this problem.

edit retag flag offensive close merge delete