SHARE
TWEET

Untitled

a guest Oct 21st, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import sys
  2. import signal
  3. import wiringpi as wp
  4. import encoder as enc
  5. import threading as th
  6. import time
  7. import Queue
  8.  
  9. pwmpinA = 26 #A
  10. pwmpinB = 24 #B
  11. pwmB = 23 #Signalo A generatorius
  12. pwmA = 1 #Signalo B generatorius
  13. wp.wiringPiSetup()
  14. daugiklis = input("metrai")
  15. atstumas = 174*daugiklis
  16. atstumasR = 174*daugiklis
  17.  
  18. freqDiv = 1200
  19. def movingMotor(pwm, pwmPin, on, speed):
  20.     if on:
  21.         wp.pinMode(pwmPin, 2)
  22.         wp.pwmWrite(pwm, speed)
  23.     else:
  24.         wp.pinMode(pwmPin, 1)
  25.         wp.pwmWrite(pwm, 0)
  26.  
  27. def signal_handler(sig, frame):
  28.     movingMotor(pwmpinA, pwmA, False, 0)
  29.     movingMotor(pwmpinB, pwmB, False, 0)
  30.     print("Exit")
  31.     sys.exit(0)
  32.  
  33. signal.signal(signal.SIGINT, signal_handler)
  34. left_queue = Queue.Queue()
  35. right_queue = Queue.Queue()
  36.  
  37. left = th.Thread(target = enc.GetStepsLeft)
  38. left.daemon = True
  39. right = th.Thread(target = enc.GetStepsRight)
  40. right.daemon = True
  41. left.start()
  42. right.start()
  43. left_value = 0
  44. right_value = 0
  45. cmd = 1
  46. #for i in  range(10):
  47.  #   movingMotor(pwmpinA,pwmA,True,57*i)
  48.   #  movingMotor(pwmpinB,pwmB,True,60*i)
  49.    # time.sleep(0.1)
  50. while left_value < atstumas or right_value *-1< atstumasR:
  51.     #cmd = int(input("input "))
  52.     if cmd == 1:
  53.         on = True
  54.        
  55.  
  56.         movingMotor(pwmpinA, pwmA, on, 732) #Right  Wheel
  57.                 #time.sleep(0.005)
  58.         movingMotor(pwmpinB, pwmB, on, 740) #Left  Wheel
  59.     elif cmd == 0:
  60.         on = False
  61.         movingMotor(pwmpinA, pwmA, on, 0)
  62.         movingMotor(pwmpinB, pwmB, on, 0)
  63.     left_value = enc.Lsteps
  64.     right_value = enc.Rsteps
  65.     #print(praslydimas)
  66.     print(enc.Lsteps , right_value *-1)
  67.     time.sleep(0.05)
  68. movingMotor(pwmpinA, pwmA, False, 0)
  69. movingMotor(pwmpinB, pwmB, False, 0)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top