ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
Through a bit more experimenting, the combination of #1 and #2 did the trick. It still seems like there might be a cleaner way.
class Base(object):
def __init__(self):
service = rospy.Service('~get_state', ...)
class Node1(Base):
def __init__(self):
rospy.init_node('node1')
super(Node1, self).__init__()
Note that init_node is called before Service and the Service includes a tilde (~).
That seems consistent with the docs here to keep the Service private to the node... http://wiki.ros.org/Names
2 | No.2 Revision |
Through a bit more experimenting, the combination of #1 and #2 did the trick. It still seems like there might be a cleaner way.
class Base(object):
def __init__(self):
service = rospy.Service('~get_state', ...)
class Node1(Base):
def __init__(self):
rospy.init_node('node1')
super(Node1, self).__init__()
Note that init_node is called before the Service is created in the super class and the further Service includes a tilde (~).
(~). That seems consistent with the docs here to keep the Service private to the node...
http://wiki.ros.org/Names
3 | No.3 Revision |
Through a bit more experimenting, the combination of #1 and #2 did the trick. It still seems like there might be a cleaner way.
# src/foo.py
class Base(object):
def __init__(self):
service = rospy.Service('~get_state', ...)
# nodes/node1.py
import foo
class Node1(Base):
Node1(foo.Base):
def __init__(self):
rospy.init_node('node1')
super(Node1, self).__init__()
Note that init_node is called before the Service is created in the super class and further Service includes a tilde (~). That seems consistent with the docs to keep the Service private to the node... http://wiki.ros.org/Names
4 | No.4 Revision |
Through The answer is simply to include a bit tilde (~) when creating the service. A good practice would be to call init_node from the main block to prevent the mistake of including more experimenting, than one node in a single process. There isn't much benefit in calling the combination of #1 and #2 did init_node from within the trick. It still seems like there might be a cleaner way.class __init__.
# src/foo.py
class Base(object):
def __init__(self):
service = rospy.Service('set_state', ...) # results in /set_state
service = rospy.Service('~get_state', ...) # results in /node1/get_state (as desired)
# nodes/node1.py
import foo
class Node1(foo.Base):
def __init__(self):
rospy.init_node('node1')
super(Node1, self).__init__()
if __name__ == '__main__':
super(Node1, self).__init__()
rospy.init_node('node1')
Note that init_node is called before the Service is created in the super class and further Service includes a tilde (~). That seems consistent with the docs to keep the Service private to the node...
node's namespace...
http://wiki.ros.org/Names
5 | No.5 Revision |
The answer is simply to include a tilde (~) when creating the service. A good practice would be to call init_node from the main block to prevent the mistake of including more than one node in a single process. There isn't much benefit in calling the init_node from within the class __init__.
# src/foo.py
class Base(object):
def __init__(self):
service = rospy.Service('set_state', ...) # results in /set_state
service = rospy.Service('~get_state', ...) # results in /node1/get_state (as desired)
# nodes/node1.py
import foo
class Node1(foo.Base):
def __init__(self):
super(Node1, self).__init__()
if __name__ == '__main__':
rospy.init_node('node1')
node = Node1()
...
That seems consistent with the docs to keep the Service private to the node's namespace... http://wiki.ros.org/Names
6 | No.6 Revision |
The answer is simply to include a tilde (~) when creating the service. A good practice would be to call init_node from the main block to prevent the mistake of including more than one node in a single process. There isn't much benefit in calling the init_node from within the class __init__.
# src/foo.py
class Base(object):
def __init__(self):
service = rospy.Service('set_state', ...) # results in /set_state
service = rospy.Service('~get_state', ...) # results in /node1/get_state (as desired)
# nodes/node1.py
import foo
class Node1(foo.Base):
def __init__(self):
super(Node1, self).__init__()
if __name__ == '__main__':
rospy.init_node('node1')
rospy.init_node('node1') # moved out of Node1.__init__
node = Node1()
...
That seems consistent with the docs to keep the Service private to the node's namespace... http://wiki.ros.org/Names