sr_ronex_parse_parameter_server.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 # ####################################################################
00004 # Copyright (c) 2013, Shadow Robot Company, All rights reserved.
00005 # 
00006 # This library is free software; you can redistribute it and/or
00007 # modify it under the terms of the GNU Lesser General Public
00008 # License as published by the Free Software Foundation; either
00009 # version 3.0 of the License, or (at your option) any later version.
00010 #
00011 # This library is distributed in the hope that it will be useful,
00012 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00014 # Lesser General Public License for more details.
00015 #
00016 # You should have received a copy of the GNU Lesser General Public
00017 # License along with this library.
00018 # ####################################################################
00019 
00020 import roslib; roslib.load_manifest('sr_ronex_examples')
00021 import rospy
00022 from time import sleep
00023 
00024 #--------------------------------------------------------------------------------
00025 
00026 """
00027 Assume that your RoNeX consists of a Bridge (IN) module, and one or multiple
00028 General I/O module(s). This class demonstrates how to access the General I/O module(s)
00029 listed in the parameter server. For each General I/O module, the parameter server 
00030 stores parameters such as its product_id, product_name, ronex_id, path, and serial.
00031 Note that the Python version is simpler than the C++ version, because parameters
00032 are stored as a dictionary in Python.
00033 """
00034 class SrRonexParseParamExample(object):
00035 
00036     def __init__(self):
00037         self.find_general_io_modules()
00038         
00039     def find_general_io_modules(self):
00040         """
00041         Find the General I/O modules present on the system.
00042         """
00043         # Wait until there's at least one General I/O module.
00044         while True:
00045             try:
00046                 rospy.get_param("/ronex/devices/0/ronex_id")
00047                 break
00048             except:
00049                 rospy.loginfo("Waiting for the General I/O module to be loaded properly.")
00050                 sleep(0.1)
00051 
00052         # Retrieve all General I/O modules (stored in a dict) from the parameter server.
00053         # Note that the dict's keyword is ronex_param_id, and it starts from zero.
00054         devices = rospy.get_param("/ronex/devices")
00055         for ronex_param_id in devices:
00056             # Retrieve the values of all parameters related to the current General I/O module.
00057             # Path looks like "/ronex/general_io/2", where 2 is a ronex_id.
00058             rospy.loginfo( "*** General I/O Module %s ***",  ronex_param_id );
00059             rospy.loginfo( "product_id   = %s", devices[ronex_param_id]["product_id"] );
00060             rospy.loginfo( "product_name = %s", devices[ronex_param_id]["product_name"] );
00061             rospy.loginfo( "ronex_id     = %s", devices[ronex_param_id]["ronex_id"] );
00062             rospy.loginfo( "path         = %s", devices[ronex_param_id]["path"]);
00063             rospy.loginfo( "serial       = %s", devices[ronex_param_id]["serial"] );
00064 
00065 #--------------------------------------------------------------------------------
00066 
00067 if __name__ == "__main__":
00068 
00069     rospy.init_node("sr_ronex_parse_parameter_server") 
00070 
00071     # This class demonstrates how to access the General I/O module(s) 
00072     # listed in the parameter server. 
00073     SrRonexParseParamExample()
00074 
00075 #--------------------------------------------------------------------------------


sr_ronex_examples
Author(s): Ugo Cupcic, Toni Oliver, Mark Pitchless, Yi Li
autogenerated on Fri Aug 28 2015 13:12:34