@@ -448,7 +448,9 @@ void MqttClient::loadParameters() {
448
448
rclcpp::Parameter durability_param;
449
449
if (get_parameter (fmt::format (" bridge.ros2mqtt.{}.advanced.ros.qos.durability" , mqtt_topic), durability_param)) {
450
450
const auto p = durability_param.as_string ();
451
- if (p == " volatile" ) {
451
+ if (p == " system_default" ) {
452
+ ros2mqtt.ros .qos .durability = rclcpp::DurabilityPolicy::SystemDefault;
453
+ } else if (p == " volatile" ) {
452
454
ros2mqtt.ros .qos .durability = rclcpp::DurabilityPolicy::Volatile;
453
455
} else if (p == " transient_local" ) {
454
456
ros2mqtt.ros .qos .durability = rclcpp::DurabilityPolicy::TransientLocal;
@@ -463,7 +465,9 @@ void MqttClient::loadParameters() {
463
465
rclcpp::Parameter reliability_param;
464
466
if (get_parameter (fmt::format (" bridge.ros2mqtt.{}.advanced.ros.qos.reliability" , mqtt_topic), reliability_param)) {
465
467
const auto p = reliability_param.as_string ();
466
- if (p == " best_effort" ) {
468
+ if (p == " system_default" ) {
469
+ ros2mqtt.ros .qos .reliability = rclcpp::ReliabilityPolicy::SystemDefault;
470
+ } else if (p == " best_effort" ) {
467
471
ros2mqtt.ros .qos .reliability = rclcpp::ReliabilityPolicy::BestEffort;
468
472
} else if (p == " reliable" ) {
469
473
ros2mqtt.ros .qos .reliability = rclcpp::ReliabilityPolicy::Reliable;
@@ -538,7 +542,9 @@ void MqttClient::loadParameters() {
538
542
rclcpp::Parameter durability_param;
539
543
if (get_parameter (fmt::format (" bridge.mqtt2ros.{}.advanced.ros.qos.durability" , mqtt_topic), durability_param)) {
540
544
const auto p = durability_param.as_string ();
541
- if (p == " volatile" ) {
545
+ if (p == " system_default" ) {
546
+ mqtt2ros.ros .qos .durability = rclcpp::DurabilityPolicy::SystemDefault;
547
+ } else if (p == " volatile" ) {
542
548
mqtt2ros.ros .qos .durability = rclcpp::DurabilityPolicy::Volatile;
543
549
} else if (p == " transient_local" ) {
544
550
mqtt2ros.ros .qos .durability =
@@ -552,7 +558,9 @@ void MqttClient::loadParameters() {
552
558
rclcpp::Parameter reliability_param;
553
559
if (get_parameter (fmt::format (" bridge.mqtt2ros.{}.advanced.ros.qos.reliability" , mqtt_topic), reliability_param)) {
554
560
const auto p = reliability_param.as_string ();
555
- if (p == " best_effort" ) {
561
+ if (p == " system_default" ) {
562
+ mqtt2ros.ros .qos .reliability = rclcpp::ReliabilityPolicy::SystemDefault;
563
+ } else if (p == " best_effort" ) {
556
564
mqtt2ros.ros .qos .reliability = rclcpp::ReliabilityPolicy::BestEffort;
557
565
} else if (p == " reliable" ) {
558
566
mqtt2ros.ros .qos .reliability = rclcpp::ReliabilityPolicy::Reliable;
@@ -664,6 +672,8 @@ void MqttClient::setup() {
664
672
check_subscriptions_timer_ =
665
673
create_wall_timer (std::chrono::duration<double >(1.0 ),
666
674
std::bind (&MqttClient::setupSubscriptions, this ));
675
+
676
+ setupPublishers ();
667
677
}
668
678
669
679
std::optional<rclcpp::QoS> MqttClient::getCompatibleQoS (const std::string &ros_topic, const rclcpp::TopicEndpointInfo &tei,
@@ -812,6 +822,31 @@ void MqttClient::setupSubscriptions() {
812
822
}
813
823
}
814
824
825
+ void MqttClient::setupPublishers () {
826
+
827
+ for (auto & [mqtt_topic, mqtt2ros] : mqtt2ros_) {
828
+ if (mqtt2ros.ros .publisher )
829
+ continue ;
830
+
831
+ // If the type is not fixed, we require a mqtt message in order to deduce the type
832
+ if (!mqtt2ros.fixed_type )
833
+ continue ;
834
+
835
+ try {
836
+ const auto qos = rclcpp::QoS (mqtt2ros.ros .queue_size )
837
+ .durability (mqtt2ros.ros .qos .durability )
838
+ .reliability (mqtt2ros.ros .qos .reliability );
839
+ mqtt2ros.ros .publisher = create_generic_publisher (
840
+ mqtt2ros.ros .topic , mqtt2ros.ros .msg_type , qos);
841
+
842
+ mqtt2ros.ros .is_stale = false ;
843
+ } catch (const rclcpp::exceptions::RCLError& e) {
844
+ RCLCPP_ERROR (get_logger (), " Failed to create generic publisher: %s" ,
845
+ e.what ());
846
+ }
847
+ }
848
+ }
849
+
815
850
void MqttClient::setupClient () {
816
851
817
852
// basic client connection options
@@ -1210,6 +1245,7 @@ void MqttClient::mqtt2fixed(mqtt::const_message_ptr mqtt_msg) {
1210
1245
} catch (const rclcpp::exceptions::RCLError& e) {
1211
1246
RCLCPP_ERROR (get_logger (), " Failed to create generic publisher: %s" ,
1212
1247
e.what ());
1248
+ return ;
1213
1249
}
1214
1250
}
1215
1251
0 commit comments