def Stream(): while (1): time.sleep(0.05) a = arm.GetYoloOutput() print(len(a)) if len(a) > 0: arm.DrawTargetsOnVideo(a)
def LookForObject(): global ismove global lastpos while (ismove == 0): a = arm.GetYoloOutput() if len(a) > 0: arm.DrawTargetsOnVideo(a) arm.StopMovement() lastpos = arm.GetArmPosition() GetObject()
def GetObject(): global lastpos base = float(lastpos[1]) compensation = float(lastpos[3]) pos = "w" while (1): a = arm.GetYoloOutput() if len(a) > 0: pos = a[0][3] arm.DrawTargetsOnVideo(a) lock = arm.TryLockAtObject(a[0], 3, 40, res) if (lock == 1): base = base - 3 compensation = compensation - 3 arm.SetPosition(-1, base, -1, compensation, -1, -1) WaitForMove() trigger = arm.GetTriggerStatus() if (trigger == "1"): break GetAndThrowiT(pos)
import Arm as arm import numpy as np import cv2 import sys arm.InitCom() try: res = arm.GetStreamResolution() cap = cv2.VideoCapture( "C:\\Users\\mt2si\\Desktop\\projekty\\S.O.C Robotic Arm\\Robotic Arm\\PyScript\\test.mp4" ) while (1): _, frame = cap.read() BGR = np.uint8([[[51, 91, 222]]]) _, a = arm.BasicColorRecognition(frame, BGR, 20, 7000) arm.DrawTargetsOnVideo(a) if a != []: while (1): b = arm.TryLockAtObject(a[0][0], a[0][1], 5, 10, res) if b == 1: break except: # catch *all* exceptions e = sys.exc_info()[0] arm.SendMessage(e) arm.CloseCom()
conf = 0 last_center = [0, 0] arm.MovingSpeed(10) distance = 0 WaitForMove() time.sleep(0.500) id = "" while (True): time.sleep(0.1) qr, targets, center = FindQr() if (qr == 1): id = targets[0][2] arm.DrawTargetsOnVideo(targets) if distance == 0: distance = GetDistance(center[0], center[1]) arm.SendMessage("distance = " + str(distance)) arm.TryLockAtObject(center, 2, 25, res) if (last_center[0] >= center[0] - 2 and last_center[0] <= center[0] + 2 and last_center[1] >= center[1] - 2 and last_center[1] <= center[1] + 2): conf = conf + 1 else: conf = 0 if (conf == 3): act_pos = arm.GetArmPosition() f_pos = BruteForcePos(distance)