Two nodes with common base class declaring a namespaced service path
I want to be able to use a base class for declaring a service that separate nodes can utilize. I thought I might be able to remap this in a launch file, but I must be doing something wrong.
To illustrate, imagine this class hierarchy:
class Base(object):
def __init__(self):
service = rospy.Service('get_state', ...)
class Node1(Base):
def __init__(self):
super(Node1, self).__init__()
rospy.init_node('node1')
class Node2(Base):
def __init__(self):
super(Node2, self).__init__()
rospy.init_node('node2')
My hope would be that I could call:
$ rosservice my_pkg /node1/get_state
$ rosservice my_pkg /node2/get_state
Instead I have a service named "/get_state" and a collision.
I have tried a few things:
- re-order so init_node is called before super of the base class
- use ~get_state but this results in '/unnamed/get_state' which is still a collision
- Use a launch file to remap the namespace
This last attempt included a launch file like this:
<node pkg="my_pkg" name="node1" type="node1">
<remap from="get_state" to="node1/get_state"/>
</node>
The result still seems to be a name collision and only a /get_state for the first node and not the second.
Is there a simpler/better way to go about something like this?