ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I f

Found the following which seems to work, i.e. using spin_some insted of spin_once (which is available only in the Python API).

.
.
.
 rmw_qos_profile_t custom_qos_profile = rmw_qos_profile_default;
 custom_qos_profile.depth = 7;

 auto node           = rclcpp::Node::make_shared("IMU_node");
 auto imu_publisher  = node->create_publisher<sensor_msgs::msg::Imu>("Imu_topic", custom_qos_profile.depth);

 while(rclcpp::ok())
 {
     std::string buf = imu.SerialReadLine();

     // Do some conversion of data from buf to parsed_val vector
     // .
     // .
     // Fill the imu_msg
     imu_msg_->orientation.x = parsed_val_[0];
     imu_msg_->orientation.y = parsed_val_[1];
     imu_msg_->orientation.z = parsed_val_[2];
     imu_msg_->orientation.w = parsed_val_[3];

     // Publish the msg
     imu_publisher->publish(*imu_msg_);
     rclcpp::spin_some(node);
  }

So there is no continuously spinning node, publish method called only when an input arrived.

I f

Found the following which seems to work, i.e. using spin_some insted of spin_once (which is available only in the Python API).

.
.
.
 rmw_qos_profile_t custom_qos_profile = rmw_qos_profile_default;
 custom_qos_profile.depth = 7;

 auto node           = rclcpp::Node::make_shared("IMU_node");
 auto imu_publisher  = node->create_publisher<sensor_msgs::msg::Imu>("Imu_topic", custom_qos_profile.depth);

 while(rclcpp::ok())
 {
     std::string buf = imu.SerialReadLine();

     // Do some conversion of data from buf to parsed_val vector
     // .
     // .
     // Fill the imu_msg
     imu_msg_->orientation.x = parsed_val_[0];
     imu_msg_->orientation.y = parsed_val_[1];
     imu_msg_->orientation.z = parsed_val_[2];
     imu_msg_->orientation.w = parsed_val_[3];

     // Publish the msg
     imu_publisher->publish(*imu_msg_);
     rclcpp::spin_some(node);
  }

So there is no continuously spinning node, publish method called only when an input arrived.

Found the following which seems to work, i.e. using spin_some insted of spin_once (which is available only in the Python API).

.
.
.
 rmw_qos_profile_t custom_qos_profile = rmw_qos_profile_default;
 custom_qos_profile.depth = 7;

 auto node           = rclcpp::Node::make_shared("IMU_node");
 auto imu_publisher  = node->create_publisher<sensor_msgs::msg::Imu>("Imu_topic", custom_qos_profile.depth);
 auto imu_msg_       = std::make_shared<sensor_msgs::msg::Imu>();

 while(rclcpp::ok())
 {
     std::string buf = imu.SerialReadLine();

     // Do some conversion of data from buf to parsed_val vector
     // .
     // .
     // Fill the imu_msg
     imu_msg_->orientation.x = parsed_val_[0];
     imu_msg_->orientation.y = parsed_val_[1];
     imu_msg_->orientation.z = parsed_val_[2];
     imu_msg_->orientation.w = parsed_val_[3];

     // Publish the msg
     imu_publisher->publish(*imu_msg_);
     rclcpp::spin_some(node);
  }

So there is no continuously spinning node, publish method called only when an input arrived.