File tree 1 file changed +34
-0
lines changed
robotpy_ext/common_drivers
1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -36,6 +36,40 @@ def getDistance(self):
36
36
return max (min (d , 145.0 ), 22.5 )
37
37
38
38
39
+ class SharpIR2Y0A21 :
40
+ """
41
+ Sharp GP2Y0A21YK0F is an analog IR sensor capable of measuring
42
+ distances from 10cm to 80cm. Output distance is measured in
43
+ centimeters.
44
+
45
+ Distance is calculated using the following equation derived from
46
+ the graph provided in the datasheet::
47
+
48
+ 26.449*x ^ -1.226
49
+
50
+ .. warning:: FRC Teams: the case on these sensors is conductive and
51
+ grounded, and should not be mounted on a metallic
52
+ surface!
53
+ """
54
+
55
+ def __init__ (self , port ):
56
+ """:param port: Analog port number"""
57
+ self .distance = wpilib .AnalogInput (port )
58
+
59
+ def getDistance (self ):
60
+ """
61
+ :returns: distance in centimeters. The output is constrained to
62
+ be between 10 and 80
63
+ """
64
+
65
+ # Don't allow zero/negative values
66
+ v = max (self .distance .getVoltage (), 0.00001 )
67
+ d = 26.449 * math .pow (v , - 1.226 )
68
+
69
+ # Constrain output
70
+ return max (min (d , 80.0 ), 10.0 )
71
+
72
+
39
73
class SharpIRGP2Y0A41SK0F :
40
74
"""
41
75
Sharp GP2Y0A41SK0F is an analog IR sensor capable of measuring
You can’t perform that action at this time.
0 commit comments