Using ROS subscribers in Unreal Engine
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.
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 could subscribe from within Unreal would be greatly appreciated.
**Edit: image of debug added.
Minor, but: we don't really close questions if they are answered. Accepting the correct answer makes it much more obvious from the question listing that it has been answered.
We do close questions that are spam, outdated, etc.
Oops. Thank you for pointing that out, noted for future instances. Thanks again for your help.
No problem. Not a big thing, just something to keep in mind.