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

Revision history [back]

Ok I give it a try. If I understand you right, you want to execute multiple and always different functions with one function call? Well I guess it is not supported by the rosservice, but you could probably use a string and execute the python code in it (storing your function calls) ... what ever you need that for ...

But I really do not know if this would be "good practice", it somehow does not feel like that for me, if you know what I mean and of course I understood you right. ;-)

http://stackoverflow.com/questions/701802/how-do-i-execute-a-string-containing-python-code-in-python

Ok I give it a try. If I understand you right, you want to execute multiple and always different functions with one function call? Well I guess it is not supported by the rosservice, but you could probably use a string and execute the python code in it (storing your function calls) ... what ever you need that for ...

But I really do not know if this would be "good practice", it somehow does not feel like that for me, if you know what I mean and of course I understood you right. ;-)

http://stackoverflow.com/questions/701802/how-do-i-execute-a-string-containing-python-code-in-python


Update:

Yes you can create services for each object you create of course also at runtime, but the service name has to be unique systemwide. So if you have a serviceFoo1 there is only this service called like that, others must be called serviceFoo2 etc... And the service file (with defined parameters) must exist, before you run the application! You can of course do multiple of them and use each multiple times. But they must be there before runtime! The classes are created by catkin

So adding parameters won't work at runtime, well except you would use my first try, that I won't recommend.

Ok I give it a try. If I understand you right, you want to execute multiple and always different functions with one function call? Well I guess it is not supported by the rosservice, but you could probably use a string and execute the python code in it (storing your function calls) ... what ever you need that for ...

But I really do not know if this would be "good practice", it somehow does not feel like that for me, if you know what I mean and of course I understood you right. ;-)

http://stackoverflow.com/questions/701802/how-do-i-execute-a-string-containing-python-code-in-python


Update:

Yes you can create services for each object you create of course also at runtime, but the service name has to be unique systemwide. So if you have a serviceFoo1 there is only this service called like that, others must be called serviceFoo2 etc... And the service file (with defined parameters) must exist, before you run the application! You can of course do multiple of them and use each multiple times. But they must be there before runtime! The classes are created by catkin

So adding parameters won't work at runtime, well except you would use my first try, that I won't recommend.

Update 2 (Comment):

You can only use standard variables for the parameters: int, uint, bool, string, float (also in arrays and dynamic arrays) and any message type, but they also only use standard types.

Ok I give it a try. If I understand you right, you want to execute multiple and always different functions with one function call? Well I guess it is not supported by the rosservice, but you could probably use a string and execute the python code in it (storing your function calls) ... what ever you need that for ...

But I really do not know if this would be "good practice", it somehow does not feel like that for me, if you know what I mean and of course I understood you right. ;-)

http://stackoverflow.com/questions/701802/how-do-i-execute-a-string-containing-python-code-in-python


Update:

Yes you can create services for each object you create of course also at runtime, but the service name has to be unique systemwide. So if you have a serviceFoo1 there is only this service called like that, others must be called serviceFoo2 etc... And the service file (with defined parameters) must exist, before you run the application! You can of course do multiple of them and use each multiple times. But they must be there before runtime! The classes are created by catkin

So adding parameters won't work at runtime, well except you would use my first try, that I won't recommend.


Update 2 (Comment):

You can only use standard variables for the parameters: int, uint, bool, string, float (also in arrays and dynamic arrays) and any message type, but they also only use standard types.

Ok I give it a try. If I understand you right, you want to execute multiple and always different functions with one function call? Well I guess it is not supported by the rosservice, but you could probably use a string and execute the python code in it (storing your function calls) ... what ever you need that for ...

But I really do not know if this would be "good practice", it somehow does not feel like that for me, if you know what I mean and of course I understood you right. ;-)

http://stackoverflow.com/questions/701802/how-do-i-execute-a-string-containing-python-code-in-python


Update:

Yes you can create services for each object you create of course also at runtime, but the service name has to be unique systemwide. So if you have a serviceFoo1 there is only this service called like that, others must be called serviceFoo2 etc... And the service file (with defined parameters) must exist, before you run the application! You can of course do multiple of them and use each multiple times. But they must be there before runtime! The classes are created by catkin

So adding parameters won't work at runtime, well except you would use my first try, that I won't recommend.


Update 2 (Comment):

You can only use standard variables for the parameters: int, uint, bool, string, float (also in arrays and dynamic arrays) and any message type, but they also only use standard types.

You could probably use JSON to transmit a class object to your function (would feel ok for me and also works in CPP or python). Or you could send python class code (somehow this does not feel right).

Ok I give it a try. If I understand you right, you want to execute multiple and always different functions with one function call? Well I guess it is not supported by the rosservice, but you could probably use a string and execute the python code in it (storing your function calls) ... what ever you need that for ...

But I really do not know if this would be "good practice", it somehow does not feel like that for me, if you know what I mean and of course I understood you right. ;-)

http://stackoverflow.com/questions/701802/how-do-i-execute-a-string-containing-python-code-in-python


Update:

Yes you can create services for each object you create of course also at runtime, but the service name has to be unique systemwide. So if you have a serviceFoo1 there is only this service called like that, others must be called serviceFoo2 etc... And the service file (with defined parameters) must exist, before you run the application! You can of course do multiple of them and use each multiple times. But they must be there before runtime! The classes are created by catkin

So adding parameters won't work at runtime, well except you would use my first try, that I won't recommend.


Update 2 (Comment):

You can only use standard variables for the parameters: int, uint, bool, string, float (also in arrays and dynamic arrays) and any message type, but they also only use standard types.

You could probably use JSON (in a string) to transmit a class object to your function (would feel ok for me and also works in CPP or python). Or you could send python class code (somehow this does not feel right).