rosutils.py
Go to the documentation of this file.
00001 # MIT License
00002 #
00003 # Copyright (c) <2015> <Ikergune, Etxetar>
00004 #
00005 # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
00006 # (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge,
00007 # publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
00008 # subject to the following conditions:
00009 #
00010 # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
00011 #
00012 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00013 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
00014 # FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00015 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00016 
00017 
00018 def ros2Obj(msgInstance):
00019     ## \brief Map a Ros Object to dict
00020     # \param Ros Object instance
00021     obj = {}
00022     for key in msgInstance.__slots__:
00023         attr = getattr(msgInstance, key)
00024         if hasattr(attr, '__slots__'):
00025             obj[key] = ros2Obj(attr)
00026         else:
00027             obj[key] = attr
00028     return obj
00029 
00030 
00031 def obj2Ros(obj, msgInstance):
00032     ## \brief Map a dict to Ros Object
00033     # \param dictionary
00034     # \param Ros Object instance
00035     if hasattr(msgInstance, '__slots__'):
00036         for key in msgInstance.__slots__:
00037             if key in obj:
00038                 setattr(msgInstance, key, obj2Ros(obj[key], getattr(msgInstance, key)))
00039     else:
00040         if type(obj) is dict:
00041             raise Exception("Not a primitive")
00042         msgInstance = obj
00043     return msgInstance
00044 
00045 
00046 def ros2Definition(msgInstance):
00047     ## \brief Generate Ros object definition
00048     # \param ROS Object instance
00049     obj = {}
00050     index = 0
00051     for key in msgInstance.__slots__:
00052         attr = getattr(msgInstance, key)
00053         if hasattr(attr, '__slots__'):
00054             obj[key] = ros2Definition(attr)
00055         else:
00056             obj[key] = msgInstance._slot_types[index]
00057         index += 1
00058     return obj


firos
Author(s): IƱigo Gonzalez, igonzalez@ikergune.com
autogenerated on Thu Jun 6 2019 17:51:04