在ros2通信编程中,总有一个和qos相关的参数:
publisher:
template<typename MessageT, typename AllocatorT, typename PublisherT>
std::shared_ptr<PublisherT>
Node::create_publisher(const std::string & topic_name,const rclcpp::QoS & qos,const PublisherOptionsWithAllocator<AllocatorT> & options)
{return rclcpp::create_publisher<MessageT, AllocatorT, PublisherT>(*this,extend_name_with_sub_namespace(topic_name, this->get_sub_namespace()),qos,options);
}
subscription:
template<typename MessageT,typename CallbackT,typename AllocatorT,typename SubscriptionT,typename MessageMemoryStrategyT>
std::shared_ptr<SubscriptionT>
Node::create_subscription(const std::string & topic_name,const rclcpp::QoS & qos,CallbackT && callback,const SubscriptionOptionsWithAllocator<AllocatorT> & options,typename MessageMemoryStrategyT::SharedPtr msg_mem_strat)
{return rclcpp::create_subscription<MessageT>(*this,extend_name_with_sub_namespace(topic_name, this->get_sub_namespace()),qos,std::forward<CallbackT>(callback),options,msg_mem_strat);
}
client:
template<typename ServiceT>
typename Client<ServiceT>::SharedPtr
Node::create_client(const std::string & service_name,const rmw_qos_profile_t & qos_profile,rclcpp::CallbackGroup::SharedPtr group)
{return rclcpp::create_client<ServiceT>(node_base_,node_graph_,node_services_,extend_name_with_sub_namespace(service_name, this->get_sub_namespace()),qos_profile,group);
}
service:
template<typename ServiceT, typename CallbackT>
typename rclcpp::Service<ServiceT>::SharedPtr
Node::create_service(const std::string & service_name,CallbackT && callback,const rmw_qos_profile_t & qos_profile,rclcpp::CallbackGroup::SharedPtr group)
{return rclcpp::create_service<ServiceT, CallbackT>(node_base_,node_services_,extend_name_with_sub_namespace(service_name, this->get_sub_namespace()),std::forward<CallbackT>(callback),qos_profile,group);
}
在话题中是必须指定qos.
QOS
The quality of service |
qos在代码层面就是一个类对象。
class RCLCPP_PUBLIC QoS
{
public:explicitQoS(const QoSInitialization & qos_initialization,const rmw_qos_profile_t & initial_profile = rmw_qos_profile_default);
}