Advertisement
Guest User

GoPiGo

a guest
May 1st, 2016
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.56 KB | None | 0 0
  1. def checkdist():
  2.     global last_vl
  3.     global last_vr
  4.     if last_vl == 0 or last_vr == 0:
  5.         global init_left
  6.         global init_right
  7.         global left_w
  8.         global right_w
  9.         left = abs(enc_read(0))
  10.         print left
  11.         left = abs(left - left_w - init_left)
  12.         print left
  13.         right = abs(enc_read(1))
  14.         right = abs(right - right_w - init_right)
  15.         print ("Left wheel encoder value::      " + str(left))
  16.         print ("Right wheel encoder value::     " + str(right))
  17.         last_vl = left
  18.         last_vr = right
  19.         av = (left+right)/2
  20.         turns = av/18
  21.         dist_travelled = turns*circum
  22.         return dist_travelled
  23.     else:
  24.         global init_left
  25.         global init_right
  26.         global left_w
  27.         global right_w
  28.         left = abs(enc_read(0))
  29.         print left
  30.         left = abs(left - left_w - init_left - last_vl)
  31.         print left
  32.         right = abs(enc_read(1))
  33.         right = abs(right - right_w - init_right - last_vr)
  34.         print ("Left wheel encoder value:       " + str(left))
  35.         print ("Right wheel encoder value:      " + str(right))
  36.         last_vl = left
  37.         last_vr = right
  38.         av = (left+right)/2
  39.         turns = av/18
  40.         dist_travelled = turns*circum
  41.         return dist_travelled
  42.  
  43. def getdist():
  44.     global left_w
  45.     global right_w
  46.     left_w = abs(enc_read(0))
  47.     right_w = abs(enc_read(1))
  48.     print ("starting left wheel encoder value:       " + str(left_w))
  49.     print ("starting right wheel encoder value:      " + str(right_w))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement