mirror of
https://gitee.com/xiaohuolufeihua/bizhang_-obav.git
synced 2026-05-21 01:12:11 +00:00
apply ROS2 default memory management and publish mode QoS policies; make sure that SharedMemory is only used with FastDDS as the rmw
This commit is contained in:
@@ -100,14 +100,18 @@ bool @(topic)_Publisher::init(const std::string &ns)
|
|||||||
PParam.rtps.builtin.leaseDuration = c_TimeInfinite;
|
PParam.rtps.builtin.leaseDuration = c_TimeInfinite;
|
||||||
@[else]@
|
@[else]@
|
||||||
PParam.rtps.builtin.discovery_config.leaseDuration = c_TimeInfinite;
|
PParam.rtps.builtin.discovery_config.leaseDuration = c_TimeInfinite;
|
||||||
|
@[end if]@
|
||||||
|
@[if ros2_distro]@
|
||||||
|
// ROS2 default memory management policy
|
||||||
|
PParam.rtps.builtin.writerHistoryMemoryPolicy = PREALLOCATED_WITH_REALLOC_MEMORY_MODE;
|
||||||
@[end if]@
|
@[end if]@
|
||||||
std::string nodeName = ns;
|
std::string nodeName = ns;
|
||||||
nodeName.append("@(topic)_publisher");
|
nodeName.append("@(topic)_publisher");
|
||||||
PParam.rtps.setName(nodeName.c_str());
|
PParam.rtps.setName(nodeName.c_str());
|
||||||
|
|
||||||
// Check if ROS_LOCALHOST_ONLY is set. This means that one wants to use
|
// Check if ROS_LOCALHOST_ONLY is set. This means that one wants to use only
|
||||||
// only the localhost network for data sharing. If FastRTPS/DDS >= 2.0
|
// the localhost network for data sharing. If FastRTPS/DDS >= 2.0 and
|
||||||
// then the Shared Memory transport is used
|
// RMW_IMPLEMENTATION is FastDDS then the Shared Memory transport is used
|
||||||
const char* localhost_only = std::getenv("ROS_LOCALHOST_ONLY");
|
const char* localhost_only = std::getenv("ROS_LOCALHOST_ONLY");
|
||||||
if (localhost_only && strcmp(localhost_only, "1") == 0) {
|
if (localhost_only && strcmp(localhost_only, "1") == 0) {
|
||||||
// Create a custom network UDPv4 transport descriptor
|
// Create a custom network UDPv4 transport descriptor
|
||||||
@@ -122,11 +126,16 @@ bool @(topic)_Publisher::init(const std::string &ns)
|
|||||||
PParam.rtps.userTransports.push_back(localhostUdpTransport);
|
PParam.rtps.userTransports.push_back(localhostUdpTransport);
|
||||||
|
|
||||||
@[if version.parse(fastrtps_version) >= version.parse('2.0')]@
|
@[if version.parse(fastrtps_version) >= version.parse('2.0')]@
|
||||||
// Add shared memory transport when available
|
const char* rmw_implementation = std::getenv("RMW_IMPLEMENTATION");
|
||||||
auto shmTransport = std::make_shared<SharedMemTransportDescriptor>();
|
const char* ros_distro = std::getenv("RMW_IMPLEMENTATION");
|
||||||
PParam.rtps.userTransports.push_back(shmTransport);
|
if (((rmw_implementation && (strcmp(rmw_implementation, "rmw_fastrtps_cpp") == 0)) || (strcmp(rmw_implementation, "rmw_fastrtps_dynamic_cpp") == 0)) ||
|
||||||
|
(!rmw_implementation && strcmp(ros_distro, "foxy") == 0)) {
|
||||||
|
// Add shared memory transport when available
|
||||||
|
auto shmTransport = std::make_shared<SharedMemTransportDescriptor>();
|
||||||
|
PParam.rtps.userTransports.push_back(shmTransport);
|
||||||
|
}
|
||||||
@[end if]@
|
@[end if]@
|
||||||
}
|
}
|
||||||
|
|
||||||
mp_participant = Domain::createParticipant(PParam);
|
mp_participant = Domain::createParticipant(PParam);
|
||||||
|
|
||||||
@@ -153,6 +162,8 @@ bool @(topic)_Publisher::init(const std::string &ns)
|
|||||||
topicName.append("@(topic)_PubSubTopic");
|
topicName.append("@(topic)_PubSubTopic");
|
||||||
Wparam.topic.topicName = topicName;
|
Wparam.topic.topicName = topicName;
|
||||||
@[ end if]@
|
@[ end if]@
|
||||||
|
// ROS2 default publish mode QoS policy
|
||||||
|
Wparam.qos.m_publishMode.kind = ASYNCHRONOUS_PUBLISH_MODE;
|
||||||
@[else]@
|
@[else]@
|
||||||
std::string topicName = ns;
|
std::string topicName = ns;
|
||||||
topicName.append("@(topic)PubSubTopic");
|
topicName.append("@(topic)PubSubTopic");
|
||||||
|
|||||||
@@ -106,14 +106,18 @@ bool @(topic)_Subscriber::init(uint8_t topic_ID, std::condition_variable *t_send
|
|||||||
PParam.rtps.builtin.leaseDuration = c_TimeInfinite;
|
PParam.rtps.builtin.leaseDuration = c_TimeInfinite;
|
||||||
@[else]@
|
@[else]@
|
||||||
PParam.rtps.builtin.discovery_config.leaseDuration = c_TimeInfinite;
|
PParam.rtps.builtin.discovery_config.leaseDuration = c_TimeInfinite;
|
||||||
|
@[end if]@
|
||||||
|
@[if ros2_distro]@
|
||||||
|
// ROS2 default memory management policy
|
||||||
|
PParam.rtps.builtin.writerHistoryMemoryPolicy = PREALLOCATED_WITH_REALLOC_MEMORY_MODE;
|
||||||
@[end if]@
|
@[end if]@
|
||||||
std::string nodeName = ns;
|
std::string nodeName = ns;
|
||||||
nodeName.append("@(topic)_subscriber");
|
nodeName.append("@(topic)_subscriber");
|
||||||
PParam.rtps.setName(nodeName.c_str());
|
PParam.rtps.setName(nodeName.c_str());
|
||||||
|
|
||||||
// Check if ROS_LOCALHOST_ONLY is set. This means that one wants to use
|
// Check if ROS_LOCALHOST_ONLY is set. This means that one wants to use only
|
||||||
// only the localhost network for data sharing. If FastRTPS/DDS >= 2.0
|
// the localhost network for data sharing. If FastRTPS/DDS >= 2.0 and
|
||||||
// then the Shared Memory transport is used
|
// RMW_IMPLEMENTATION is FastDDS then the Shared Memory transport is used
|
||||||
const char* localhost_only = std::getenv("ROS_LOCALHOST_ONLY");
|
const char* localhost_only = std::getenv("ROS_LOCALHOST_ONLY");
|
||||||
if (localhost_only && strcmp(localhost_only, "1") == 0) {
|
if (localhost_only && strcmp(localhost_only, "1") == 0) {
|
||||||
// Create a custom network UDPv4 transport descriptor
|
// Create a custom network UDPv4 transport descriptor
|
||||||
@@ -128,9 +132,14 @@ bool @(topic)_Subscriber::init(uint8_t topic_ID, std::condition_variable *t_send
|
|||||||
PParam.rtps.userTransports.push_back(localhostUdpTransport);
|
PParam.rtps.userTransports.push_back(localhostUdpTransport);
|
||||||
|
|
||||||
@[if version.parse(fastrtps_version) >= version.parse('2.0')]@
|
@[if version.parse(fastrtps_version) >= version.parse('2.0')]@
|
||||||
// Add shared memory transport when available
|
const char* rmw_implementation = std::getenv("RMW_IMPLEMENTATION");
|
||||||
auto shmTransport = std::make_shared<SharedMemTransportDescriptor>();
|
const char* ros_distro = std::getenv("RMW_IMPLEMENTATION");
|
||||||
PParam.rtps.userTransports.push_back(shmTransport);
|
if (((rmw_implementation && (strcmp(rmw_implementation, "rmw_fastrtps_cpp") == 0)) || (strcmp(rmw_implementation, "rmw_fastrtps_dynamic_cpp") == 0)) ||
|
||||||
|
(!rmw_implementation && strcmp(ros_distro, "foxy") == 0)) {
|
||||||
|
// Add shared memory transport when available
|
||||||
|
auto shmTransport = std::make_shared<SharedMemTransportDescriptor>();
|
||||||
|
PParam.rtps.userTransports.push_back(shmTransport);
|
||||||
|
}
|
||||||
@[end if]@
|
@[end if]@
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user