diff --git a/Urumbot/Urumbot-serial-servo.py b/Urumbot/Urumbot-serial-servo.py index dbefe1ac564ea220d194ba02cb148fb874d624fd..9e605f782595ab6c550eeb7b660350b7c06b517c 100644 --- a/Urumbot/Urumbot-serial-servo.py +++ b/Urumbot/Urumbot-serial-servo.py @@ -28,13 +28,13 @@ xmin = ymin = 0 count0 = count1 = countz = 0 probstep0 = probstep1 = 0 port0 = port1 = portz = 0 -time = stepus = 0 +t = stepus = 0 pwmtime = 20000 # 50 Hz # # open ports and start alarm # def Connect(): - global port0,port1,portz,time,countz,stepus + global port0,port1,portz,t,countz,stepus # try: port0 = serial.Serial(Port0Var.get(),baudrate=int(BaudRateVar.get()),timeout=0) # non-blocking @@ -56,7 +56,7 @@ def Connect(): print('can not open '+PortZVar.get()) # try: - time = 0 + t = 0 stepus = int(float(StepTimeVar.get())*1000000) countz = int(PWMVar.get()) signal.signal(signal.SIGALRM,AlarmHandler) @@ -68,8 +68,8 @@ def Connect(): # alarm handler # def AlarmHandler(signum,stack): - global count0,count1,time - time += stepus + global count0,count1,t + t += stepus # if ((port0 != 0) and (count0 != 0) and (probstep0 != 0)): if (random.random() <= probstep0): @@ -90,9 +90,9 @@ def AlarmHandler(signum,stack): count1 += 1 # if ((portz != 0) and (countz != 0)): - if (time < pwmtime): + if (t < pwmtime): return - time = 0 + t = 0 portz.write(countz.to_bytes(2,byteorder='little')) # # UI routines @@ -174,15 +174,15 @@ def JogAngle(): MoveCount() # def UpdateStepTime(): - global time + global t signal.setitimer(signal.ITIMER_REAL,0,0) - time = 0 + t = 0 signal.signal(signal.SIGALRM,AlarmHandler) signal.setitimer(signal.ITIMER_REAL,float(StepTimeVar.get()),float(StepTimeVar.get())) # def UpdatePWM(): - global time,stepus,countz - time = 0 + global t,stepus,countz + t = 0 stepus = int(float(StepTimeVar.get())*1000000) countz = int(PWMVar.get()) # @@ -417,4 +417,8 @@ Plot.grid(column=1,row=row,columnspan=4,padx=pad,pady=pad,sticky='sw') # # start mainloop # -root.mainloop() +#root.mainloop() +while (True): + time.sleep(0.01) + update_idletasks() + update()