intera_examples/scripts/gripper_joystick.py
def map_joystick(joystick, limb):
    """
    maps joystick input to gripper commands

    @param joystick: an instance of a Joystick
    """
    print("Getting robot state... ")
    rs = intera_interface.RobotEnable(intera_interface.CHECK_VERSION)
    init_state = rs.state()
    try:
        gripper = intera_interface.Gripper(limb)
    except ValueError:
        rospy.logerr("Could not detect a gripper attached to the robot.")
        return

    def clean_shutdown():
        print("\nExiting example...")

    rospy.on_shutdown(clean_shutdown)

    # decrease position dead_zone
    gripper.set_dead_zone(2.5)

    # abbreviations
    jhi = lambda s: joystick.stick_value(s) > 0
    jlo = lambda s: joystick.stick_value(s) < 0
    bdn = joystick.button_down
    bup = joystick.button_up

    def print_help(bindings_list):
        print("Press Ctrl-C to quit.")
        for bindings in bindings_list:
            for (test, _cmd, doc) in bindings:
                if callable(doc):
                    doc = doc()
                print("%s: %s" % (str(test[1]), doc))

    def offset_position(offset):
        current = gripper.get_position()
        set_position = min(gripper.MAX_POSITION,
                          max(gripper.MIN_POSITION,
                             current + offset))
        gripper.set_position(set_position)

    def offset_holding(offset):
        current = gripper.get_force()
        print("Current force {0}".format(current))
        holding_force = min(gripper.MAX_FORCE,
                           max(gripper.MIN_FORCE,
                              current + offset))
        gripper.set_holding_force(holding_force)

    num_steps = 10.0
    position_step = (gripper.MAX_POSITION - gripper.MIN_POSITION) / num_steps
    force_step = (gripper.MAX_FORCE - gripper.MIN_FORCE) / num_steps
    bindings_list = []
    bindings = (
        #(test, command, description)
        ((bdn, ['btnLeft']), (gripper.reboot, []), "reboot"),
        ((bdn, ['btnUp']), (gripper.calibrate, []), "calibrate"),
        ((bdn, ['leftTrigger']), (gripper.close, []), "close"),
        ((bup, ['leftTrigger']), (gripper.open, []), "open (release)"),
        ((bdn, ['leftBumper']), (gripper.stop, []), "stop"),
        ((jlo, ['leftStickVert']), (offset_position, [-position_step]),
                                    "decrease position"),
        ((jhi, ['leftStickVert']), (offset_position, [position_step]),
                                     "increase position"),
        ((jlo, ['rightStickVert']), (offset_holding, [-force_step]),
                                    "decrease holding force"),
        ((jhi, ['rightStickVert']), (offset_holding, [force_step]),
                                    "increase holding force"),
        ((bdn, ['function1']), (print_help, [bindings_list]), "help"),
        ((bdn, ['function2']), (print_help, [bindings_list]), "help"),
    )
    bindings_list.append(bindings)

    rospy.loginfo("Enabling robot...")
    rs.enable()
    rate = rospy.Rate(100)
    print_help(bindings_list)
    print("Press <Start> button for help; Ctrl-C to stop...")
    while not rospy.is_shutdown():
        # test each joystick condition and call binding cmd if true
        for (test, cmd, doc) in bindings:
            if test[0](*test[1]):
                cmd[0](*cmd[1])
                print(doc)
        rate.sleep()
    rospy.signal_shutdown("Example finished.")

    maps joystick input to gripper commands

    @param joystick: an instance of a Joystick
    
maps joystick input to gripper commands
maps joystick input to gripper commands
def map_joystick(joystick, limb):
    print("Getting robot state... ")
    rs = intera_interface.RobotEnable(intera_interface.CHECK_VERSION)
    init_state = rs.state()
    try:
        gripper = intera_interface.Gripper(limb)
    except ValueError:
        rospy.logerr("Could not detect a gripper attached to the robot.")
        return
    def clean_shutdown():
        print("\nExiting example...")
    rospy.on_shutdown(clean_shutdown)
    gripper.set_dead_zone(2.5)
    jhi = lambda s: joystick.stick_value(s) > 0
    jlo = lambda s: joystick.stick_value(s) < 0
    bdn = joystick.button_down
    bup = joystick.button_up
    def print_help(bindings_list):
        print("Press Ctrl-C to quit.")
        for bindings in bindings_list:
            for (test, _cmd, doc) in bindings:
                if callable(doc):
                    doc = doc()
                print("%s: %s" % (str(test[1]), doc))
    def offset_position(offset):
        current = gripper.get_position()
        set_position = min(gripper.MAX_POSITION,
                          max(gripper.MIN_POSITION,
                             current + offset))
        gripper.set_position(set_position)
    def offset_holding(offset):
        current = gripper.get_force()
        print("Current force {0}".format(current))
        holding_force = min(gripper.MAX_FORCE,
                           max(gripper.MIN_FORCE,
                              current + offset))
        gripper.set_holding_force(holding_force)
    num_steps = 10.0
    position_step = (gripper.MAX_POSITION - gripper.MIN_POSITION) / num_steps
    force_step = (gripper.MAX_FORCE - gripper.MIN_FORCE) / num_steps
    bindings_list = []
    bindings = (
        ((bdn, ['btnLeft']), (gripper.reboot, []), "reboot"),
        ((bdn, ['btnUp']), (gripper.calibrate, []), "calibrate"),
        ((bdn, ['leftTrigger']), (gripper.close, []), "close"),
        ((bup, ['leftTrigger']), (gripper.open, []), "open (release)"),
        ((bdn, ['leftBumper']), (gripper.stop, []), "stop"),
        ((jlo, ['leftStickVert']), (offset_position, [-position_step]),
                                    "decrease position"),
        ((jhi, ['leftStickVert']), (offset_position, [position_step]),
                                     "increase position"),
        ((jlo, ['rightStickVert']), (offset_holding, [-force_step]),
                                    "decrease holding force"),
        ((jhi, ['rightStickVert']), (offset_holding, [force_step]),
                                    "increase holding force"),
        ((bdn, ['function1']), (print_help, [bindings_list]), "help"),
        ((bdn, ['function2']), (print_help, [bindings_list]), "help"),
    )
    bindings_list.append(bindings)
    rospy.loginfo("Enabling robot...")
    rs.enable()
    rate = rospy.Rate(100)
    print_help(bindings_list)
    print("Press <Start> button for help; Ctrl-C to stop...")
    while not rospy.is_shutdown():
        for (test, cmd, doc) in bindings:
            if test[0](*test[1]):
                cmd[0](*cmd[1])
                print(doc)
        rate.sleep()
    rospy.signal_shutdown("Example finished.")
def map_joystick ( joystick , limb ) : print ( "Getting robot state... " ) rs = intera_interface . RobotEnable ( intera_interface . CHECK_VERSION ) init_state = rs . state ( ) try : gripper = intera_interface . Gripper ( limb ) except ValueError : rospy . logerr ( "Could not detect a gripper attached to the robot." ) return def clean_shutdown ( ) : print ( "\nExiting example..." ) rospy . on_shutdown ( clean_shutdown ) gripper . set_dead_zone ( 2.5 ) jhi = lambda s : joystick . stick_value ( s ) > 0 jlo = lambda s : joystick . stick_value ( s ) < 0 bdn = joystick . button_down bup = joystick . button_up def print_help ( bindings_list ) : print ( "Press Ctrl-C to quit." ) for bindings in bindings_list : for ( test , _cmd , doc ) in bindings : if callable ( doc ) : doc = doc ( ) print ( "%s: %s" % ( str ( test [ 1 ] ) , doc ) ) def offset_position ( offset ) : current = gripper . get_position ( ) set_position = min ( gripper . MAX_POSITION , max ( gripper . MIN_POSITION , current + offset ) ) gripper . set_position ( set_position ) def offset_holding ( offset ) : current = gripper . get_force ( ) print ( "Current force {0}" . format ( current ) ) holding_force = min ( gripper . MAX_FORCE , max ( gripper . MIN_FORCE , current + offset ) ) gripper . set_holding_force ( holding_force ) num_steps = 10.0 position_step = ( gripper . MAX_POSITION - gripper . MIN_POSITION ) / num_steps force_step = ( gripper . MAX_FORCE - gripper . MIN_FORCE ) / num_steps bindings_list = [ ] bindings = ( ( ( bdn , [ 'btnLeft' ] ) , ( gripper . reboot , [ ] ) , "reboot" ) , ( ( bdn , [ 'btnUp' ] ) , ( gripper . calibrate , [ ] ) , "calibrate" ) , ( ( bdn , [ 'leftTrigger' ] ) , ( gripper . close , [ ] ) , "close" ) , ( ( bup , [ 'leftTrigger' ] ) , ( gripper . open , [ ] ) , "open (release)" ) , ( ( bdn , [ 'leftBumper' ] ) , ( gripper . stop , [ ] ) , "stop" ) , ( ( jlo , [ 'leftStickVert' ] ) , ( offset_position , [ - position_step ] ) , "decrease position" ) , ( ( jhi , [ 'leftStickVert' ] ) , ( offset_position , [ position_step ] ) , "increase position" ) , ( ( jlo , [ 'rightStickVert' ] ) , ( offset_holding , [ - force_step ] ) , "decrease holding force" ) , ( ( jhi , [ 'rightStickVert' ] ) , ( offset_holding , [ force_step ] ) , "increase holding force" ) , ( ( bdn , [ 'function1' ] ) , ( print_help , [ bindings_list ] ) , "help" ) , ( ( bdn , [ 'function2' ] ) , ( print_help , [ bindings_list ] ) , "help" ) , ) bindings_list . append ( bindings ) rospy . loginfo ( "Enabling robot..." ) rs . enable ( ) rate = rospy . Rate ( 100 ) print_help ( bindings_list ) print ( "Press <Start> button for help; Ctrl-C to stop..." ) while not rospy . is_shutdown ( ) : for ( test , cmd , doc ) in bindings : if test [ 0 ] ( * test [ 1 ] ) : cmd [ 0 ] ( * cmd [ 1 ] ) print ( doc ) rate . sleep ( ) rospy . signal_shutdown ( "Example finished." )
maps joystick input to gripper commands
maps joystick input to gripper commands
"""
    maps joystick input to gripper commands

    @param joystick: an instance of a Joystick
    """ # decrease position dead_zone # abbreviations #(test, command, description) # test each joystick condition and call binding cmd if true
joystick
an instance of a Joystick
an instance of a Joystick
limb