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

Remove Rviz marker upon destroyed actor #212

Open
wants to merge 3 commits 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
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,20 @@ URRROS2ActorsRvizMarkerPublisher::URRROS2ActorsRvizMarkerPublisher()
SetDefaultDelegates(); //use UpdateMessage as update delegate
}

void URRROS2ActorsRvizMarkerPublisher::AddTargetActor(AActor* InActor)
{
if (false == Actors.Contains(InActor))
{
InActor->OnDestroyed.AddDynamic(this, &URRROS2ActorsRvizMarkerPublisher::OnTargetActorDestroyed);
Actors.Add(InActor);
}
}

void URRROS2ActorsRvizMarkerPublisher::OnTargetActorDestroyed(AActor* InActor)
{
Actors.RemoveSwap(InActor);
}

void URRROS2ActorsRvizMarkerPublisher::UpdateMessage(UROS2GenericMsg* InMessage)
{
if (bUpdateActorsList)
Expand All @@ -26,6 +40,10 @@ void URRROS2ActorsRvizMarkerPublisher::UpdateMessage(UROS2GenericMsg* InMessage)
BaseMarker.Header.Stamp = URRConversionUtils::FloatToROSStamp(UGameplayStatics::GetTimeSeconds(GetWorld()));
for (AActor* actor : Actors)
{
if (!IsValid(actor))
{
continue;
}
FROSMarker marker = BaseMarker;
FTransform tf =
URRConversionUtils::TransformUEToROS(URRGeneralUtils::GetRelativeTransform(ReferenceActor, actor->GetTransform()));
Expand All @@ -35,5 +53,8 @@ void URRROS2ActorsRvizMarkerPublisher::UpdateMessage(UROS2GenericMsg* InMessage)
msg.Markers.Add(marker);
}

CastChecked<UROS2MarkerArrayMsg>(InMessage)->SetMsg(msg);
if (msg.Markers.Num() > 0)
{
CastChecked<UROS2MarkerArrayMsg>(InMessage)->SetMsg(msg);
}
}
20 changes: 10 additions & 10 deletions Source/RapyutaSimulationPlugins/Public/Core/RRROS2GameMode.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,16 @@ class RAPYUTASIMULATIONPLUGINS_API ARRROS2GameMode : public AGameMode
return NativeSpawnableClassPaths.FindRef(InEntityModelName);
}

//! Blueprint class names (also used as their entity model names) to be registered as spawnable entity types
//! Eg: {"BP_TurtlebotBurger", "BP_TurtlebotBurgerVehicle"}
UPROPERTY(config)
TArray<FString> BPSpawnableClassNames;

//! Asset paths of classes to be registered as spawnable entity types
//! Eg: {{"TurtlebotBurger", "/Script/RapyutaSimulationPlugins.TurtlebotBurger"]}
UPROPERTY(config)
TMap<FString /*Entity model name*/, FString /*Class path*/> NativeSpawnableClassPaths;

protected:
/**
* @brief Initialize Game.
Expand All @@ -131,16 +141,6 @@ class RAPYUTASIMULATIONPLUGINS_API ARRROS2GameMode : public AGameMode
*/
virtual void StartPlay() override;

//! Blueprint class names (also used as their entity model names) to be registered as spawnable entity types
//! Eg: {"BP_TurtlebotBurger", "BP_TurtlebotBurgerVehicle"}
UPROPERTY(config)
TArray<FString> BPSpawnableClassNames;

//! Asset paths of classes to be registered as spawnable entity types
//! Eg: {{"TurtlebotBurger", "/Script/RapyutaSimulationPlugins.TurtlebotBurger"]}
UPROPERTY(config)
TMap<FString /*Entity model name*/, FString /*Class path*/> NativeSpawnableClassPaths;

private:
/**
* @brief Create and initialize #MainROS2Node, #ClockPublisher and #MainSimState.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,16 @@ class RAPYUTASIMULATIONPLUGINS_API URRROS2ActorsRvizMarkerPublisher : public URO
UPROPERTY(EditAnywhere, BlueprintReadWrite)
FROSMarker BaseMarker;

/**
* @brief Add a target actor to #Actors
*/
void AddTargetActor(AActor* InActor);

/**
* @brief Callback upon a target actor in #Actors gets destroyed
*/
UFUNCTION()
void OnTargetActorDestroyed(AActor* InActor);

void UpdateMessage(UROS2GenericMsg* InMessage) override;
};