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
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 import argparse
00031 import sys
00032
00033 import rospy
00034
00035 import baxter_interface
00036
00037
00038 def blink():
00039 navs = (
00040 baxter_interface.Navigator('left'),
00041 baxter_interface.Navigator('right'),
00042 baxter_interface.Navigator('torso_left'),
00043 baxter_interface.Navigator('torso_right'),)
00044
00045 print ("Blinking LED's for 10 seconds")
00046 rate = rospy.Rate(10)
00047 i = 0
00048 while not rospy.is_shutdown() and i < 100:
00049 for nav in navs:
00050 nav.inner_led = not nav.inner_led
00051 nav.outer_led = not nav.outer_led
00052 rate.sleep()
00053 i += 1
00054
00055
00056 def echo_input():
00057 def b0_pressed(v):
00058 print ("Button 0: %s" % (v,))
00059
00060 def b1_pressed(v):
00061 print ("Button 1: %s" % (v,))
00062
00063 def b2_pressed(v):
00064 print ("Button 2: %s" % (v,))
00065
00066 def wheel_moved(v):
00067 print ("Wheel Increment: %d, New Value: %s" % (v, nav.wheel))
00068
00069 nav = baxter_interface.Navigator('left')
00070 nav.button0_changed.connect(b0_pressed)
00071 nav.button1_changed.connect(b1_pressed)
00072 nav.button2_changed.connect(b2_pressed)
00073 nav.wheel_changed.connect(wheel_moved)
00074
00075 print ("Press input buttons on the left navigator, "
00076 "input will be echoed here.")
00077
00078 rate = rospy.Rate(1)
00079 i = 0
00080 while not rospy.is_shutdown() and i < 10:
00081 rate.sleep()
00082 i += 1
00083
00084
00085 def main():
00086 """RSDK Navigator Input/Output Example
00087
00088 Demonstrates Navigator output by blinking the lights, or
00089 Navigator input by echoing input values from wheels and
00090 buttons.
00091
00092 Run this example, selecting either the input or output action
00093 with the corresponding arguments, then follow the instructions
00094 on screen.
00095
00096 Uses the baxter_interface.Navigator class to interface with the
00097 four Navigator button/LED controls. Also shows a nice example of
00098 using the button_changed Signal feature.
00099 """
00100 arg_fmt = argparse.RawDescriptionHelpFormatter
00101 parser = argparse.ArgumentParser(formatter_class=arg_fmt,
00102 description=main.__doc__)
00103 action_grp = parser.add_mutually_exclusive_group(required=True)
00104 action_grp.add_argument(
00105 '-b', '--blink', dest='action', action='store_const', const=blink,
00106 help='Blink navigator lights for 10 seconds'
00107 )
00108 action_grp.add_argument(
00109 '-i', '--input', dest='action', action='store_const', const=echo_input,
00110 help='Show input of left arm for 10 seconds'
00111 )
00112 args = parser.parse_args(rospy.myargv()[1:])
00113
00114 rospy.init_node('rsdk_navigator_io', anonymous=True)
00115 args.action()
00116 return 0
00117
00118 if __name__ == '__main__':
00119 sys.exit(main())