def ros_action(fn = None, type = None, name = None): """ The @ros_action decorator. This decorator is very similar to the standard :py:meth:`morse.core.services.async_service` decorator. It sets a class method to be a asynchronous service, exposed as a ROS action of type `type`. This decorator can only be used on methods in classes inheriting from :py:class:`morse.core.object.MorseObjectClass`. :param callable fn: [automatically set by Python to point to the decorated function] :param class type: you MUST set this parameter to define the type of the ROS action. :param string name: by default, the name of the service is the name of the method. You can override it by setting the 'name' argument. Your ROS action will appear as /component_instance/<name>/... """ if not type: logger.error("You must provide a valid ROS action type when using the " + \ "@ros_action decorator, e.g. @ros_action(type=MyRosAction). Action ignored.") return if not hasattr(fn, "__call__"): return partial(ros_action, type = type, name = name) fn._ros_action_type = type return services.service(fn, component = None, name = name, async = True)
def ros_action(fn = None, type = None, name = None): """ The @ros_action decorator. This decorator is very similar to the standard :py:meth:`morse.core.services.async_service` decorator. It sets a class method to be a asynchronous service, exposed as a ROS action of type `type`. This decorator can only be used on methods in classes inheriting from :py:class:`morse.core.object.Object`. :param callable fn: [automatically set by Python to point to the decorated function] :param class type: you MUST set this parameter to define the type of the ROS action. :param string name: by default, the name of the service is the name of the method. You can override it by setting the 'name' argument. Your ROS action will appear as /component_instance/<name>/... """ if not type: logger.error("You must provide a valid ROS action type when using the " + \ "@ros_action decorator, e.g. @ros_action(type=MyRosAction). Action ignored.") return if not hasattr(fn, "__call__"): return partial(ros_action, type = type, name = name) fn._ros_action_type = type return services.service(fn, component = None, name = name, async = True)
def ros_service(fn=None, type=None, component=None, name=None): """ The @ros_service decorator. This decorator is very similar to the standard :py:meth:`morse.core.services.service` decorator. It sets a free function or class method to be a (synchronous) service, exposed as a ROS service of type `type`. This decorator works both with free function and for methods in classes inheriting from :py:class:`morse.core.object.Object`. In the former case, you must specify a component (your service will belong to this namespace), in the later case, it is automatically set to the name of the corresponding MORSE component. :param callable fn: [automatically set by Python to point to the decorated function] :param class type: you MUST set this parameter to define the type of the ROS action. :param string component: you MUST set this parameter to define the name of the component which export the service ONLY for free functions. Cf explanation above. :param string name: by default, the name of the service is the name of the method. You can override it by setting the 'name' argument. Your ROS service will appear as /<name> """ if not type: logger.error("You must provide a valid ROS action type when using the " + \ "@ros_action decorator, e.g. @ros_action(type=MyRosAction). Service ignored.") return if not hasattr(fn, "__call__"): return partial(ros_service, type=type, component=component, name=name) fn._ros_service_type = type return services.service(fn, component=component, name=name, asynchronous=False)
def ros_service(fn=None, type=None, component=None, name=None): """ The @ros_service decorator. This decorator is very similar to the standard :py:meth:`morse.core.services.service` decorator. It sets a free function or class method to be a (synchronous) service, exposed as a ROS service of type `type`. This decorator works both with free function and for methods in classes inheriting from :py:class:`morse.core.object.Object`. In the former case, you must specify a component (your service will belong to this namespace), in the later case, it is automatically set to the name of the corresponding MORSE component. :param callable fn: [automatically set by Python to point to the decorated function] :param class type: you MUST set this parameter to define the type of the ROS action. :param string component: you MUST set this parameter to define the name of the component which export the service ONLY for free functions. Cf explanation above. :param string name: by default, the name of the service is the name of the method. You can override it by setting the 'name' argument. Your ROS service will appear as /<name> """ if not type: logger.error( "You must provide a valid ROS action type when using the " + "@ros_action decorator, e.g. @ros_action(type=MyRosAction). Service ignored." ) return if not hasattr(fn, "__call__"): return partial(ros_service, type=type, component=component, name=name) fn._ros_service_type = type return services.service(fn, component=component, name=name, async=False)