Advertisement
noahtren

ev3 Code

Apr 21st, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. def reset_motors():
  2. m1.off()
  3. m2.off()
  4. m4.off()
  5.  
  6. def color_map():
  7. if c_exists:
  8. if c.value() > 1:
  9. return "White"
  10. else:
  11. return "Black"
  12. else:
  13. return "No reading"
  14.  
  15. def move_and_scan():
  16. c.mode='COL-COLOR'
  17. i = 0; cols = []
  18. while len(cols) != 4:
  19. reset_motors()
  20. time.sleep(0.5)
  21. cols.append(color_map())
  22. if len(cols) == 4:
  23. break
  24. m1.on(-3)
  25. m2.on(-3)
  26. time.sleep(0.7)
  27. reset_motors()
  28. print(cols)
  29.  
  30. def iGPS_math(a, c, d):
  31. """Returns the x and y coordinates relative to
  32. the origin, given radial distances a, b, and d"""
  33. C_TO_A = 120 # the absolute distance between tower C and tower A
  34. C_TO_D = 96 # the absolute distance between tower C and tower D
  35. _theta = law_of_cosines(a,C_TO_A,c)
  36. _lambda = law_of_cosines(d,C_TO_D,c)
  37. print(_lambda)
  38. x = (math.sin(_theta) * a) + 6
  39. y = 108 - math.sin(_lambda) * d + 6
  40. return x, y
  41.  
  42. def iGPS():
  43. a = float(input("[a?]>"))
  44. c = float(input("[c?]>"))
  45. d = float(input("[d?]>"))
  46. loc = iGPS_math(a,c,d)
  47. print("x: {}, y: {}".format(loc[0], loc[1]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement