Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I can Publish and Subscribe but the Callback function is not being called #46

Open
yrazin opened this issue Oct 26, 2017 · 35 comments
Open

Comments

@yrazin
Copy link

yrazin commented Oct 26, 2017

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();
}

}

@allspawj
Copy link
Member

It is almost certainly being blocked by your firewall. Try disabling the windows firewall and see if that fixes it.

@yrazin
Copy link
Author

yrazin commented Oct 26, 2017

firewall is already disabled

@nuclearmistake
Copy link
Collaborator

nuclearmistake commented Oct 26, 2017 via email

@yrazin
Copy link
Author

yrazin commented Oct 26, 2017

nuclearmistake - I'm sorry, I don't understand. which thread is unnecessary?

@STGRobotics
Copy link

Are both machine of the same ip/subnet range

@yrazin
Copy link
Author

yrazin commented Oct 26, 2017

yes - same range 192...101 and 192...102

@allspawj
Copy link
Member

In your update function you create a new thread to publish. I don't think that's your issue, but it's unnecessary. Publisher.publish is non blocking already.

Also you create two nodehandles, which is uncommon, but I don't think that would cause any issues.

You said if you rostopic info the topic you are subscribing too it shows your unity node right? And your sure your ros_hostname is correct?

@nuclearmistake
Copy link
Collaborator

nuclearmistake commented Oct 26, 2017 via email

@STGRobotics
Copy link

Are you able to ping from each machine and get a reply?

@yrazin
Copy link
Author

yrazin commented Oct 26, 2017

I created two nodehandles as a test to see if that was the problem.
I can certainly remove the thread but I agree - its not the issue.

yes - rostopic info is correct it shows the publisher and subscript and when I echo I see plenty of new data

@yrazin
Copy link
Author

yrazin commented Oct 26, 2017

yes, the machines ping. As I said, other programs (MATLAB) on the windows machine are working fine for publishing/subscribing

@yrazin
Copy link
Author

yrazin commented Oct 26, 2017

roscore

@yrazin
Copy link
Author

yrazin commented Oct 26, 2017

image

You can see I am publishing and subscribing from two different programs on the windows machine

@nuclearmistake
Copy link
Collaborator

nuclearmistake commented Oct 26, 2017 via email

@yrazin
Copy link
Author

yrazin commented Oct 26, 2017

@nuclearmistake -Not sure how. SIMULINK (in MATLAB) is doing the publishing and does not give a latching option.

@nuclearmistake
Copy link
Collaborator

nuclearmistake commented Oct 26, 2017 via email

@yrazin
Copy link
Author

yrazin commented Oct 26, 2017

Playing the bag doesn't change that unity isn't calling anything.
I did notice that when you stop unity, its subscriber doesn't go away.

I'll try non-unity next - I've actually never done that. Can I just get rid of the unity specific bits here and switch to a main() function - and then call it from the command line?

@yrazin
Copy link
Author

yrazin commented Oct 26, 2017

@nuclearmistake ok

here is my new results and code - it never publishes "hi" (which is in the callback)

image

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;
using System.Collections.Generic;
using Ros_CSharp;
using System;
using System.Threading;
using System.Net.Sockets;

namespace ros_test3
{
class Program
{

    public Dictionary<string, float> state = new Dictionary<string, float>();

    //void updateState(string key, float value)
    //{
    //    state[key] = value;
    //}


    static void Main()
    {

        Console.WriteLine("hello world!");
        //addState("v");

        ROS.Init(new string[0], "UnityROS");

        NodeHandle nh2 = new NodeHandle("test_2");

        Subscriber<Messages.std_msgs.Float64> v = nh2.subscribe<Messages.std_msgs.Float64>("/transform1", 1, UpdateTransform2);

       // Console.WriteLine(state["v"]);

    }

    //static void addState(string key)
    //{
    //    state.Add(key, 0.0f);

    //}
    static void UpdateTransform2(Messages.std_msgs.Float64 msg)
    {
        Console.WriteLine("hi");
        //float v = (float)msg.data;
        //updateState("v", v);
    }




}

}

@yrazin
Copy link
Author

yrazin commented Oct 26, 2017

@nuclearmistake if I do Console.Log(v.NumPublishers) it prints 0 but rostopic info shows 1 publisher

