__init__.py
Go to the documentation of this file.
00001 # -*- coding: utf-8 -*-
00002 # vim:set ts=4 sw=4 et:
00003 
00004 __all__ = (
00005     'get_namespace',
00006     'set_namespace',
00007     'get_topic',
00008     'DEFAULT_NAMESPACE'
00009 )
00010 
00011 DEFAULT_NAMESPACE = '/mavros'
00012 
00013 # global namespace storage
00014 _mavros_ns = None
00015 _mavros_ns_update = []
00016 
00017 
00018 def get_namespace():
00019     """
00020     Returns mavros node namespace
00021     """
00022     global _mavros_ns
00023     if _mavros_ns is None:
00024         raise RuntimeError("mavros namespace is uninitialized! "
00025                            "Call mavros.set_namespace() first!")
00026     return _mavros_ns
00027 
00028 
00029 def set_namespace(ns=DEFAULT_NAMESPACE):
00030     """
00031     Sets namespace of mavros node
00032     """
00033     global _mavros_ns, _mavros_ns_update
00034     _mavros_ns = ns
00035 
00036     for cb in _mavros_ns_update:
00037         if callable(cb):
00038             cb()
00039 
00040 
00041 def register_on_namespace_update(cb):
00042     """
00043     Call callback after namespace update
00044     """
00045     global _mavros_ns_update
00046     _mavros_ns_update.append(cb)
00047 
00048 
00049 def get_topic(*args):
00050     """
00051     Create topic name for mavros node
00052     """
00053     return '/'.join((get_namespace(), ) + args)


mavros
Author(s): Vladimir Ermakov
autogenerated on Sat Jun 8 2019 19:55:19