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
00021 import rospy
00022 from time import sleep
00023 
00024 roslib.load_manifest('sr_ronex_examples')
00025 
00026 # --------------------------------------------------------------------------------
00027 
00028 """
00029 Assume that your RoNeX consists of a Bridge (IN) module, and one or multiple
00030 General I/O module(s). This class demonstrates how to access the General I/O module(s)
00031 listed in the parameter server. For each General I/O module, the parameter server
00032 stores parameters such as its product_id, product_name, ronex_id, path, and serial.
00033 Note that the Python version is simpler than the C++ version, because parameters
00034 are stored as a dictionary in Python.
00035 """
00036 
00037 
00038 class SrRonexParseParamExample(object):
00039 
00040     def __init__(self):
00041         self.find_general_io_modules()
00042 
00043     def find_general_io_modules(self):
00044         """
00045         Find the General I/O modules present on the system.
00046         """
00047         # Wait until there's at least one General I/O module.
00048         while True:
00049             try:
00050                 rospy.get_param("/ronex/devices/0/ronex_id")
00051                 break
00052             except:
00053                 rospy.loginfo("Waiting for the General I/O module to be loaded properly.")
00054                 sleep(0.1)
00055 
00056         # Retrieve all General I/O modules (stored in a dict) from the parameter server.
00057         # Note that the dict's keyword is ronex_param_id, and it starts from zero.
00058         devices = rospy.get_param("/ronex/devices")
00059         for ronex_param_id in devices:
00060             # Retrieve the values of all parameters related to the current General I/O module.
00061             # Path looks like "/ronex/general_io/2", where 2 is a ronex_id.
00062             rospy.loginfo("*** General I/O Module %s ***",  ronex_param_id)
00063             rospy.loginfo("product_id   = %s", devices[ronex_param_id]["product_id"])
00064             rospy.loginfo("product_name = %s", devices[ronex_param_id]["product_name"])
00065             rospy.loginfo("ronex_id     = %s", devices[ronex_param_id]["ronex_id"])
00066             rospy.loginfo("path         = %s", devices[ronex_param_id]["path"])
00067             rospy.loginfo("serial       = %s", devices[ronex_param_id]["serial"])
00068 
00069 # --------------------------------------------------------------------------------
00070 
00071 if __name__ == "__main__":
00072 
00073     rospy.init_node("sr_ronex_parse_parameter_server")
00074 
00075     # This class demonstrates how to access the General I/O module(s)
00076     # listed in the parameter server.
00077     SrRonexParseParamExample()
00078 
00079 # --------------------------------------------------------------------------------


sr_ronex_examples
Author(s): Ugo Cupcic, Toni Oliver, Mark Pitchless, Yi Li
autogenerated on Thu Jun 6 2019 21:22:11