@nuclearmistake
Copy link
Collaborator

nuclearmistake commented Oct 26, 2017 via email

@nuclearmistake
Copy link
Collaborator

nuclearmistake commented Oct 26, 2017 via email

@yrazin
Copy link
Author

yrazin commented Oct 26, 2017

rostopic pub doesn't seem to help. I can see it in echo fine but unity always shows 0. remember it didn't work from a rosbag either - I don't think the problem is simulink, I think its unity. How do I check the advertised host names or dns failure? Where are these debugging check boxes? I'm happy to do what ever. (This all was working a few weeks ago but the computer got messed up btw. I know this can work I just don't know how to get it back)

@nuclearmistake
Copy link
Collaborator

nuclearmistake commented Oct 26, 2017 via email

@yrazin
Copy link
Author

yrazin commented Oct 26, 2017

Windows
There is also ROS_HOSTNAME = 192.168.56.102
and ROS_MASTER_URI = http://192.168.56.101:11311

Linux
ROS_MASTER_URI=http://localhost:11311
ROS_IP=192.168.56.101
ROS_HOSTNAME=192.168.56.101

I used the original and a paired down reproduced version.

I think you're right - its the dns config. Linux can find windows but nbtstat not working from windows to linux (though it can ping). Not sure how to fix or even diagnose, any help appreciated

@nuclearmistake
Copy link
Collaborator

Are you doing anything with multiple network interfaces on either the windows or Linux pc?

@yrazin
Copy link
Author

yrazin commented Oct 26, 2017

Both computers are internet connected in addition to the virtual adapter between them. I am able to ping by name from both computers. I was able to subscribe from the matlab command line successfully and do a callback. So rosinit is working in matlab fine as is node creation, subscription, and callback.

rosinit (matlab) gives me the follwoing output:

The value of the ROS_MASTER_URI environment variable, http://192.168.56.101:11311, will be used to connect to the ROS master.
The value of the ROS_HOSTNAME environment variable, 192.168.56.102, will be used to set the advertised address for the ROS node.
Initializing global node /matlab_global_node_10191 with NodeURI http://192.168.56.102:56613/

I'm not sure why ROS.NET is not able to do the same. What were those check boxes you mentioned? Can I get similar feedback or more?

@yrazin
Copy link
Author

yrazin commented Oct 26, 2017

Also ROS_CSharp does not have a ROS.spin() function

@yrazin
Copy link
Author

yrazin commented Oct 26, 2017

Does this help (this is from the non-unity csharp

image

image

@nuclearmistake
Copy link
Collaborator

Lol oh yeah... Was thinking of ROS.waitForShutdown() for the bottom of your main function -- ros.net used to require spinning like roscpp nodes, but has since been improved to automatically spin more like rospy

The debugger check boxes are in the build section of project the properties

@nuclearmistake
Copy link
Collaborator

Debug check boxes... Enable debug and enable tracing in ros_csharp project of your non-unity solution

@nuclearmistake
Copy link
Collaborator

Is the VM network in NAT, host-only or bridged mode? VM networking can sometimes be the sort of quirky that might present itself as what you're experiencing

@nuclearmistake
Copy link
Collaborator

Can a separate Matlab simulink node subscribe to the one that's publishing?

@yrazin
Copy link
Author

yrazin commented Oct 29, 2017

Sorry - I was away Friday.

  1. My VM is host only - its the only way it seems to work for me.
  2. A separate Matlab simulink node can subscribe without issue

I can try rebuilding when I'm back in the office Monday

@yrazin
Copy link
Author

yrazin commented Oct 30, 2017

ok @nuclearmistake

I have debug working on a non-unity one now (code already above). I get the following messages (I turned the publisher off and back on in the middle). The callback is still never seemingly called.

hello world!
Adding pollthreadlistener :Void checkForShutdown()
Adding pollthreadlistener Ros_CSharp.ConnectionManager:Void removeDroppedConnections()
Publisher update for [/clock]
Publisher update for [/transform1]
Began asynchronous xmlrpc connection to http://192.168.56.102:18452/ for topic [/transform1]
Adding pollthreadlistener Ros_CSharp.Publication:Void processPublishQueue()
Finalize transport subscriber link for /rosout
here is when I turned off the publisher
TopicManager is updating publishers for /transform1
Publisher update for [/transform1]
here is when I turned it back on
TopicManager is updating publishers for /transform1
Publisher update for [/transform1]
Began asynchronous xmlrpc connection to http://192.168.56.102:18656/ for topic [/transform1]
and when I turned it off again
TopicManager is updating publishers for /transform1
Publisher update for [/transform1]

Here is the debug output from visual studio

'ros_test3.vshost.exe' (CLR v4.0.30319: ros_test3.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'ros_test3.vshost.exe' (CLR v4.0.30319: ros_test3.vshost.exe): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities\14.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'ros_test3.vshost.exe' (CLR v4.0.30319: ros_test3.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Windows.Forms\v4.0_4.0.0.0__b77a5c561934e089\System.Windows.Forms.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'ros_test3.vshost.exe' (CLR v4.0.30319: ros_test3.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'ros_test3.vshost.exe' (CLR v4.0.30319: ros_test3.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Drawing\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'ros_test3.vshost.exe' (CLR v4.0.30319: ros_test3.vshost.exe): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities.Sync\14.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.Sync.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'ros_test3.vshost.exe' (CLR v4.0.30319: ros_test3.vshost.exe): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\Microsoft.VisualStudio.Debugger.Runtime\14.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.Debugger.Runtime.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'ros_test3.vshost.exe' (CLR v4.0.30319: ros_test3.vshost.exe): Loaded 'C:\Users\yrazin3\Documents\Visual Studio 2015\Projects\ros_test3\ros_test3\bin\Debug\ros_test3.vshost.exe'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'ros_test3.vshost.exe' (CLR v4.0.30319: ros_test3.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'ros_test3.vshost.exe' (CLR v4.0.30319: ros_test3.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Xml.Linq\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.Linq.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'ros_test3.vshost.exe' (CLR v4.0.30319: ros_test3.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Data.DataSetExtensions\v4.0_4.0.0.0__b77a5c561934e089\System.Data.DataSetExtensions.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'ros_test3.vshost.exe' (CLR v4.0.30319: ros_test3.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\Microsoft.CSharp\v4.0_4.0.0.0__b03f5f7f11d50a3a\Microsoft.CSharp.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'ros_test3.vshost.exe' (CLR v4.0.30319: ros_test3.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_32\System.Data\v4.0_4.0.0.0__b77a5c561934e089\System.Data.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'ros_test3.vshost.exe' (CLR v4.0.30319: ros_test3.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Net.Http\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Net.Http.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'ros_test3.vshost.exe' (CLR v4.0.30319: ros_test3.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Xml\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
The thread 0x714c has exited with code 0 (0x0).
The thread 0x5f08 has exited with code 0 (0x0).
'ros_test3.vshost.exe' (CLR v4.0.30319: ros_test3.vshost.exe): Loaded 'C:\Users\yrazin3\Documents\Visual Studio 2015\Projects\ros_test3\ros_test3\bin\Debug\ros_test3.exe'. Symbols loaded.
'ros_test3.vshost.exe' (CLR v4.0.30319: ros_test3.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'ros_test3.vshost.exe' (CLR v4.0.30319: ros_test3.vshost.exe): Loaded 'C:\Users\yrazin3\Documents\Visual Studio 2015\Projects\ros_test3\ros_test3\bin\Debug\Ros_CSharp.dll'. Symbols loaded.
'ros_test3.vshost.exe' (CLR v4.0.30319: ros_test3.vshost.exe): Loaded 'C:\Users\yrazin3\Documents\Visual Studio 2015\Projects\ros_test3\ros_test3\bin\Debug\Messages.dll'. Symbols loaded.
'ros_test3.vshost.exe' (CLR v4.0.30319: ros_test3.vshost.exe): Loaded 'C:\Users\yrazin3\Documents\Visual Studio 2015\Projects\ros_test3\ros_test3\bin\Debug\XmlRpc_Wrapper.dll'. Symbols loaded.
The thread 0xcac has exited with code 0 (0x0).
The thread 0x59a0 has exited with code 0 (0x0).
The thread 0x4414 has exited with code 0 (0x0).

@Mor-harry
Copy link

Hello, I can receive the topic data sent by ROS from Windows. But when talker works, ROS can't receive the normal topic data, but it can see topic exists. @nuclearmistake

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants