def build(side=None): pymelLogger.debug('Starting: build()...') if side == None: raise Exception('Make sure side: %s is valid ' % side) if side != Names.prefixes['left'] and side != Names.prefixes['right']: raise Exception('Make sure side: %s is valid ' % side) # create hand jnt handJntList = _createHandJnt(side) # [handJnt, handJntName] handJnt = handJntList[0] handJntSH = handJntList[1] # create hand switch ctrl = handJntSH + '_' + Names.suffixes['switch'] hand_switch_offset = Control.create(name=ctrl, offsets=1, shape='cube', size=[1, 1, 1], color=_getSideColor(side), pos=None, parent=handJnt, typ='body') hand_switch_offset.setParent(world=1) hand_switch = hand_switch_offset.getChildren()[ 0] # it will work only with one offset hideLockAttr(hand_switch, lockHideTRSV) # add switch attr pm.addAttr(hand_switch, longName=Names.switchIkFk, k=True, min=0, max=1) # parentConstraint switch offset to sh handJnt !!!! Make sure it will work pm.parentConstraint(handJntSH, hand_switch_offset, mo=True) # build fingers Finger.build(side=side, label='Fingers', control=hand_switch, parentJnt=handJnt, curl='Z', twist='X', spread='Y', fkNormal=(1.0, 0.0, 0.0), radius=0.3) # group switch and hand hand_grp = pm.group(hand_switch_offset, handJnt, name=handJntSH + '_' + Names.suffixes['group']) _cleanUp(hand_grp) pymelLogger.debug('End: build()...')
def build( side=None ): pymelLogger.debug('Starting: build()...') if side == None: raise Exception('Make sure side: %s is valid '%side) if side != Names.prefixes['left'] and side != Names.prefixes['right']: raise Exception('Make sure side: %s is valid '%side) # create hand jnt handJntList = _createHandJnt( side ) # [handJnt, handJntName] handJnt = handJntList[0] handJntSH = handJntList[1] # create hand switch ctrl = handJntSH + '_' + Names.suffixes['switch'] hand_switch_offset = Control.create( name= ctrl , offsets=1, shape='cube', size=[1,1,1], color=_getSideColor(side), pos=None, parent=handJnt, typ='body' ) hand_switch_offset.setParent( world=1 ) hand_switch = hand_switch_offset.getChildren()[0] # it will work only with one offset hideLockAttr(hand_switch, lockHideTRSV) # add switch attr pm.addAttr( hand_switch, longName= Names.switchIkFk, k=True, min=0, max=1 ) # parentConstraint switch offset to sh handJnt !!!! Make sure it will work pm.parentConstraint(handJntSH, hand_switch_offset, mo=True) # build fingers Finger.build( side=side, label='Fingers', control=hand_switch, parentJnt = handJnt, curl='Z',twist='X',spread='Y', fkNormal=(1.0, 0.0, 0.0), radius=0.3 ) # group switch and hand hand_grp = pm.group(hand_switch_offset,handJnt,name = handJntSH + '_' + Names.suffixes['group']) _cleanUp( hand_grp ) pymelLogger.debug('End: build()...')
#-- Abrir el puerto serie. Si hay algun error se termina #-------------------------------------------------------- try: s = serial.Serial(serial_name, 115200) #-- Timeout: 100 ms s.timeout=0.1; except serial.SerialException: #-- Error al abrir el puerto serie sys.stderr.write("Error opening the port {0}".format(serial_name)) sys.exit(1) #-- Mostrar el nombre del dispositivo print "Puerto serie abierto: {0}\n".format(s.name) #-- Create the servos to use #s1 = Servo(s, 2) #s2 = Servo(s, 4) f1 = Finger(s, 2, up = 68, down = 76) f2 = Finger(s, 4, up = 65, down = 74) #-- Put the fingers in the up position f1.up() f2.up()
def move_list(data): move_list = [] curr_move = Move() curr_frame = Frame() last_frameid = None for row in range(0, len(data)): if (data[row]): #Each row represents a finger in a frame curr_finger = Finger(data[row]) #Handle the first entry if (row == 0): curr_frame.id = curr_finger.frame curr_frame.Fingers.append(curr_finger) curr_frame.numFingers += 1 else: #A new frame has begun if (curr_frame.id != curr_finger.frame): #Check if the old frame was still or stopped (i.e. fingers lifted off) #and if so, end the last move and add it to the list of moves. if (curr_frame.is_still()) or (curr_frame.is_stopped()): #We don't care about collecting still-frame data so just disregard it #but end the move accordingly. #We know the current move has ended so added it to the list of moves #but only if there are frames in it, this is to mitigate the fact that #WHENEVER there is a still frame a new Move obj is created, but #we don't care about these. if (curr_move.Framelist): curr_move.endAngle = curr_frame.Fingers[ 0].angle #Only looks at one finger curr_move.endXVel = curr_frame.Fingers[ 0].xvel #Only looks at one finger move_list.append(curr_move) curr_move = Move() #The last frame was neither still nor stopped, but we need to add it #to the current move. else: if (not curr_move.Framelist): curr_move.startAngle = curr_frame.Fingers[ 0].angle #Not actually accurate e.g. it only looks at one finger curr_move.startXVel = curr_frame.Fingers[ 0].xvel #Not accurate, see above. curr_move.Framelist.append(curr_frame) if (curr_frame.numFingers > curr_move.maxFingers): curr_move.maxFingers = curr_frame.numFingers if (curr_frame.numFingers < curr_move.minFingers): curr_move.minFingers = curr_frame.numFingers #Update the current frame curr_frame = Frame() curr_frame.id = curr_finger.frame curr_frame.Fingers.append(curr_finger) curr_frame.numFingers += 1 #A new frame has not begun but there are more fingers to add to it. else: curr_frame.Fingers.append(curr_finger) curr_frame.numFingers += 1 if (curr_move.Framelist): curr_move.endAngle = curr_frame.Fingers[ 0].angle #Only looks at one finger curr_move.endXVel = curr_frame.Fingers[ 0].xvel #Only looks at one finger move_list.append(curr_move) return move_list
#print "Puerto serie: {0}".format(serial_name) #-- Open the serial port #-------------------------------------------------------- #-- Abrir el puerto serie. Si hay algun error se termina #-------------------------------------------------------- try: s = serial.Serial(serial_name, 115200) #-- Timeout: 100 ms s.timeout = 0.1 except serial.SerialException: #-- Error al abrir el puerto serie sys.stderr.write("Error opening the port {0}".format(serial_name)) sys.exit(1) #-- Mostrar el nombre del dispositivo print "Puerto serie abierto: {0}\n".format(s.name) #-- Create the servos to use #s1 = Servo(s, 2) #s2 = Servo(s, 4) f1 = Finger(s, 2, up=68, down=76) f2 = Finger(s, 4, up=65, down=74) #-- Put the fingers in the up position f1.up() f2.up()
def main(): # Add epilog __epilog = "For suggestions use <" + __email__ + ">" # Set program name __program = "FingerPrint" # Set description __description = "Olimex finger sensor demo" parser = argparse.ArgumentParser(description=__description, epilog=__epilog, prog=__program) # Register common arguments parser.add_argument("-p", "--port", action="store", required=True, help="Communication port to use") parser.add_argument("--baudrate", action="store", type=int, default=57600, help="Set communication speed. Default: 57600") parser.add_argument("--settings", action="store_true", help="Read current sensor settings") parser.add_argument("-v", "--verbose", action="store_true", help="Enables verbose output") parser.add_argument("--version", action="version", version="%(prog)s 0.1.0", help="Print program version") # Models group models_group = parser.add_argument_group( "Models", "Arguments for models usage").add_mutually_exclusive_group() models_group.add_argument("--list-models", action="store", type=int, choices=[0, 1, 2, 3], help="Print the usage of model pages") models_group.add_argument("--model-store", action="store", type=int, nargs=2, metavar=("BUFFER", "PAGE"), help="Transfer model from buffer# to page#") models_group.add_argument( "--model-delete", action="store", type=int, nargs=2, metavar=("START", "COUNT"), help="Delete models in the database at START to START+COUNT") models_group.add_argument("--model-load", action="store", type=int, nargs=2, metavar=("BUFFER", "PAGE"), help="Load model at #PAGE into #BUFFER") models_group.add_argument( "--model-upload", action="store", nargs=2, metavar=("BUFFER", "FILE"), help="Transfer the content of #BUFFER to #FILE on the host computer") models_group.add_argument("--model-download", action="store", nargs=2, metavar=("BUFFER", "FILE"), help="Transfer the content of #FILE to #BUFFER") models_group.add_argument("--model-generate", action="store_true", help="Generate fingerprint image") models_group.add_argument( "--model-chars", action="store", type=int, choices=[1, 2], metavar="BUFFER", help= "Generate characteristics from the image in the ImageBuffer and store it in #BUFFER" ) models_group.add_argument( "--model-match", action="store_true", help="Compare models in charBuffer1 and charBuffer2 and look for match" ) models_group.add_argument( "--model-search", action="store", type=int, nargs=3, metavar=("BUFFER", "START", "COUNT"), help="Search the database for match to the model stored in #BUFFER") models_group.add_argument("--models-count", action="store_true", help="Print current models count") models_group.add_argument( "--model-register", action="store_true", help="Compare CharBuffer1 with CharBuffer2 and creates model") models_group.add_argument("--empty", action="store_true", help="Empty model database") # Register common argument group sensor_group = parser.add_argument_group("Sensor", "Sensor configuration") sensor_group.add_argument( "--set-baud", action="store", type=int, choices=[ 9600, 19200, 28800, 38400, 48000, 57600, 67200, 76800, 86400, 96000, 115200 ], help="Set new speed for the sensor. Range 9600 to 115200") sensor_group.add_argument("--set-security", action="store", type=int, choices=[1, 2, 3, 4, 5], help="Set security level.") sensor_group.add_argument("--set-packet", action="store", type=int, choices=[32, 64, 128, 256], help="Set the length of data packet in bytes") sensor_group.add_argument("--password", action="store", type=parser_hex, default=0x00000000, help="Sensor password. Default: 0x00000000") sensor_group.add_argument("--address", action="store", type=parser_hex, default=0xFFFFFFFF, help="Sensor address. Default: 0xffffffff") # Register argument group image_group = parser.add_argument_group( "Fingerprint image", "Actions with ImageBuffer").add_mutually_exclusive_group() image_group.add_argument( "--image-upload", action="store", metavar="FILE", help="Upload fingerprint image from sensor to host PC") # Parse arguments args = parser.parse_args() # Configure logging if args.verbose: logging.basicConfig(format="%(message)s", level=logging.DEBUG) else: logging.basicConfig(format="%(message)s", level=logging.INFO) # Start communication with the sensor sensor = Finger.System(args.port, baud=args.baudrate, password=args.password, address=args.address) model = Finger.Models(args.port, baud=args.baudrate, password=args.password, address=args.address) image = Finger.Image(args.port, baud=args.baudrate, password=args.password, address=args.address) # Check is there is someone logging.debug("Connecting with sensor") logging.debug("----------------------") if sensor.verify_password(): return 1 else: logging.debug("Response: OK") # Check if settings flag is set if args.settings: logging.debug("\nReading settings") logging.debug("----------------") sensor.read_system_params() return 0 # Check for command if args.set_baud: logging.debug("\nSetting baudrate to %d" % args.set_baud) logging.debug("------------------------------") if sensor.set_baudrate(args.set_baud): return 1 else: logging.debug("Response: OK") if args.set_security: logging.debug("\nSetting security to %d" % args.set_security) logging.debug("------------------------------") if sensor.set_security(args.set_security): return 1 else: logging.debug("Response: OK") if args.set_packet: logging.debug("\nSetting packet length to %d" % args.set_packet) logging.debug("------------------------------") if sensor.set_packet(args.set_packet): return 1 else: logging.debug("Response: OK") if args.list_models is not None: model.get_storage_table(args.list_models) if args.models_count: model.get_model_count() if args.model_store is not None: model.store_model(args.model_store[0], args.model_store[1]) if args.model_delete is not None: model.delete_model(args.model_delete[0], args.model_delete[1]) if args.model_load is not None: model.load_model(args.model_load[0], args.model_load[1]) if args.model_upload is not None: sensor.read_system_params() model.upload_model(args.model_upload[0], args.model_upload[1]) if args.model_download is not None: sensor.read_system_params() model.download_model(args.model_download[0], args.model_download[1]) if args.model_generate: model.generate_model() if args.model_chars is not None: model.generate_characteristics(args.model_chars) if args.model_match: model.match_model() if args.model_search is not None: model.search_model(args.model_search[0], args.model_search[1], args.model_search[2]) if args.image_upload is not None: sensor.read_system_params() image.upload_image(args.image_upload[0]) if args.empty: model.empty_database()