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 PWM
00024
00025 roslib.load_manifest('sr_ronex_examples')
00026
00027
00028
00029
00030
00031
00032 def flashLED(topic):
00033 pwm_period = 320
00034
00035 pwm_on_time_0 = pwm_period
00036
00037 pwm_on_time_1 = 0
00038
00039 pub = rospy.Publisher(topic, PWM)
00040 while not rospy.is_shutdown():
00041
00042 pwm_on_time_0 -= 10
00043 if pwm_on_time_0 < 0:
00044 pwm_on_time_0 = pwm_period
00045
00046
00047 pwm = PWM()
00048 pwm.pwm_period = pwm_period
00049 pwm.pwm_on_time_0 = pwm_on_time_0
00050 pwm.pwm_on_time_1 = pwm_on_time_1
00051
00052 pub.publish(pwm)
00053 rospy.sleep(0.01)
00054
00055
00056
00057 """
00058 This class demonstrates how to find the General I/O module with the given ronex_id.
00059 """
00060
00061
00062 class SrRonexFindGeneralIOModule(object):
00063
00064 def __init__(self, ronex_id):
00065 self.ronex_id = ronex_id
00066
00067 """
00068 Get the path of the General I/O module with the given ronex_id.
00069 Note that None is returned if the module is not found.
00070 """
00071 def get_path(self):
00072 """
00073 Find the ronexes present on the system.
00074 """
00075
00076 while True:
00077 try:
00078 rospy.get_param("/ronex/devices/0/ronex_id")
00079 break
00080 except:
00081 rospy.loginfo("Waiting for the ronex to be loaded properly.")
00082 sleep(0.1)
00083
00084 """
00085 Retrieve all the ronex parameter ids from the parameter server.
00086 If there are three General I/O modules, then ronex_param_ids is [0,1,2].
00087 Note that the id starts from zero. And the size of the returned variable
00088 is equal to the number of General I/O modules.
00089 """
00090 ronex_param_ids = rospy.get_param("/ronex/devices")
00091 for key in ronex_param_ids:
00092 if self.ronex_id == ronex_param_ids[key]["ronex_id"]:
00093 path = ronex_param_ids[key]["path"]
00094 return path
00095
00096
00097
00098 """
00099 Assume that your RoNeX consists of a Bridge (IN) module, and one or multiple General I/O module(s).
00100 This example demonstrates how to flash a LED light with pulse-width modulation (PWM).
00101 """
00102 if __name__ == "__main__":
00103 rospy.init_node('sr_ronex_flash_LED_with_PWM')
00104
00105 print "Please configure D0 pin of your ronex module as output (you can use plugin Dynamic Reconfigure in rqt): \n"
00106
00107
00108
00109 ronex_id = raw_input("Please enter the ronex id: ")
00110 findModule = SrRonexFindGeneralIOModule(str(ronex_id))
00111 path = findModule.get_path()
00112
00113 if path is not None:
00114
00115
00116 topic = path + "/command/pwm/0"
00117 rospy.loginfo("topic = %s.", topic)
00118 try:
00119 flashLED(topic)
00120 except rospy.ROSInterruptException:
00121 pass
00122 else:
00123 rospy.loginfo("Failed to find the General I/O module with the given ronex_id %s.", ronex_id)
00124
00125