How to use the pypot.dynamixel function in pypot

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 / samples / motor-sinus.py View on Github external
import pypot.dynamixel



timeout = 1

if __name__ == '__main__':
    ports = pypot.dynamixel.get_available_ports()
    if not ports:
        print 'No port found :-('
        sys.exit(1)

    port = ports[0]
    print 'Try to connect on ', port
    dxl_io = pypot.dynamixel.DynamixelIO(port, timeout=timeout)
    
    print 'Connexion established :', dxl_io
    
    motor_ids = dxl_io.scan(range(25))
    print len(motor_ids), 'motors found:', motor_ids
    
    print 'Model'
    print [dxl_io.get_model(mid) for mid in motor_ids]
    
    print 'Return delay time'
    print [dxl_io.get_return_delay_time(mid) for mid in motor_ids]
    
    
    print 'Setting the position of all motors to the origin'
    origin = 150.0
    dxl_io.set_sync_positions(zip(motor_ids, [origin] * len(motor_ids)))
github poppy-project / pypot / pypot / robot / config.py View on Github external
port = pypot.dynamixel.find_port(ids, strict)
        logger.info('Found port {} for ids {}'.format(port, ids))

    sync_read = c_params['sync_read']

    if sync_read == 'auto':
        # USB Vendor Product ID "VID:PID=0403:6001" for USB2Dynamixel
        # USB Vendor Product ID "VID:PID=16d0:06a7" for USBAX
        vendor_pid = pypot.dynamixel.get_port_vendor_info(port)
        sync_read = ('PID=0403:6001' in vendor_pid and c_params['protocol'] == 2 or
                     'PID=16d0:06a7' in vendor_pid)
        logger.info('sync_read is {}. Vendor pid = {}'.format(sync_read, vendor_pid))

    handler = pypot.dynamixel.error.BaseErrorHandler

    DxlIOCls = (pypot.dynamixel.io.Dxl320IO
                if 'protocol' in c_params and c_params['protocol'] == 2
                else pypot.dynamixel.io.DxlIO)

    dxl_io = DxlIOCls(port=port,
                      use_sync_read=sync_read,
                      error_handler_cls=handler)

    try:
        found_ids = dxl_io.scan(ids)
    except pypot.dynamixel.io.DxlError:
        dxl_io.close()
        found_ids = []

    if ids != found_ids:
        missing_ids = tuple(set(ids) - set(found_ids))
        msg = 'Could not find the motors {} on bus {}.'.format(missing_ids,
github poppy-project / pypot / pypot / config / xmlparser.py View on Github external
def _handle_motor(motor_node):
    """ Parses the  and returns a :py:class:`~pypot.dynamixel.DynamixelMotor`. """
    motor_name = motor_node.getAttribute("name")
    motor_id = int(motor_node.getAttribute("id"))
    motor_type = motor_node.getAttribute("type")
    motor_orientation = motor_node.getAttribute("orientation")
    motor_is_direct = True if motor_orientation == "direct" else False
    motor_offset = float(motor_node.getAttribute("offset"))
    
    custom_eeprom = _handle_eeprom(motor_node)
    
    motor = pypot.dynamixel.DynamixelMotor(motor_id, motor_name, motor_type,
                                           motor_is_direct, motor_offset,
                                           **custom_eeprom)

    return motor
github poppy-project / pypot / pypot / config / xmlparser.py View on Github external
def _handle_controller(controller_node):
    """ Parses the  element and returns a :py:class`~pypot.dynamixel.DynamixelController`.  """
    controller_type = controller_node.getAttribute("type")
    controller_port = controller_node.getAttribute("port")

    alarm_node = controller_node.getElementsByTagName("AlarmBlackList")[0]
    alarms = map(lambda node: node.tagName,
                 filter(lambda child: child.nodeType == alarm_node.ELEMENT_NODE, alarm_node.childNodes))
    
    motor_nodes = controller_node.getElementsByTagName("DynamixelMotor")
    motors = [_handle_motor(m) for m in motor_nodes]
    
    controller = pypot.dynamixel.DynamixelController(controller_port, controller_type, motors,
                                                     blacklisted_alarms=alarms)
    
    sync_nodes = controller_node.getElementsByTagName("Loop")
    loops = [_handle_sync_loop(l) for l in sync_nodes]
    [controller.add_sync_loop(*l) for l in loops]
    
    return controller
github poppy-project / pypot / pypot / robot / config.py View on Github external
if [m for m in attached_motors if m._broken]:
            strict = False

        attached_ids = [m.id for m in attached_motors]
        if not use_dummy_io:
            dxl_io = dxl_io_from_confignode(config, c_params, attached_ids, strict)

            check_motor_eprom_configuration(config, dxl_io, motor_names)

            logger.info('Instantiating controller on %s with motors %s',
                        dxl_io.port, motor_names,
                        extra={'config': config})

            syncloop = (c_params['syncloop'] if 'syncloop' in c_params
                        else 'BaseDxlController')
            SyncLoopCls = getattr(pypot.dynamixel.syncloop, syncloop)

            c = SyncLoopCls(dxl_io, attached_motors)
            controllers.append(c)
        else:
            controllers.append(DummyController(attached_motors))

    try:
        robot = Robot(motor_controllers=controllers, sync=sync)
    except RuntimeError:
        for c in controllers:
            c.io.close()

        raise

    make_alias(config, robot)