[WARN] [1644578813.965216245] [subscriber_qos_obj]: New publisher discovered on topic '/qos_test', offering incompatible QoS. No messages will be received from it. Last incompatible policy: RELIABILITY
// Create a publisher using the QoS settings to emulate a ROS1 latched topic occ_pub_ = create_publisher<nav_msgs::msg::OccupancyGrid>( topic_name, rclcpp::QoS(rclcpp::KeepLast(1)).transient_local().reliable());
/// Constant representing an infinite duration. Use rmw_time_equal for comparisons. /** * Different RMW implementations have different representations for infinite durations. * This value is reported for QoS policy durations that are left unspecified. * Do not directly compare `sec == sec && nsec == nsec`, because we don't want to be sensitive * to non-normalized values (nsec > 1 second) - use rmw_time_equal instead. * This value is INT64_MAX nanoseconds = 0x7FFF FFFF FFFF FFFF = d 9 223 372 036 854 775 807 * * Note: these constants cannot be `static const rmw_time_t` because in C that can't be used * as a compile-time initializer */ #define RMW_DURATION_INFINITE {9223372036LL, 854775807LL} #define RMW_DURATION_UNSPECIFIED {0LL, 0LL}
import argparse import rclpy from rclpy.node import Node from std_msgs.msg import String from rclpy.qos_event import PublisherEventCallbacks from rclpy.duration import Duration from rclpy.qos import QoSProfile from rclpy.qos import QoSDurabilityPolicy from rclpy.qos import QoSLivelinessPolicy from rclpy.qos import QoSReliabilityPolicy
# This is the Unique id for each of the messages that will be sent self.msgs_id = 0 #self.current_time = self.get_clock().now() self.current_time_s = 0 self.current_time_ns = 0 # define the timer period for 0.5 seconds timer_period = 0.5 # create a timer sending two parameters: # - the duration between 2 callbacks (0.5 seeconds) # - the timer function (timer_callback) self.timer = self.create_timer(timer_period, self.timer_callback)
defincompatible_qos_clb(self, event): """ This is the callback that will be executed when the Event of **Incompatible QoS** is triggered. """ self.get_logger().error("A subscriber is asking for an INCOMPATIBLE QoS Triggered!!") self.get_logger().error(str(event.last_policy_kind)) self.get_logger().error("############################")
deftimer_callback(self): # Here we have the callback method msg = String() test_time = self.get_clock().now() self.current_time_s, self.current_time_ns = test_time.seconds_nanoseconds() time_str = str(self.current_time_s)+","+str(self.current_time_ns) dds_msg_str = str(self.msgs_id)+":"+time_str msg.data = dds_msg_str # Publish the message to the topic self.publisher_.publish(msg) # Display the message on the console self.get_logger().info('Publishing: "%s"' % msg)
self.msgs_id += 1
defget_parser(): parser = argparse.ArgumentParser() parser.add_argument( '-reliability', type=str, choices=['best_effort', 'reliable'], help='Select Policy for reliability, use ros2 run dds_tests_pkg publisher_dds_custom_qos_exe -reliability best_effort|reliable') return parser
# initialize the ROS communication rclpy.init(args=args) # declare the node constructor pub_qos_obj = PublisherQoS(qos_profile_publisher) # pause the program execution, waits for a request to kill the node (ctrl+c) rclpy.spin(pub_qos_obj) # Explicity destroy the node pub_qos_obj.destroy_node() # shutdown the ROS communication rclpy.shutdown()
if __name__ == '__main__': main()
按照下面的方式启动能正常收发
1 2
export RMW_IMPLEMENTATION=rmw_cyclonedds_cpp #指定中间通信件 ros2 run qos_tests_pkg publisher_custom_minimal_qos_exe -reliability reliable
1 2
export RMW_IMPLEMENTATION=rmw_cyclonedds_cpp #指定中间通信件 ros2 run qos_tests_pkg subscriber_custom_minimal_qos_exe
[INFO] [1644578723.015739998] [subscriber_qos_obj]: Data Received =0:1644578722,985456932 [INFO] [1644578723.486751033] [subscriber_qos_obj]: Data Received =1:1644578723,485332074 [INFO] [1644578723.986497548] [subscriber_qos_obj]: Data Received =2:1644578723,985345254 [INFO] [1644578724.486954816] [subscriber_qos_obj]: Data Received =3:1644578724,485467771 [INFO] [1644578724.986790852] [subscriber_qos_obj]: Data Received =4:1644578724,985333069 [INFO] [1644578725.486864984] [subscriber_qos_obj]: Data Received =5:1644578725,485435341 [INFO] [1644578725.986921274] [subscriber_qos_obj]: Data Received =6:1644578725,985460097 [INFO] [1644578726.486804679] [subscriber_qos_obj]: Data Received =7:1644578726,485332301 [INFO] [1644578726.986422874] [subscriber_qos_obj]: Data Received =8:1644578726,985357784
按Qos不兼容的方式启动
1 2
export RMW_IMPLEMENTATION=rmw_cyclonedds_cpp #指定中间通信件 ros2 run qos_tests_pkg publisher_custom_minimal_qos_exe -reliability best_effort
1 2
export RMW_IMPLEMENTATION=rmw_cyclonedds_cpp #指定中间通信件 ros2 run qos_tests_pkg subscriber_custom_minimal_qos_exe
[WARN] [1644578813.965216245] [subscriber_qos_obj]: New publisher discovered on topic '/qos_test', offering incompatible QoS. No messages will be received from it. Last incompatible policy: RELIABILITY