Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 import roslib
00021 import rospy
00022 from time import sleep
00023 from sr_ronex_msgs.msg import GeneralIOState
00024
00025 roslib.load_manifest('sr_ronex_examples')
00026
00027
00028
00029 """
00030 The callback function given to the subscribe() call.
00031 """
00032
00033
00034 def generalIOState_callback(data):
00035
00036 analogue = data.analogue
00037 rospy.loginfo("analogue = %s", analogue)
00038
00039
00040
00041 """
00042 This class demonstrates how to find the General I/O module with the given ronex_id.
00043 """
00044
00045
00046 class SrRonexFindGeneralIOModule(object):
00047
00048 def __init__(self, ronex_id):
00049 self.ronex_id = ronex_id
00050
00051 """
00052 Get the path of the General I/O module with the given ronex_id.
00053 Note that None is returned if the module is not found.
00054 """
00055 def get_path(self):
00056 """
00057 Find the ronexes present on the system.
00058 """
00059
00060 while True:
00061 try:
00062 rospy.get_param("/ronex/devices/0/ronex_id")
00063 break
00064 except:
00065 rospy.loginfo("Waiting for the ronex to be loaded properly.")
00066 sleep(0.1)
00067
00068 """
00069 Retrieve all the ronex parameter ids from the parameter server.
00070 If there are three General I/O modules, then ronex_param_ids is [0,1,2].
00071 Note that the id starts from zero. And the size of the returned variable
00072 is equal to the number of General I/O modules.
00073 """
00074 ronex_param_ids = rospy.get_param("/ronex/devices")
00075 for key in ronex_param_ids:
00076 if self.ronex_id == ronex_param_ids[key]["ronex_id"]:
00077 path = ronex_param_ids[key]["path"]
00078 return path
00079
00080
00081
00082 """
00083 Assume that your RoNeX consists of a Bridge (IN) module, and one
00084 or multiple General I/O module(s). This example demonstrates how
00085 to read analogue data with RoNeX.
00086 """
00087 if __name__ == "__main__":
00088 rospy.init_node("sr_ronex_read_analog_data")
00089
00090
00091
00092 ronex_id = raw_input("Please enter the ronex id: ")
00093 findModule = SrRonexFindGeneralIOModule(str(ronex_id))
00094 path = findModule.get_path()
00095
00096 if path is not None:
00097
00098 topic = path + "/state"
00099 rospy.Subscriber(topic, GeneralIOState, generalIOState_callback)
00100 rospy.spin()
00101 else:
00102 rospy.loginfo("Failed to find the General I/O module with the given ronex_id %s.", ronex_id)
00103
00104