ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

rospy.ServiceProxy master port mismatch

asked 2018-07-27 09:44:18 -0500

thinwybk gravatar image

updated 2018-07-27 10:02:49 -0500

On my dev machine I run ros master on default port 11311 via ROSLaunchParent as follows:

os.environ["ROS_IP"] = "<dev-machine-ip>"
os.environ["ROS_MASTER_URI"] = "http://<dev-machine-ip>:11311"
roslaunch = ROSLaunchParent('', [], is_core=True, port=11311)
roslaunch.start()

stdout states that the roslaunch server is running on port 43121 (changes randomly between starts of roslaunch):

started roslaunch server http://<dev-machine-ip>:43121/

The master seems to be started on port 11311:

auto-starting new master
process[master]: started with pid [15304]
ROS_MASTER_URI=http://<dev-machine-ip>:11311/

I use docker-py (dc is a client, di is an images instance, dn is a network) to run a ROS node <some-node> in a docker container which connects to the dev machines master.

dn = dc.networks.create(name='some_test', driver="bridge")
some_node = dc.containers.run(image=di[0].id, environment=["ROS_IP=<some-ip-in-the-dev-machine-subnet>", "ROS_MASTER_URI=http://<dev-machine-ip>:11311"], name='<some-node>', network='test', command=rosrun_command, detach=True, tty=True)

import rosnode; nodes = rosnode.get_node_names(); print(nodes) lists /<some-node> (and /rosout). some-node is (at least) discoverable in the network. So far so good.

If I send multiple service requests with

rc_itempick_start = rospy.ServiceProxy('/<some-node-namespace>/<some-service>', <service-type>)
rc_itempick_start()

a random port is used instead of 11311:

core.py    WARNING  Unknown error initiating TCP/IP socket to <some-ip-in-the-dev-machine-subnet>:35516 (rosrpc://<some-ip-in-the-dev-machine-subnet>:35516)
(...)
error: [Errno 113] No route to host
core.py    WARNING  Unknown error initiating TCP/IP socket to <some-ip-in-the-dev-machine-subnet>:60739 (rosrpc://<some-ip-in-the-dev-machine-subnet>:60739)
(...)
error: [Errno 113] No route to host
(etc.)

Can someone help out in cross-checking what I missed?

edit retag flag offensive close merge delete

Comments

1

The port in the rosrpc URIs is not 11311 (or the port of the roslaunch server) because those URIs are not pointing to the master (or the roslaunch server), but to the port the service server uses to accept an incoming service request.

gvdhoorn gravatar image gvdhoorn  ( 2018-07-27 09:47:37 -0500 )edit

after your edit:

error: [Errno 113] No route to host

This points to your service server not having been configured with the correct value for either ROS_IP or ROS_HOSTNAME. Or if it is the correct IP, then the docker container can't reach it.

gvdhoorn gravatar image gvdhoorn  ( 2018-07-27 10:25:24 -0500 )edit

Right. I am not sure what to look at else w.r.t. service server config. I am not sure what the default docker network behaviour is. probably good to continue debugging here...

thinwybk gravatar image thinwybk  ( 2018-07-27 10:36:42 -0500 )edit

The Python stuff you show seems to setup a bridged network, so IPs in the dev-machine-subnet should probably work. Is some-ip-in-the-dev-machine-subnet in the rosrpc URI an expected value? Can you ping that IP from the container? If not, that would be the first thing to fix.

gvdhoorn gravatar image gvdhoorn  ( 2018-07-27 10:39:22 -0500 )edit

Btw: I don't see you configuring the IP for the container to use. If the container uses a 'random' IP instead of the one you set in ROS_IP, then things probably won't work.

Edit: in fact, if the code sample you show is what you actually run I'm pretty sure that is the problem. The ..

gvdhoorn gravatar image gvdhoorn  ( 2018-07-27 10:40:44 -0500 )edit
1

.. container must have the same IP as you pass in for ROS_IP. Even if test is a bridged network, handing out IPs from another subnet will most likely not work. You'll have to use IPs from the test network. Afaik, bridged for a Docker network is not like VMware's bridged (for example).

gvdhoorn gravatar image gvdhoorn  ( 2018-07-27 10:43:19 -0500 )edit

Right, totally missed that. When using docker-py setting the ip of the container explicitly requires to configuring the network (subnets , etc.).

thinwybk gravatar image thinwybk  ( 2018-07-27 10:52:54 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2018-07-27 11:43:31 -0500

thinwybk gravatar image

I missed to configure the docker subnet configuration

ipam_pool = docker.types.IPAMPool(subnet='X.X.X.0/24')
ipam_config = docker.types.IPAMConfig(pool_configs=[ipam_pool])
dn = dc.networks.create(name='some_test', driver="bridge", ipam=ipam_config)

and a specific ip for the container

some_node = dc.containers.run(image=di[0].id, environment=["ROS_IP=<some-ip-in-the-dev-machine-subnet>", "ROS_MASTER_URI=http://<dev-machine-ip>:11311"], name='<some-node>', command=rosrun_command, detach=True, tty=True)
dn.connect(rc_itempick, ipv4_address='<some-ip-in-the-dev-machine-subnet>')

Have to do additional checks but seems to work now...

edit flag offensive delete link more

Comments

I'm surprised you can actually hand out IPs from a different subnet, but if it works for you ..

gvdhoorn gravatar image gvdhoorn  ( 2018-07-29 03:27:23 -0500 )edit

The ips have to be in the same subnet. Which different subnets do you mean? Have I missed a typo above...?

thinwybk gravatar image thinwybk  ( 2018-07-30 11:37:09 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2018-07-27 09:44:18 -0500

Seen: 989 times

Last updated: Jul 27 '18