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.