Advertisement
Guest User

Untitled

a guest
Feb 25th, 2020
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. #!/usr/bin/python3
  2. # coding=utf-8
  3. from ev3dev.ev3 import *
  4. import math
  5.  
  6. mB = LargeMotor('outB')
  7. mC = LargeMotor('outC')
  8. f = open('lab6.txt', 'w')
  9. f.write('0' + ' ' + '0' + '\n')
  10. mB.position = 0
  11. mC.position = 0
  12. masx = [1, -1, -1, 1]
  13. masy = [1, 1, -1, -1]
  14. x1 = 0
  15. y1 = 0
  16. a1 = 0
  17. al2 = 0
  18. ar2 = 0
  19. r = 0.0275
  20. B = 0.19
  21. ar1 = 0
  22. al1 = 0
  23. k = 0.1
  24. t2 = 0
  25. v_max = 300
  26. try:
  27. for i in range(len(masx)):
  28. while True:
  29. t1 = time.time()
  30. dt = t1 - t2
  31.  
  32. al1 = mB.position
  33. ar1 = mC.position
  34. a1 += math.radians((ar1 - ar2) - (al1 - al2)) * r / B
  35. x1 += math.cos(a1) * math.radians((ar1 - ar2) + (al1 - al2)) * r / 2
  36. y1 += math.sin(a1) * math.radians((ar1 - ar2) + (al1 - al2)) * r / 2
  37.  
  38. p = math.sqrt(math.pow(x1 - masx[i], 2) + math.pow(y1 - masy[i], 2))
  39. if a1 > 2*math.pi:
  40. a = math.atan2(masy[i] - y1, masx[i] - x1) - a1 + 2*math.pi
  41. else:
  42. a = math.atan2(masy[i] - y1, masx[i] - x1) - a1ΠΉ
  43.  
  44. v = v_max * math.tanh(p) * math.cos(a)
  45. w = k * a + v_max * math.tanh(p) / p * math.sin(a) * math.cos(a)
  46. print(str(v) + ' ' + str(w) + ' ' + str(p) + ' ' + str(a))
  47. print(str(math.tanh(p)) + ' ' + str(math.cos(a)))
  48. f.write(str(x1) + ' ' + str(y1) + ' ' + str(dt))
  49. if abs(p) < 0.2:
  50. break
  51.  
  52. if w > 20:
  53. w = 20
  54. if w < -20:
  55. w = -20
  56.  
  57. if v > 80:
  58. v = 80
  59. if v < -80:
  60. v = -80
  61.  
  62. mB.run_direct(duty_cycle_sp=v - w)
  63. mC.run_direct(duty_cycle_sp=v + w)
  64.  
  65. t2 = t1
  66. ar2 = ar1
  67. al2 = al1
  68. finally:
  69. mB.stop(stop_action='brake')
  70. mC.stop(stop_action='brake')
  71. f.close
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement