So I have rpi wheeled robot, with wheel encoders and I want to always keep the track of the encoders and to be able to access the value when ever I need it.
Basically, I created a thread, which always keeps incrementing global variable on a change of encoder. There are 12 stripes on a wheel, I tested just on main and it works good, it kept track of all 12 and stopped at exactly the same point as it started. However, I need to be able to track both of them at the same time. With threads, its so slow, that it misses about 30% of High/Low and it is bad. However, with multiprocessing it kept track of both of them accurately, but I cant access the memory whenever I need.
def countRightEncoder(): global countRight flag=0 while True: if encoderRight() == True and flag!=True: countRight+=1 flag=True elif encoderRight() == False and flag!=False: countRight+=1 flag=False print countRight
This loop will just always go, it wont stop and I just want to get the countRight value really often.
I was just wondering does anyone have any suggestions on how I could manage to do this without loosing any data? Maybe there is an easy way to get the value from multiprocessing?