How to use pypot - 10 common examples

To help you get started, we’ve selected a few pypot examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github poppy-project / pypot / samples / test_connection.py View on Github external
end = time.time()
        t.append(1000 * (end - start))

    print '\tTook {}ms (STD={}) per read'.format(numpy.mean(t), numpy.std(t))
    print


def full_test(dxl, ids):
    print 'Testing the communication speed with motor{} {}'.format('s' if len(ids) else '',
                                                                   ids)
    read_register(dxl, 'present_position', ids)
    read_register(dxl, 'control_table', ids)


if __name__ == '__main__':
    available_ports = pypot.dynamixel.get_available_ports()

    parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter,
                                     description='Test low-level communication with Dynamixel motors.')

    parser.add_argument('-p', '--ports',
                        type=str, nargs='+',
                        default=available_ports,
                        help='Select which port(s) to test')

    parser.add_argument('-b', '--baudrate',
                        type=int, choices=[57600, 1000000], default=1000000,
                        help='Sets the baudrate')

    args = parser.parse_args()

    for port in args.ports:
github poppy-project / pypot / tests / test_dummy.py View on Github external
import unittest

from pypot.creatures import PoppyErgoJr
from pypot.primitive import LoopPrimitive


class EmptyPrim(LoopPrimitive):
    def setup(self):
        pass

    def update(self):
        pass

    def teardown(self):
        pass


class TestDummy(unittest.TestCase):
    def setUp(self):
        self.jr = PoppyErgoJr(simulator='dummy')

    def test_dummy_controller(self):
        for m in self.jr.motors:
github poppy-project / pypot / tests / test_primitive.py View on Github external
def test_set_once(self):
        class Switcher(LoopPrimitive):
            def setup(self):
                self.current_state = False
                self.old_state = self.current_state

            def update(self):
                if self.current_state != self.old_state:
                    for m in self.robot.motors:
                        self.affect_once(m, 'led',
                                         'red' if self.current_state else 'off')

                    self.old_state = self.current_state

        p = Switcher(self.jr, 10)
        p.start()

        for m in self.jr.motors:
github poppy-project / pypot / pypot / creatures / configure_utility.py View on Github external
parser.add_argument('robot', type=str, choices=robots,
                        help='Robot used.')

    parser.add_argument('motor', type=str,
                        help='Name of the motor to configure.')

    args = parser.parse_args()

    RobotCls = installed_poppy_creatures['poppy-{}'.format(args.robot)]
    c = RobotCls.default_config

    if args.motor not in c['motors']:
        print('"{}" is not a motor of "{}"! '
              'possibilities={}'.format(args.motor, args.robot,
                                        sorted(c['motors'].keys())))
        print('Exiting now...')
        sys.exit(1)

    motor_config = c['motors'][args.motor]

    args = [
        '--id', motor_config['id'],
        '--type', motor_config['type'],
        '--port', find_port_for_motor(c, args.motor),
        '--return-delay-time', 0
    ]
    
    if 'wheel_mode' in motor_config.keys():
        args.extend(('--wheel-mode', motor_config['wheel_mode']))
    else:
        args.extend(('--angle-limit',motor_config['angle_limit'][0],motor_config['angle_limit'][1],
                     '--goto-zero'))
github poppy-project / pypot / pypot / creatures / services_launcher.py View on Github external
def start_poppy_with_services(args):
    params = poppy_params_from_args(args)

    for i in range(5):
        try:
            print('Attempt {} to start the robot...'.format(i + 1))
            return installed_poppy_creatures[args.creature](**params)

        except Exception as e:
            # In case of failure,
            # Give the robot some time to statup, reboot...
            time.sleep(random.random())
            print(e)
    else:
        print('Could not start up the robot...')
        sys.exit(1)
