-
Notifications
You must be signed in to change notification settings - Fork 52
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
Comments
It is almost certainly being blocked by your firewall. Try disabling the windows firewall and see if that fixes it. |
firewall is already disabled |
Simplify your frame callback. The thread is unnecessary and at best will
slow things down. ROS.net's publish execution path already manages an
outbound queue worked on by a threadpool. It should not block your callback
when you publish.
…On Oct 26, 2017 1:35 PM, "yrazin" ***@***.***> wrote:
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();
}
}
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#46>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABLrWy7fMYB5RXGvr4aRd-YLHL5W8hC0ks5swMLDgaJpZM4QH8W0>
.
|
nuclearmistake - I'm sorry, I don't understand. which thread is unnecessary? |
Are both machine of the same ip/subnet range |
yes - same range 192...101 and 192...102 |
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? |
Also, don't explicitly set ROS_IP in the environment (not necessary for
most cases or tested)
And comment the assignments to ROS.ROS* -- ROS.Init will set those
automagically from the environment.
Try to restart roscore, and post a screenshot of the rqt node+topic graph
from the machine running your roscore.
If the program running ros.net is stopped in the debugger, its node name
will not unregister itself from the master, which can cause weirdness on
the next start. Using a node name that is always unique (add seconds since
1970 to the name, for example) is a workaround that won't clean up
leftovers BUT will work more reliably. The best solution is to kill the
program in a way that always shuts down all of the ROS.net things.
Speaking of which.... Are there any rogue copies of your program running in
taskmgr?
…On Oct 26, 2017 1:38 PM, "Eric McCann" ***@***.***> wrote:
Simplify your frame callback. The thread is unnecessary and at best will
slow things down. ROS.net's publish execution path already manages an
outbound queue worked on by a threadpool. It should not block your callback
when you publish.
On Oct 26, 2017 1:35 PM, "yrazin" ***@***.***> wrote:
> 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();
> }
>
> }
>
> —
> You are receiving this because you are subscribed to this thread.
> Reply to this email directly, view it on GitHub
> <#46>, or mute the thread
> <https://github.com/notifications/unsubscribe-auth/ABLrWy7fMYB5RXGvr4aRd-YLHL5W8hC0ks5swMLDgaJpZM4QH8W0>
> .
>
|
Are you able to ping from each machine and get a reply? |
I created two nodehandles as a test to see if that was the problem. yes - rostopic info is correct it shows the publisher and subscript and when I echo I see plenty of new data |
yes, the machines ping. As I said, other programs (MATLAB) on the windows machine are working fine for publishing/subscribing |
Try enabling latching?
Intraprocess pub+sub shouldn't be touching tcp -- but it's not the most
heavily tested usecase.
On Oct 26, 2017 1:49 PM, "yrazin" <[email protected]> wrote:
yes, the machines ping. As I said, other programs (MATLAB) on the windows
machine are working fine for publishing/subscribing
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#46 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABLrW2PW5IS7UGCsMXaKLEdnx2PvbWhyks5swMZHgaJpZM4QH8W0>
.
|
@nuclearmistake -Not sure how. SIMULINK (in MATLAB) is doing the publishing and does not give a latching option. |
What happens if you bag the messages on the Linux machine and then play
them back? Does your Ros.net code receive those
What about a non-unity ros.net node? (To remove unity-related unknown
variables)
…On Oct 26, 2017 1:59 PM, "yrazin" ***@***.***> wrote:
@nuclearmistake <https://github.com/nuclearmistake> -Not sure how.
SIMULINK (in MATLAB) is doing the publishing and does not give a latching
option.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#46 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABLrWzbN86Xj2z7ctki4MaDnENr_7uRqks5swMhMgaJpZM4QH8W0>
.
|
Playing the bag doesn't change that unity isn't calling anything. 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? |
here is my new results and code - it never publishes "hi" (which is in the callback) using System; namespace ros_test3
} |
@nuclearmistake if I do Console.Log(v.NumPublishers) it prints 0 but rostopic info shows 1 publisher |
Unlike programs with their own callback loops, you beed to ROS.spin() in
that simple Main to keep it going.
…On Oct 26, 2017 2:59 PM, "yrazin" ***@***.***> wrote:
@nuclearmistake <https://github.com/nuclearmistake> if I do
Console.Log(v.NumPublishers) it prints 0 but rostopic info shows 1 publisher
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#46 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABLrW-4411-qCj4tx0W8liXWWuX-jnWLks5swNaWgaJpZM4QH8W0>
.
|
What does the simulink node advertise its hostname as? Could it be a dns
failure when your subscriber is trying to get the IP of the simulink node
after master refers it to the publisher's IPEP?
Can you rostopic pub float64s from Linux to your unity node?
Maybe simulink is trying to be smart, and trying to avoid TCP for
intraprocess comms -- is it possible you need to republish your messages
(circuitously) to a Linux node and then back to ros.net?
Otherwise, I'd need to see the console output with as many debugging check
boxes checked as you can find in any of the ros.net projects.
…On Oct 26, 2017 3:30 PM, "Eric McCann" ***@***.***> wrote:
Unlike programs with their own callback loops, you beed to ROS.spin() in
that simple Main to keep it going.
On Oct 26, 2017 2:59 PM, "yrazin" ***@***.***> wrote:
> @nuclearmistake <https://github.com/nuclearmistake> if I do
> Console.Log(v.NumPublishers) it prints 0 but rostopic info shows 1 publisher
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <#46 (comment)>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/ABLrW-4411-qCj4tx0W8liXWWuX-jnWLks5swNaWgaJpZM4QH8W0>
> .
>
|
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) |
What are your ROS-specific environment variables set to? Are you trying to
use the old unity project? Or did you reproduce what you had?
…On Oct 26, 2017 4:43 PM, "yrazin" ***@***.***> wrote:
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)
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#46 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABLrW-9JHnA_pcXqp-CO9tTD0ZKYf6-Vks5swO7lgaJpZM4QH8W0>
.
|
Windows Linux 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 |
Are you doing anything with multiple network interfaces on either the windows or Linux pc? |
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. 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? |
Also ROS_CSharp does not have a ROS.spin() function |
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 |
Debug check boxes... Enable debug and enable tracing in ros_csharp project of your non-unity solution |
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 |
Can a separate Matlab simulink node subscribe to the one that's publishing? |
Sorry - I was away Friday.
I can try rebuilding when I'm back in the office Monday |
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! 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. |
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 |
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 {
}
The text was updated successfully, but these errors were encountered: