-
Notifications
You must be signed in to change notification settings - Fork 53
Open
Description
I am running ros when a linux machine which is a virtual machine on a windows 10 computer and the windows 10 is the second machine on the ROS network.
I have set all my env var (HOSTNAME, MASTER_URI, etc).
From Matlab on the windows machine I can publish and subscribe fine. However, using Unity (ROS_CSharp) while I can publish and I can subscribe (which I check via rostopic list -v), my (local) callbaack function is just not being called. Any idea why?
Thank you!
Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Ros_CSharp;
using System;
using System.Threading;
using System.Net.Sockets;
public class ROS_Test : MonoBehaviour {
Subscriber<Messages.std_msgs.Float64> v;
Publisher<Messages.std_msgs.Float64> LKA;
NodeHandle nh;
NodeHandle nh2;
private bool closing;
private Thread pubthread;
public Dictionary<string, float> state = new Dictionary<string, float>();
void addState(string key)
{
state.Add(key, 0.0f);
}
void updateState(string key, float value)
{
state[key] = value;
}
// Use this for initialization
void Start () {
addState ("v");
ROS.ROS_HOSTNAME = System.Environment.GetEnvironmentVariable ("ROS_HOSTNAME");
ROS.ROS_IP = System.Environment.GetEnvironmentVariable ("ROS_IP");
ROS.ROS_MASTER_URI = System.Environment.GetEnvironmentVariable ("ROS_MASTER_URI");
ROS.Init(new string[0], "UnityROS");
nh = new NodeHandle("test");
nh2 = new NodeHandle("test_2");
v = nh2.subscribe<Messages.std_msgs.Float64> ("/transform1", 1, UpdateTransform2);
LKA = nh.advertise<Messages.std_msgs.Float64>("/lka", 10, false);
}
void UpdateTransform2(Messages.std_msgs.Float64 msg)
{
Debug.Log ("hi");
float v = (float)msg.data;
updateState("v", v);
}
// Update is called once per frame
void Update () {
Debug.Log (state ["v"]);
int level = 2;
pubthread = new Thread(() =>
{
Messages.std_msgs.Float64 msg = new Messages.std_msgs.Float64();
msg.data = level;
LKA.publish(msg);
});
pubthread.Start();
}
void onDestroy()
{
//pubthread.Join();
ROS.shutdown();
ROS.waitForShutdown();
}
}
Metadata
Metadata
Assignees
Labels
No labels