Source code ev3dev2/wheel.py

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env python3
"""
Wheel and Rim classes

A great reference when adding new wheels is http://wheels.sariel.pl/
"""
from math import pi


class Wheel(object):
    """
    A base class for various types of wheels, tires, etc.  All units are in mm.

    One scenario where one of the child classes below would be used is when the
    user needs their robot to drive at a specific speed or drive for a specific
    distance. Both of those calculations require the circumference of the wheel
    of the robot.

    Example:

    .. code:: python

        from ev3dev2.wheel import EV3Tire

        tire = EV3Tire()

        # calculate the number of rotations needed to travel forward 500 mm
        rotations_for_500mm = 500 / tire.circumference_mm
    """
    def __init__(self, diameter_mm, width_mm):
        self.diameter_mm = float(diameter_mm)
        self.width_mm = float(width_mm)
        self.circumference_mm = diameter_mm * pi

    @property
    def radius_mm(self):
        return float(self.diameter_mm / 2)


class EV3Rim(Wheel):
    """
    part number 56145
    comes in set 31313
    """
    def __init__(self):
        Wheel.__init__(self, 30, 20)


class EV3Tire(Wheel):
    """
    part number 44309
    comes in set 31313
    """
    def __init__(self):
        Wheel.__init__(self, 43.2, 21)


class EV3EducationSetRim(Wheel):
    """
    part number 56908
    comes in set 45544
    """
    def __init__(self):
        Wheel.__init__(self, 43, 26)


class EV3EducationSetTire(Wheel):
    """
    part number 41897
    comes in set 45544
    """
    def __init__(self):
        Wheel.__init__(self, 56, 28)