Dropping Messages

asked 2021-06-25 15:20:57 -0600

gimic9912 gravatar image

I’m trying to use ros’s bridge TCP server (melodic) to connect (and publish/subscribe) my ros topics from my Ubuntu VM to Unreal4 (which is not on the VM). I’m using RosIntegration to do this. I’ve been able to successfully send messages from Unreal to Ros. However, the message will not be received in certain cases. For instance, if I’m sending a string (std_msgs/String) from Unreal the length of the string will depend if it reaches the subscriber on my VM. I’m thinking it may have something to do with the ros bridge (http://wiki.ros.org/rosbridge_suite).

Here’s what I got:

Unreal side (RosIntegration)

TopicPubActor.cpp (added to scene) - entire file not show

void ATopicPubActor::BeginPlay()
{
    Super::BeginPlay();

    // Initialize a topic
    ExampleTopic = NewObject<UTopic>(UTopic::StaticClass());
    UROSIntegrationGameInstance* rosinst = Cast<UROSIntegrationGameInstance>(GetGameInstance());
    ExampleTopic->Init(rosinst->ROSIntegrationCore, TEXT("/example_topic"), TEXT("std_msgs/String"), 1000);

    // Advertise the topic
    ExampleTopic->Advertise();
}

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

    FString textString = "This is a test message to see if ROS likes long strings!";

    // Publish a string to the topic
    TSharedPtr<ROSMessages::std_msgs::String> pubMessage(new ROSMessages::std_msgs::String(textString));

    ExampleTopic->Publish(pubMessage);
}

TopicPubActor.h

#pragma once

#include "ROSIntegration/Classes/RI/Topic.h"
#include "ROSIntegration/Classes/ROSIntegrationGameInstance.h"
#include "ROSIntegration/Public/std_msgs/String.h"

#include "ROSIntegration/Public/std_msgs/Float32.h"
#include "ROSIntegration/Public/geometry_msgs/Twist.h"

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

UCLASS()
class ROSTEST2_API ATopicPubActor : public AActor
{
    GENERATED_BODY()

public: 
    // Sets default values for this actor's properties
    ATopicPubActor();

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

    UPROPERTY()
        UTopic* ExampleTopic;

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

MyROSIntegrationGameInstance_BP (active game instance) This was given by ROSIntegration here

image description

Unreal builds successfully and should be ready to connect to rosbridge.

FYI, this project is an advanced vehicle starter project.

Ubuntu VM side (using RosBridge)

Command to start up the TCP ros bridge server (on port 9090)

image description

Starts up fine

image description

Startup subscriber “listener.cpp”. Is using the same topic as Unreal publisher (“/example_topic”)

image description

listener.cpp

#include "ros/ros.h"
#include "std_msgs/String.h"
#include "std_msgs/Float32.h"
#include <iostream>

using namespace std;

void chatterCallback(const std_msgs::String::ConstPtr& msg)
{
  ROS_INFO("I heard: [%s]", msg->data.c_str());
}

int main(int argc, char **argv)
{
  ros::init(argc, argv, "listener");

  ros::NodeHandle n;

  ros::Subscriber sub = n.subscribe("/example_topic", 1000, chatterCallback);

  ros::spin();

  return 0;
}

Test #1

image description

  • Unreal RosIntegration connects via TCP to the ros bridge server as Client 0.
  • Listener is not receiving any data, even though an unreal actor is publishing to the same topic.

Now if we test this again, but only change the length of the publishing string it will have a different output.

What we had in test #1 (TopicPubActor.cpp)

FString textString = "This is a test message to see if ROS likes long strings!";

What we will change for test #2 (TopicPubActor.cpp)

FString textString = "A test message!";

I’ll restart the ros tcp bridge server and listener. I ... (more)

edit retag flag offensive close merge delete