November 2018
Beginner
472 pages
13h 5m
English
We'll want the conversions for our encoders in the the EncoderCounter class so that we can use them in these behaviors. Open up your encoder_counter.py class. First, we need the math import:
from gpiozero import DigitalInputDeviceimport math...
At the top of the class, add ticks_to_mm_const as a class variable (not an instance variable) so that we can use it without any instances of the class. Set this to none initially so that we can calculate it:
...class EncoderCounter(object): ticks_to_mm_const = None # you must set this up before using distance methods ...
In our class, we want to be able to retrieve the distance the wheel has traveled directly from the encoder, in mm. Add this ...