How do you set namespace in a Python program?
Is it possible to set the namespace in a Python program? I have looked through the APIs and cannot fins any obvious way.
The reason I want to do it is that I run a Jupyter Notebook server and I need to use different namespaces for the same server.
For example: I want to dynamically change the namespace that is used when expanding a name "pose" for example. I want to be able to set the namespace to for example "/uav0" and "pose" as a topic would then be "/uav0/pose". And it is enough to be able to set that once for a Python program that is started with no namespace.
/Tommy Persson, Linköping University
What do you mean? The namespace for topics? For parameters? Something else?
For topics and parameters, does #q261862 help?
Yes, for topics and service calls. I did not see how the question you referred to could help. i tried for example:
but it did not work. I have written a lot of my code without the namespace in the specifcation of topics and services. If I set ROS_NAMESPACE before starting my Jupyter server it works but then this server can only handle notebooks with that namespace. I really need a way in the Pthon program to specify the namespace. Or maybe rewrite all code that specified names and use ROS_NAMESPACE environment variable there.
I still don't understand what you are trying to achieve. Could you please clarify by editing your question? Maybe also give a short example?
It could be (at least) any of the following:
A
, the second time in namespaceB
.A
and some in namespaceB
I want to dynamically change the namespace that is used when expanding a name "pose" for example. I want to be able to set the namespace to for example "/uav0" and "pose" as a topic would then be "/uav0/pose". And it is enough to be able to set that once for a Python program that is started with no namespace.
Just to double-check: "Changing dynamically" means at runtime. I.e. you want to start this and THEN change the namespace WHILE the node is running?
Yes, or while the Python program is running. I suppose the node is running when you do init. I want to have a Python program were I inside the program can set what
returns. I only need to set it once.