示例#1
0
文件: dmxl_scan.py 项目: pobot/PyBot
def main(args):
    if args.verbose:
        print(
'''accessing bus interface:
  - port     : %s
  - baudrate : %d
  - timeout  : %.3f s''' % (args.port, args.baudrate, args.timeout))

    try:
        intf = dmxl.DynamixelBusInterface(
                port=args.port, 
                baudrate=args.baudrate,
                timeout=args.timeout
                )
    except Exception as e: 
        cli.die(e)
    
    print('Scanning bus on %s from id=%d to id=%d...' % (args.port,
        args.from_id, args.to_id))
    ids = intf.scan(args.from_id, args.to_id)
    if ids:
        print ('%d servo(s) found with id(s) : %s' % 
            (len(ids), ', '.join([str(_id) for _id in ids]))
        )
    
    else:
        print('No servo found.')
    
    return 0
示例#2
0
文件: dmxl_regs.py 项目: pobot/PyBot
def main(args): #pylint: disable=W0621
    # process the 'list registers' action which invovles no equipment
    if args.list:
        list_registers()
        return

    try:
        intf = dmxl.DynamixelBusInterface(
            port=args.port,
            baudrate=args.baudrate,
            timeout=args.timeout,
            debug=args.debug
        )
    except Exception as e:  #pylint: disable=W0703
        cli.die(e)

    if args.intf or intf.ping(args.id):

        if args.intf:
            print('Interface register(s) :')
        else:
            print('Servo id=%s register(s) :' % args.id)

        if args.readall:
            # we want to display all registers
            intf.dump_regs(args.id)
        elif args.read != None:
            # we want to read a specific register
            display_register(intf, args.id, args.read)
        elif args.write:
            # we want to write to a specific register
            reg, value =  WriteStatement.parse(args.write)
            if reg == dmxl.Register.Id:
                print( '''
Warning : Writing to register 0x%0.2x will change the servo id.
        Use dmxl_setid.py script for doing this in a secure way.
                        ''' % dmxl.Register.Id
                )
                return
            write_register(intf, args.id, reg, value)
            display_register(intf, args.id, reg)

    else:
        cli.print_err('no servo found with id=%d' % args.id)
示例#3
0
文件: dmxl_setid.py 项目: pobot/PyBot
def main(args):
    try:
        intf = dmxl.DynamixelBusInterface(port=args.port,
                baudrate=args.baudrate, timeout=args.timeout)
    except Exception as e:
        cli.die(e)
    
    if not args.force:
        print('Scanning bus on %s to find connected servos...' % args.port)
        nb_servos = len(intf.scan())

        if nb_servos == 0:
            cli.print_err('no servo found on the bus')
            return 1
            
        if nb_servos > 1:
            cli.print_err('only ONE servo must be connected to the bus (%d servos found)' % nb_servos)
            return 1
        
    intf.write_register(dmxl.DynamixelBusInterface.BROADCASTING_ID, dmxl.Register.Id, args.newid)
    print("Servo id changed to %d." % args.newid)
    return 0
示例#4
0
                        default=300,
                        dest='scan_off_delay'
                        )
    parser.add_argument('--laser_off_delay',
                        help='delay of lasers auto off (secs)',
                        type=int,
                        default=30,
                        dest='laser_off_delay'
                        )

    cli_args = parser.parse_args()

    try:
        _ctrl = BeaconsController(cli_args)
    except Exception as e: #pylint: disable=W0703
        cli.die(e)
    else:
        # Publish the service with Avahi
        svc = avahi_utils.AvahiService(
            svc_name='beacons',
            svc_type='pobot_demo',
            svc_port=cli_args.control_port
        )
        try:
            # starts the beacons controller
            signal.signal(signal.SIGTERM, sigterm_handler)
            svc.publish()
            _ctrl.run()

        finally:
            svc.unpublish()
示例#5
0
    parser.add_argument('-T', '--trace',
                        help="""Trace the communications with the Create and set the display format
                        ('d' = decimal, 'h' = hex)""",
                        choices=['d', 'h'],
                        dest='trace',
                        default=None
                        )

    _args = parser.parse_args()

    demo_name = _args.demo[0]
    if demo_name == '?':
        wrapper = textwrap.TextWrapper(initial_indent='  | ', subsequent_indent='  | ')
        print("%s available demos :\n" % parser.prog)
        for _name, _doc in _all_demos.iteritems():
            txt = '\n'.join(l.strip() for l in _doc.split('\n'))
            print('- %s :\n%s\n' % (_name, wrapper.fill(txt)))
        sys.exit(0)

    try:
        demo = Demo(demo_name, _args)
        demo.run()

    except ValueError as e: #pylint: disable=W0703
        cli.die('demo error : %s' % e)

    except:
        cli.die(traceback.format_exc())