Beispiel #1
0
def _load_tree(logger):
    tree = None

    cached_tree_path = cache_path('arm_movement_engine.kdtree')
    try:
        with open(cached_tree_path, 'rb') as f:
            logger.info("Attemptimg to load kd-tree from cache...")
            tree = pickle.load(f)
            logger.info("Successfully loaded kd-tree from cache.")
    except (OSError, IOError):
        logger.info("Failed to load kd-tree from {}".format(cached_tree_path))

    if tree is None:
        try:
            pts_path = opt_path('arm_movement_engine_pts.npy')
            logger.info("Loading {}...".format(pts_path))
            with open(pts_path, 'rb') as f:
                pts = np.load(f)
                logger.info("Building kd-tree...")
                tree = KDTree(pts)
                logger.info("Done building kd-tree.")
                needs_to_write_cache = True
        except IOError:
            raise RaspberryTurkError("Arm movement engine can't find required file: {}".format(pts_path))
        else:
            try:
                with open(cached_tree_path, 'wb') as f:
                    logger.info("Writing kd-tree to cache...")
                    pickle.dump(tree, f)
                    logger.info("Done writing kd-tree to cache.")
            except (OSError, IOError) as e:
                logger.warn("Failed to write kdtree to {}. Reason: {}.".format(cached_tree_path, e))

    return tree
def get_chessboard_perspective_transform():
    try:
        M = np.load(_chessboard_perspective_transform_path())
        return M
    except IOError:
        raise RaspberryTurkError(
            "No chessboard perspective transform found. Camera position recalibration required."
        )
Beispiel #3
0
def _load_svc(logger):
    try:
        svc_path = opt_path('square_color_detector.svc')
        logger.info("Loading {}...".format(svc_path))
        with open(svc_path, 'rb') as f:
            svc = pickle.load(f)
        pca_path = opt_path('square_color_detector.pca')
        logger.info("Loading {}...".format(pca_path))
        with open(pca_path, 'rb') as f:
            pca = pickle.load(f)
        _convert_to_32bit_pca(pca)
        return svc, pca
    except IOError as e:
        raise RaspberryTurkError("Square color detector can't find required file: {}".format(e.filename))
Beispiel #4
0
def main():
    setup_console_logging()
    args = _get_args()
    logger = logging.getLogger(__name__)
    sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
    logger.info("connecting to {}".format(SERVER_ADDRESS))
    try:
        sock.connect(SERVER_ADDRESS)
    except socket.error as msg:
        logger.error(msg)
        raise RaspberryTurkError(
            "There was a problem connecting to {}".format(SERVER_ADDRESS))
    try:
        message = args.move
        logger.info("sending {}".format(message))
        sock.sendall(message)
        data = sock.recv(19)
        logger.info(data)
    finally:
        logger.info("closing socket")
        sock.close()
Beispiel #5
0
from raspberryturk import is_running_on_raspberryturk, RaspberryTurkError

if not is_running_on_raspberryturk():
    raise RaspberryTurkError(
        "Must be running on Raspberry Turk to use {} module.".format(__name__))