github poppy-project / pypot / pypot / tools / dxlconfig.py View on Github external
with Dxl320IO(args.port, baudrate=1000000, timeout=0.01) as io:
            io.factory_reset(ids=range(253))
    print('Done!')

    factory_baudrate = 57600 if args.type.startswith('MX') else 1000000

    # Wait for the motor to "reboot..."
    for _ in range(10):
        with DxlIOPort(args.port, baudrate=factory_baudrate) as io:
            if io.ping(1):
                break

            time.sleep(.5)
    else:
        print('Could not communicate with the motor...')
        print('Make sure one (and only one) is connected and try again')
        sys.exit(1)

    # Switch to 1M bauds
    if args.type.startswith('MX') or args.type.startswith('SR'):
        print('Changing to 1M bauds...')
        with DxlIO(args.port, baudrate=factory_baudrate) as io:
            io.change_baudrate({1: 1000000})

        time.sleep(.5)
        print('Done!')

    # Change id
    print('Changing id to {}...'.format(args.id))
    if args.id != 1:
        with DxlIOPort(args.port) as io:
            io.change_id({1: args.id})
github poppy-project / pypot / pypot / creatures / services_launcher.py View on Github external
print('No installed poppy creature were found!')
        print('You should first install the python package '
              'corresponding to your robot or check your python environment.')
        sys.exit(1)

    args = parser.parse_args()

    # If no creature are specified and only one is installed
    # We use it as default.
    if args.creature is None:
        if nb_creatures > 1:
            parser.print_help()
            sys.exit(1)

        args.creature = installed_poppy_creatures.keys()[0]
        print('No creature specified, use {}'.format(args.creature))

    if args.log_file:
        fh = logging.FileHandler(args.log_file)
        fh.setLevel(logging.DEBUG)
        formatter = logging.Formatter(
            '%(asctime)s - %(name)s - %(levelname)s - %(message)s')
        fh.setFormatter(formatter)
        logging.getLogger('').addHandler(fh)

    if args.verbose:
        args.snap_quiet = False
        args.http_quiet = False
        args.ws_quiet = False

        if args.verbose == 1:
            lvl = logging.WARNING
github poppy-project / pypot / pypot / creatures / services_launcher.py View on Github external
elif args.verbose > 2:
            lvl = logging.DEBUG

        if args.log_file is not None:
            ch = logging.FileHandler(args.log_file)
        else:
            ch = logging.StreamHandler()

        ch.setLevel(lvl)
        formatter = logging.Formatter(
            '%(name)-12s: %(levelname)-8s %(message)s')
        ch.setFormatter(formatter)
        logging.getLogger('').addHandler(ch)

    if not any([args.snap, args.http, args.remote, args.poppy_simu, args.ws, args.dummy]):
        print('No service specified! See --help for details.')
        sys.exit(1)

    static_server_started = False
    if args.snap and not args.no_browser:     
        snap_static_port = 8888
        snap_static_server = HTTPServer(("0.0.0.0", snap_static_port), SimpleHTTPRequestHandler)

        os.chdir(os.path.join(os.path.dirname(__file__), "..", "snap"))
        snap_static_server_process = Process(target=snap_static_server.serve_forever, args=())
        static_server_started = True
        snap_static_server_process.start()

        snap_url = 'http://127.0.0.1:{}/snap.html'.format(snap_static_port)
        block_url = 'http://{}:{}/snap-blocks.xml'.format(
            find_local_ip(), args.snap_port)
        url = '{}#open:{}'.format(snap_url, block_url)
github poppy-project / pypot / pypot / creatures / services_launcher.py View on Github external
def start_poppy_with_services(args):
    params = poppy_params_from_args(args)

    for i in range(5):
        try:
            print('Attempt {} to start the robot...'.format(i + 1))
            return installed_poppy_creatures[args.creature](**params)

        except Exception as e:
            # In case of failure,
            # Give the robot some time to statup, reboot...
            time.sleep(random.random())
            print(e)
    else:
        print('Could not start up the robot...')
        sys.exit(1)
github poppy-project / pypot / pypot / tools / dxlconfig.py View on Github external
def check(pred, msg):
    if not pred:
        print(msg)
        print('Exiting now...')
        sys.exit(1)