Пример #1
0
            return v
        else:
            raise argparse.ArgumentTypeError('must be in range [0..7]')

if __name__ == '__main__':
    CFG_FILE_NAME = os.path.splitext(os.path.basename(__file__))[0] + '.cfg'
    dflt_search_path = [
        '/etc/' + CFG_FILE_NAME,
        os.path.expanduser('~/.' + CFG_FILE_NAME)
    ]

    cfg = simpleconfig.parse(files=dflt_search_path, defaults={
        'port' : dspin.RASPI_SPI_DEVICE,
        'max_speed' : 1000,
        'step_mode' : 7,
        'resolution' : 400,
        'stdby_gpio' : 24,
        'cs_gpio' : 26,
        'not_busy_gpio' : 22
    })

    parser = cli.get_argument_parser(
        description="Demonstration of controlling a stepper motor with a dSPIN chip via SPI."
    )
    parser.add_argument('-R', '--resolution',
                        help="Stepper motor resolution (steps/turn)",
                        dest='resolution',
                        type=int,
                        default=cfg['resolution']
                        )
    parser.add_argument('-M', '--max-speed',
Пример #2
0
            ('B', 3, 11),
            ('C', 4, 11),
            ('A', 3, 33),
        ])
        sequence = robot.song_sequence_record(0, s.score)
        robot.song_sequence_play(sequence)


if __name__ == '__main__':
    dflt_search_path = [
        '/etc/demo-create.cfg',
        os.path.expanduser('~/.demo-create.cfg')
    ]

    cfg = simpleconfig.parse(files=dflt_search_path, defaults={
        'port' : '/dev/ttyUSB0'
    })

    parser = cli.get_argument_parser(
        description="Demonstration of controlling a iRobot Create robot with Python scripts."
    )
    parser.add_argument(dest='demo',
                        metavar='DEMO_NAME',
                        choices=_all_demos.keys() + ['?'],
                        nargs=1,
                        help="demonstration selector. Use '?' for a detailed list"
                        )
    parser.add_argument('-p', '--port',
                        help="Create connection serial port",
                        dest='port',
                        default=cfg['port']