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

Can't publish string to ROS2 outside of Unreal #147

Open
samiamlabs opened this issue Jun 20, 2024 · 2 comments
Open

Can't publish string to ROS2 outside of Unreal #147

samiamlabs opened this issue Jun 20, 2024 · 2 comments

Comments

@samiamlabs
Copy link

Hi!

I'm having some trouble getting the topic I'm publishing on from inside Unreal to reach outside Unreal to a terminal on my main system.

Some info:
Ubuntu 22.04
Unreal 5.1 built from source
ROS2 humble

If I make a subscriber in Unreal it seems to receive what is published from the publisher in Unreal though.

The terminal just looks like this:

ros2 topic list
/parameter_events
/rosout

Any ideas as to what the problem could be?

Here is the code for the publisher (but I don't think the code is actually the issue):

TestPublisher.h

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"

#include "Msgs/ROS2Str.h"
#include <ROS2Publisher.h>

#include "TestPublisher.generated.h"



UCLASS()
class FIRSTUNREALPROJECT_API ATestPublisher : public AActor
{
	GENERATED_BODY()
	
public:	
	// Sets default values for this actor's properties
	ATestPublisher();

protected:
	// Called when the game starts or when spawned
	virtual void BeginPlay() override;

public:	
	// Called every frame
	virtual void Tick(float DeltaTime) override;

	UPROPERTY(EditAnywhere, BlueprintReadWrite)
        UROS2NodeComponent* Node = nullptr;

        UPROPERTY(EditAnywhere, BlueprintReadWrite)
        UROS2Publisher* Publisher = nullptr;
	
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
        FString TopicName = TEXT("test_topic");

	UPROPERTY(EditAnywhere, BlueprintReadWrite)
        FString Message = TEXT("Hello from C++");

private:

	void PublishMessage();

	FTimerHandle TimerHandle;
};

TestPublisher.cpp

#include "TestPublisher.h"


// Sets default values
ATestPublisher::ATestPublisher()
{
 	// Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
	PrimaryActorTick.bCanEverTick = true;

	Node = CreateDefaultSubobject<UROS2NodeComponent>(TEXT("ROS2NodeComponent"));

	Node->Name = TEXT("subscriber_node");
}

// Called when the game starts or when spawned
void ATestPublisher::BeginPlay()
{
	Super::BeginPlay();
	Node->Init();

	Publisher = Node->CreatePublisher(TopicName, UROS2Publisher::StaticClass(), UROS2StrMsg::StaticClass(), UROS2QoS::KeepLast);
	
	FROSStr msg;
        msg.Data = FString::Printf(TEXT("%s from non loop publisher"), *Message);
        CastChecked<UROS2StrMsg>(Publisher->TopicMessage)->SetMsg(msg);

	GetWorld()->GetTimerManager().SetTimer(TimerHandle, this, &ATestPublisher::PublishMessage, 1.0, true);
}

// Called every frame
void ATestPublisher::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

}

void ATestPublisher::PublishMessage()
{
	UE_LOG(LogTemp, Warning, TEXT("Publishing message"));
	Publisher->Publish();
}
@pabsan-0
Copy link

Hi, have you tried running a source run_discovery_service.sh in the receiving terminal?

@pabsan-0
Copy link

pabsan-0 commented Jul 5, 2024

Hi, I just started using Ubuntu 22.04 with the turtlebot3 repo and I had the same problem. Ignoring the dds-wrapping scripts and just running the world with $UE5_DIR/Engine/Binaries/Linux/UnrealEditor turtlebot.uproject, then just sourcing ROS in the receiving terminal, made me able to see and echo all topics published by the simulation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants