Using ROS in Unreal (callbacks & Subscriptions)

Hi, Has anyone had any experience with using ROS subscribers inside the Unreal Engine? My Unreal game will crash as soon as ros::NodeHandle.spinOnce() is called. spinOnce() is a function which should call any callbacks.

My Header: TestingSubs.h

#pragma once
#include <ros.h>
#include <time.h>
#include <baxter_core_msgs/EndpointState.h>
#include "Components/ActorComponent.h"
#include "TestingSubs.generated.h"

UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class WALLCLIMBING_API UTestingSubs : public UActorComponent
{
    GENERATED_BODY()

public: 
    // Sets default values for this component's properties
    UTestingSubs();

    // Called when the game starts
    virtual void BeginPlay() override;

    // Called every frame
    virtual void TickComponent( float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction ) override;

    void StartUp();

    void MyCallback(const baxter_core_msgs::EndpointState& msg);
    char *ros_master = "192.168.1.120";
    ros::NodeHandle MyNode;
};

My cpp: TestingSubs.cpp

#include "WallClimbing.h"
#include "TestingSubs.h"

// Sets default values for this component's properties
UTestingSubs::UTestingSubs()
{
    // Set this component to be initialized when the game starts, and to be ticked every frame.  You can turn these features
    // off to improve performance if you don't need them.
    bWantsBeginPlay = true;
    PrimaryComponentTick.bCanEverTick = true;
}


// Called when the game starts
void UTestingSubs::BeginPlay()
{
    Super::BeginPlay();
    StartUp();
}


// Called every frame
void UTestingSubs::TickComponent( float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction )
{
    Super::TickComponent( DeltaTime, TickType, ThisTickFunction );
    MyNode.spinOnce();
}

void UTestingSubs::MyCallback(const baxter_core_msgs::EndpointState& msg)
{
    UE_LOG(LogTemp, Warning, TEXT("Callback was called"));
}

void Callback(const baxter_core_msgs::EndpointState& msg)
{
    UE_LOG(LogTemp, Warning, TEXT("Callback was called"));
}

void UTestingSubs::StartUp()
{
    MyNode.initNode(ros_master);
    ros::Subscriber< baxter_core_msgs::EndpointState > Mysub("/robot/limb/right/endpoint_state/", &Callback);
    MyNode.subscribe(Mysub);
}

Any suggestions of how I can use a ROS subscriber from within Unreal would be greatly appreciated.
P.S. I am pretty new to C++, Unreal & ROS.

Hi, I am wondering how did you get ros.h compiled in Unreal as I got a lot of errors when tried to compile it in VS2015. Thx!

Hi, I am working on a similar project, but I am unable to compile the unreal source with ROS headers. Can you tell me how did you implement ROS with UE?

Hi, basically I followed Ros windows tutorial:rosserial_windows/Tutorials/Hello World - ROS Wiki
Then you need to undef “ERROR” in log.h as it has define conflict with wingdi.h. Also you need to use #include “AllowWindowsPlatformTypes.h” #include “HideWindowsPlatformTypes.h” for windows headers.

Hi, actually I am using Unreal on linux, so is there any direct method to integrate UE4 with ROS?

It’s probably too late ot ask now, but are oyu sure ROS callbacks on same thread? the UObject code can be only executed via Unreal threads (most notibly game thread) otherwise you might expirance crash issues and such.

First of all you need to check cause of crash, look up Saved/Logs in you project directory, if it’s issue detected by UE4 it should be written there, if it hard crash by OS (common sign of that is unfinished log) then you would need to some debugging in VS, run od debug and see when it stops.