昇腾社区首页
中文
注册

机械臂控制逻辑入口

“dofbot_color_stacking/scripts/main.py”“dofbot_garbage_yolov5/dofbot_garbage_yolov5/main.py”均为机械臂的运行控制入口,启动后调用各个功能包模块代码,实现机械臂的分拣与堆叠。核心代码片段示例如下。

# 当摄像头正常打开的情况下循环执行
while capture.isOpened():

    # 读取相机的每一帧
    ret, img = capture.read()
    print("read image from camera successfully:", ret)
    # 统一图像大小
    img = cv.resize(img, (640, 480))

    dp = np.fromfile(dp_cfg_path, dtype=np.int32)
    if DP_PRINT:
        print("dp has dtype:", dp.dtype)
        print("dp has shape:", dp.shape)
    dp = dp.reshape(4,2)
    if DP_PRINT:
        print("After reshape, dp has shape:", dp.shape)
        print("dp now is:", dp)

    img = calibration.Perspective_transform(dp, img)

    img, msg = target.garbage_run(img)
    print("Model is warming up at stage:", warm_up_count)
    if warm_up_count != 0 and last_num == warm_up_count:
        last_count += 1
        if last_count > 5:
            warm_up_count = 0
            last_count = 0
    last_num = warm_up_count