Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cherry-pick to devel from UE5_devel_humble] Service id check #163

Open
wants to merge 1 commit into
base: devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Source/rclUE/Private/ROS2ServiceServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ void UROS2ServiceServer::ProcessReady()
void* data = Service->GetRequest();
RCSOFTCHECK(rcl_take_request_with_info(&rcl_service, &req_info, data));

if (bRejectConsecutiveIdenticalRequest && UROS2Utils::IsEqualWMSrvInfo(req_info, LastReqInfo, true))
{
UE_LOG_WITH_INFO(LogROS2Srv, Warning, TEXT("Rejecting consecutive identical request"));
return;
}
LastReqInfo = req_info;

UE_LOG_WITH_INFO_NAMED(LogROS2Node, Log, TEXT("ROS2Node Executing Service server callback"));

SrvCallback.ExecuteIfBound(Service);
Expand Down
6 changes: 6 additions & 0 deletions Source/rclUE/Public/ROS2ServiceServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ class RCLUE_API UROS2ServiceServer : public UROS2Service
*
*/
virtual void InitializeServiceComponent() override;

rmw_service_info_t LastReqInfo;

//! Rejct consecutive identical requests
UPROPERTY(EditAnywhere, BlueprintReadWrite)
bool bRejectConsecutiveIdenticalRequest = true;
};

/**
Expand Down
33 changes: 33 additions & 0 deletions Source/rclUE/Public/rclcUtilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,39 @@ class UROS2Utils : public UBlueprintFunctionLibrary
GENERATED_BODY()

public:
static bool IsEqualRWMRequestId(rmw_request_id_t service1, rmw_request_id_t service2)
{
if (service1.sequence_number != service2.sequence_number)
{
return false;
}
for (int i = 0; i < 16; i++)
{
if (service1.writer_guid[i] != service2.writer_guid[i])
{
return false;
}
}
return true;
}

static bool IsEqualWMSrvInfo(rmw_service_info_t service1, rmw_service_info_t service2, bool check_received_timestamp = true)
{
if (!UROS2Utils::IsEqualRWMRequestId(service1.request_id, service2.request_id))
{
return false;
}
if (service1.source_timestamp != service2.source_timestamp)
{
return false;
}
if (check_received_timestamp && service1.received_timestamp != service2.received_timestamp)
{
return false;
}
return true;
}

static builtin_interfaces__msg__Time FloatToROSStamp(const float InTimeSec)
{
builtin_interfaces__msg__Time stamp;
Expand Down