Add the ability to control the depth and reliability of the /scan topic
This commit is contained in:
@@ -18,6 +18,8 @@ def generate_launch_description():
|
||||
inverted = LaunchConfiguration('inverted', default='false')
|
||||
angle_compensate = LaunchConfiguration('angle_compensate', default='true')
|
||||
scan_mode = LaunchConfiguration('scan_mode', default='Sensitivity')
|
||||
scan_qos_depth = LaunchConfiguration('scan_qos_depth', default='10')
|
||||
scan_qos_reliability = LaunchConfiguration('scan_qos_reliability', default='reliable')
|
||||
|
||||
return LaunchDescription([
|
||||
|
||||
@@ -55,17 +57,28 @@ def generate_launch_description():
|
||||
default_value=scan_mode,
|
||||
description='Specifying scan mode of lidar'),
|
||||
|
||||
DeclareLaunchArgument(
|
||||
'scan_qos_depth',
|
||||
default_value=scan_qos_depth,
|
||||
description='Queue depth for the /scan publisher'),
|
||||
|
||||
DeclareLaunchArgument(
|
||||
'scan_qos_reliability',
|
||||
default_value=scan_qos_reliability,
|
||||
description='Reliability policy for the /scan publisher: best_effort or reliable'),
|
||||
|
||||
Node(
|
||||
package='sllidar_ros2',
|
||||
executable='sllidar_node',
|
||||
name='sllidar_node',
|
||||
parameters=[{'channel_type':channel_type,
|
||||
'serial_port': serial_port,
|
||||
'serial_baudrate': serial_baudrate,
|
||||
parameters=[{'channel_type': channel_type,
|
||||
'serial_port': serial_port,
|
||||
'serial_baudrate': serial_baudrate,
|
||||
'frame_id': frame_id,
|
||||
'inverted': inverted,
|
||||
'angle_compensate': angle_compensate}],
|
||||
'inverted': inverted,
|
||||
'angle_compensate': angle_compensate,
|
||||
'scan_qos_depth': scan_qos_depth,
|
||||
'scan_qos_reliability': scan_qos_reliability}],
|
||||
output='screen'),
|
||||
])
|
||||
|
||||
|
||||
@@ -58,9 +58,24 @@ class SLlidarNode : public rclcpp::Node
|
||||
SLlidarNode()
|
||||
: Node("sllidar_node")
|
||||
{
|
||||
// QoS parameters must be declared here because the publisher is created
|
||||
// before init_param() is called in work_loop().
|
||||
this->declare_parameter<int>("scan_qos_depth", 2);
|
||||
this->declare_parameter<std::string>("scan_qos_reliability", "best_effort");
|
||||
|
||||
scan_pub = this->create_publisher<sensor_msgs::msg::LaserScan>("scan", rclcpp::QoS(rclcpp::KeepLast(2)).best_effort());
|
||||
|
||||
int qos_depth;
|
||||
std::string qos_reliability;
|
||||
this->get_parameter_or<int>("scan_qos_depth", qos_depth, 2);
|
||||
this->get_parameter_or<std::string>("scan_qos_reliability", qos_reliability, "best_effort");
|
||||
|
||||
auto qos = rclcpp::QoS(rclcpp::KeepLast(qos_depth));
|
||||
if (qos_reliability == "best_effort") {
|
||||
qos.best_effort();
|
||||
} else {
|
||||
qos.reliable();
|
||||
}
|
||||
|
||||
scan_pub = this->create_publisher<sensor_msgs::msg::LaserScan>("scan", qos);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user