Skip to Content
Learn Robotics Programming
book

Learn Robotics Programming

by Danny Staple
November 2018
Beginner
472 pages
13h 5m
English
Packt Publishing
Content preview from Learn Robotics Programming

Refactoring unit conversions into the EncoderCounter class

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 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learn Robotics Programming - Second Edition

Learn Robotics Programming - Second Edition

Danny Staple

Publisher Resources

ISBN: 9781789340747Supplemental Content