Skip to content

Commit

Permalink
Added check for dobot SDK installed
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianboguszewski committed Jan 23, 2025
1 parent 5592df4 commit 3b84876
Showing 1 changed file with 117 additions and 116 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -263,126 +263,127 @@
"cell_type": "code",
"execution_count": null,
"id": "a63a5943",
"metadata": {
"scrolled": false
},
"metadata": {},
"outputs": [],
"source": [
"# Dobot/general imports\n",
"# pylint: disable=wrong-import-order\n",
"import DobotDllType as dType\n",
"\n",
"CON_STR = {\n",
" dType.DobotConnect.DobotConnect_NoError: \"DobotConnect_NoError\",\n",
" dType.DobotConnect.DobotConnect_NotFound: \"DobotConnect_NotFound\",\n",
" dType.DobotConnect.DobotConnect_Occupied: \"DobotConnect_Occupied\",\n",
"}\n",
"\n",
"# Load Dll and get the CDLL object\n",
"api = dType.load()\n",
"\n",
"# Connect Dobot\n",
"state = dType.ConnectDobot(api, \"\", 115200)[0]\n",
"print(\"Connect status:\", CON_STR[state])\n",
"\n",
"use_popup = True # True\n",
"\n",
"if state == dType.DobotConnect.DobotConnect_NoError:\n",
" print(\n",
" \"[HOME] Restore to home position at first launch, please wait 30 seconds after turnning on the Dobot Magician.\",\n",
" )\n",
" print(\n",
" \"[BLOCKS] Place them besides the non-motor side of the conveyor belt,\"\n",
" \" the same side where the pick and place arm is.\",\n",
" )\n",
" print(\"[PLACING BLOCKS] Place the blocks by 3x3.\")\n",
" print(\"[CALIBRATION POINT] Looking from the back of Dobot, the top left block is the calibration point.\")\n",
" print(\"[CALIBRATION] Set the first variable to 0 to test the calibration point, then set 1 to start running.\")\n",
" print(\n",
" \"[DIRECTION] Standing behind Dobot Magician facing its front direction, X is front and back direction, \"\n",
" \"Y is left and right direction. \",\n",
" )\n",
" print(\"[CONNECTION] Motor of the conveyor belt connects to port Stepper1.\")\n",
"\n",
" Calibration__0__Run__1 = 1\n",
" Calibration_X = 221.2288\n",
" Calibration_Y = -117.0036\n",
" Calibration_Z = -42.3512\n",
" Place_X = 23.7489 # 42.2995 #\n",
" Place_Y = -264.2602 # -264.6927 #\n",
" Place_Z = 18.0862 # 63.65 #\n",
" Anomaly_X = -112 # -84.287 #\n",
" Anomaly_Y = -170 # -170.454 #\n",
" Anomaly_Z = 90 # 61.5359 #\n",
" dType.SetEndEffectorParamsEx(api, 59.7, 0, 0, 1)\n",
" j = 0\n",
" k = 0\n",
" dType.SetPTPJointParamsEx(api, 400, 400, 400, 400, 400, 400, 400, 400, 1)\n",
" dType.SetPTPCommonParamsEx(api, 100, 100, 1)\n",
" dType.SetPTPJumpParamsEx(api, 40, 100, 1)\n",
" dType.SetPTPCmdEx(api, 0, Calibration_X, Calibration_Y, Calibration_Z, 0, 1)\n",
" dType.SetEndEffectorSuctionCupEx(api, 0, 1)\n",
" STEP_PER_CRICLE = 360.0 / 1.8 * 10.0 * 16.0\n",
" MM_PER_CRICLE = 3.1415926535898 * 36.0\n",
" vel = float(0) * STEP_PER_CRICLE / MM_PER_CRICLE\n",
" dType.SetEMotorEx(api, 1, 0, int(vel), 1)\n",
"\n",
" if Calibration__0__Run__1:\n",
" for _ in range(9):\n",
" # initializing and starting multi-threaded webcam input stream\n",
" cam_stream = CameraStream(stream_id=0) # 0 id for main camera\n",
" cam_stream.start()\n",
"\n",
" dType.SetPTPCmdEx(api, 0, (Calibration_X - j), (Calibration_Y - k), (Calibration_Z - 10), 0, 1)\n",
" dType.SetEndEffectorSuctionCupEx(api, 1, 1)\n",
" dType.SetPTPCmdEx(api, 0, (Place_X - 0), (Place_Y - 0), (Place_Z + 90), 0, 1)\n",
"\n",
" # adding a delay for simulating video processing time\n",
" delay = 0.3 # delay value in seconds\n",
" time.sleep(delay)\n",
" # Capture a frame from the video player - start thread\n",
" frame = cam_stream.read()\n",
"\n",
" if acquisition:\n",
" # create filename to next frame\n",
" filename = create_filename(path=(dataset_path / folder))\n",
" cv2.imwrite(filename, frame)\n",
" dType.SetPTPCmdEx(api, 0, Place_X, Place_Y, Place_Z, 0, 1)\n",
"\n",
" else:\n",
" # Get the inference results.\n",
" frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)\n",
" # INFERENCE WITH OPENVINO\n",
" predictions = inferencer.predict(image=frame)\n",
" print(predictions.pred_score)\n",
" if predictions.pred_score > 0.48: # modify the threshold depending of your needs\n",
" dType.SetPTPCmdEx(api, 0, Anomaly_X, Anomaly_Y, Anomaly_Z, 0, 1) # define point for abnormalities\n",
" else:\n",
"try:\n",
" # Dobot/general imports\n",
" # pylint: disable=wrong-import-order\n",
" import DobotDllType as dType\n",
" \n",
" CON_STR = {\n",
" dType.DobotConnect.DobotConnect_NoError: \"DobotConnect_NoError\",\n",
" dType.DobotConnect.DobotConnect_NotFound: \"DobotConnect_NotFound\",\n",
" dType.DobotConnect.DobotConnect_Occupied: \"DobotConnect_Occupied\",\n",
" }\n",
" \n",
" # Load Dll and get the CDLL object\n",
" api = dType.load()\n",
" \n",
" # Connect Dobot\n",
" state = dType.ConnectDobot(api, \"\", 115200)[0]\n",
" print(\"Connect status:\", CON_STR[state])\n",
" \n",
" use_popup = True # True\n",
" \n",
" if state == dType.DobotConnect.DobotConnect_NoError:\n",
" print(\n",
" \"[HOME] Restore to home position at first launch, please wait 30 seconds after turnning on the Dobot Magician.\",\n",
" )\n",
" print(\n",
" \"[BLOCKS] Place them besides the non-motor side of the conveyor belt,\"\n",
" \" the same side where the pick and place arm is.\",\n",
" )\n",
" print(\"[PLACING BLOCKS] Place the blocks by 3x3.\")\n",
" print(\"[CALIBRATION POINT] Looking from the back of Dobot, the top left block is the calibration point.\")\n",
" print(\"[CALIBRATION] Set the first variable to 0 to test the calibration point, then set 1 to start running.\")\n",
" print(\n",
" \"[DIRECTION] Standing behind Dobot Magician facing its front direction, X is front and back direction, \"\n",
" \"Y is left and right direction. \",\n",
" )\n",
" print(\"[CONNECTION] Motor of the conveyor belt connects to port Stepper1.\")\n",
" \n",
" Calibration__0__Run__1 = 1\n",
" Calibration_X = 221.2288\n",
" Calibration_Y = -117.0036\n",
" Calibration_Z = -42.3512\n",
" Place_X = 23.7489 # 42.2995 #\n",
" Place_Y = -264.2602 # -264.6927 #\n",
" Place_Z = 18.0862 # 63.65 #\n",
" Anomaly_X = -112 # -84.287 #\n",
" Anomaly_Y = -170 # -170.454 #\n",
" Anomaly_Z = 90 # 61.5359 #\n",
" dType.SetEndEffectorParamsEx(api, 59.7, 0, 0, 1)\n",
" j = 0\n",
" k = 0\n",
" dType.SetPTPJointParamsEx(api, 400, 400, 400, 400, 400, 400, 400, 400, 1)\n",
" dType.SetPTPCommonParamsEx(api, 100, 100, 1)\n",
" dType.SetPTPJumpParamsEx(api, 40, 100, 1)\n",
" dType.SetPTPCmdEx(api, 0, Calibration_X, Calibration_Y, Calibration_Z, 0, 1)\n",
" dType.SetEndEffectorSuctionCupEx(api, 0, 1)\n",
" STEP_PER_CRICLE = 360.0 / 1.8 * 10.0 * 16.0\n",
" MM_PER_CRICLE = 3.1415926535898 * 36.0\n",
" vel = float(0) * STEP_PER_CRICLE / MM_PER_CRICLE\n",
" dType.SetEMotorEx(api, 1, 0, int(vel), 1)\n",
" \n",
" if Calibration__0__Run__1:\n",
" for _ in range(9):\n",
" # initializing and starting multi-threaded webcam input stream\n",
" cam_stream = CameraStream(stream_id=0) # 0 id for main camera\n",
" cam_stream.start()\n",
" \n",
" dType.SetPTPCmdEx(api, 0, (Calibration_X - j), (Calibration_Y - k), (Calibration_Z - 10), 0, 1)\n",
" dType.SetEndEffectorSuctionCupEx(api, 1, 1)\n",
" dType.SetPTPCmdEx(api, 0, (Place_X - 0), (Place_Y - 0), (Place_Z + 90), 0, 1)\n",
" \n",
" # adding a delay for simulating video processing time\n",
" delay = 0.3 # delay value in seconds\n",
" time.sleep(delay)\n",
" # Capture a frame from the video player - start thread\n",
" frame = cam_stream.read()\n",
" \n",
" if acquisition:\n",
" # create filename to next frame\n",
" filename = create_filename(path=(dataset_path / folder))\n",
" cv2.imwrite(filename, frame)\n",
" dType.SetPTPCmdEx(api, 0, Place_X, Place_Y, Place_Z, 0, 1)\n",
"\n",
" \n",
" else:\n",
" # Get the inference results.\n",
" frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)\n",
" # INFERENCE WITH OPENVINO\n",
" predictions = inferencer.predict(image=frame)\n",
" print(predictions.pred_score)\n",
" if predictions.pred_score > 0.48: # modify the threshold depending of your needs\n",
" dType.SetPTPCmdEx(api, 0, Anomaly_X, Anomaly_Y, Anomaly_Z, 0, 1) # define point for abnormalities\n",
" else:\n",
" dType.SetPTPCmdEx(api, 0, Place_X, Place_Y, Place_Z, 0, 1)\n",
" \n",
" dType.SetEndEffectorSuctionCupEx(api, 0, 1)\n",
" j = j + 25\n",
" if j == 75:\n",
" k = k + 25\n",
" j = 0\n",
" dType.SetPTPCmdEx(api, 7, 0, 0, 20, 0, 1)\n",
" time_start = dType.gettime()[0]\n",
" STEP_PER_CRICLE = 360.0 / 1.8 * 10.0 * 16.0\n",
" MM_PER_CRICLE = 3.1415926535898 * 36.0\n",
" vel = float(50) * STEP_PER_CRICLE / MM_PER_CRICLE\n",
" dType.SetEMotorEx(api, 1, 1, int(vel), 1)\n",
" filename = None\n",
" score = 0\n",
" while True:\n",
" if (dType.gettime()[0]) - time_start >= 0.5: # Time over conveyor belt\n",
" STEP_PER_CRICLE = 360.0 / 1.8 * 10.0 * 16.0\n",
" MM_PER_CRICLE = 3.1415926535898 * 36.0\n",
" vel = float(0) * STEP_PER_CRICLE / MM_PER_CRICLE\n",
" dType.SetEMotorEx(api, 1, 0, int(vel), 1)\n",
" break\n",
" dType.SetEndEffectorSuctionCupEx(api, 0, 1)\n",
" j = j + 25\n",
" if j == 75:\n",
" k = k + 25\n",
" j = 0\n",
" dType.SetPTPCmdEx(api, 7, 0, 0, 20, 0, 1)\n",
" time_start = dType.gettime()[0]\n",
" STEP_PER_CRICLE = 360.0 / 1.8 * 10.0 * 16.0\n",
" MM_PER_CRICLE = 3.1415926535898 * 36.0\n",
" vel = float(50) * STEP_PER_CRICLE / MM_PER_CRICLE\n",
" dType.SetEMotorEx(api, 1, 1, int(vel), 1)\n",
" filename = None\n",
" score = 0\n",
" while True:\n",
" if (dType.gettime()[0]) - time_start >= 0.5: # Time over conveyor belt\n",
" STEP_PER_CRICLE = 360.0 / 1.8 * 10.0 * 16.0\n",
" MM_PER_CRICLE = 3.1415926535898 * 36.0\n",
" vel = float(0) * STEP_PER_CRICLE / MM_PER_CRICLE\n",
" dType.SetEMotorEx(api, 1, 0, int(vel), 1)\n",
" break\n",
" dType.SetEndEffectorSuctionCupEx(api, 0, 1)\n",
" dType.SetPTPCmdEx(api, 0, Calibration_X, Calibration_Y, Calibration_Z, 0, 1)\n",
" cam_stream.stop() # stop the webcam stream"
" dType.SetPTPCmdEx(api, 0, Calibration_X, Calibration_Y, Calibration_Z, 0, 1)\n",
" cam_stream.stop() # stop the webcam stream\n",
"except ModuleNotFoundError:\n",
" print(\"No DobotDllType installed. Please install it first.\")"
]
}
],
Expand Down

0 comments on commit 3b84876

Please sign in to comment.