Ask Your Question
0

Using ROS subscribers in Unreal Engine

asked 2017-01-25 09:51:27 -0500

dbliam gravatar image

updated 2017-01-26 06:03:33 -0500

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.image description

edit retag flag offensive close merge delete

Comments

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.

gvdhoorn gravatar image gvdhoorn  ( 2017-01-26 06:29:22 -0500 )edit

Oops. Thank you for pointing that out, noted for future instances. Thanks again for your help.

dbliam gravatar image dbliam  ( 2017-01-26 09:18:13 -0500 )edit

No problem. Not a big thing, just something to keep in mind.

gvdhoorn gravatar image gvdhoorn  ( 2017-01-26 13:36:20 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2017-01-26 06:12:38 -0500

dbliam gravatar image

The reason this code was crashing was that

ros::Subscriber< baxter_core_msgs::EndpointState > Mysub("/robot/limb/right/endpoint_state/", &Callback);

was being declared within one of the public functions, this was leading to it falling out of scope when the callback tried to use it, I believe. The fix for me was to make this ros::subscriber a global variable.

edit flag offensive delete link more

Comments

1

Hi @dblian,

where did you touch in order to be able to use ROS on your Unreal Project?

I've tried CMakeLists.txt of the Unreal Project but was not enough.

I'm using Ubuntu, BTW, but the process you have followed should work on both OS.

Ruben Alves gravatar image Ruben Alves  ( 2017-03-01 10:23:54 -0500 )edit
0

answered 2017-01-25 20:24:30 -0500

tfoote gravatar image

I'm having trouble figuring out what API you're using. The ros::Nodehandle API does not have a method initNode as in your example.

If it's crashing a backtrace would be critical to help debug more.

edit flag offensive delete link more

Comments

Thanks for your reply. I believe its a roscpp method. It exists here in the rosserial_windows tutorial (node_handle.h) I have been following. This is also a link to the debug report.

dbliam gravatar image dbliam  ( 2017-01-26 04:24:33 -0500 )edit
2

rosserial != roscpp, it is in fact a (minimal) reimplementation with somewhat similar semantics, but definitely not something you can use as a drop-in replacement (and the same goes for the docs).

Also: please add the image to your initial post, use the edit button.

gvdhoorn gravatar image gvdhoorn  ( 2017-01-26 05:32:54 -0500 )edit

Thank you for clearing that up for me. After you pointed out that this was rosserial I found appropriate literature, turns out that my ros::subsciber needed to be a global variable. This was pointed out on this wiki page.

dbliam gravatar image dbliam  ( 2017-01-26 06:08:54 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2017-01-25 09:51:27 -0500

Seen: 2,883 times

Last updated: Mar 01 '17