Advertisement
Morbo

core-xy with stepper truncate

May 13th, 2012
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #from sys import argv
  2.  
  3. #functions
  4. def deltaX(a,b):
  5.     return .5*(a+b)
  6. def deltaY(a,b):
  7.     return .5*(a-b)
  8. def deltaA(x,y):
  9.     return x+y
  10. def deltaB(x,y):
  11.     return x-y
  12. def trunc(f,n):
  13.     '''Truncates/pads a float f to n decimal places without rounding'''
  14.     slen = len('%.*f' % (n, f))
  15.     return str(f)[:slen]
  16. ##########
  17. ##########
  18.  
  19. #constants
  20. diametre = int(raw_input('What is the pully diametre? '))
  21. steps = int(raw_input('How many steps (including micro)? '))
  22. pi = 3.14159
  23. ##########
  24. ##########
  25.  
  26. #math
  27. circ = diametre*pi
  28. steps_per_deg = steps/360
  29. mm_per_deg = circ/360
  30. mm_step = mm_per_deg/steps_per_deg
  31. step_mm = steps_per_deg/mm_per_deg
  32. ##########
  33. ##########
  34.  
  35.  
  36. a = int(raw_input('What is new position Delta A? '))
  37. b = int(raw_input('What is new position Delta B? '))
  38. #math with functions
  39. pos_x = deltaX(a,b)
  40. pos_y = deltaY(a,b)
  41. pos_a = deltaA(pos_x,pos_y)
  42. pos_b = deltaB(pos_x,pos_y)
  43. motora = step_mm * pos_a
  44. print("""
  45. New Position dX = %s
  46. New Position dY = %s
  47. New Position dA = %s
  48. Motor moves %s steps
  49. New Position dB = %s
  50. """ % (pos_x,pos_y,pos_a,trunc(motora,0),pos_b))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement