-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathutils.py
More file actions
30 lines (25 loc) · 860 Bytes
/
utils.py
File metadata and controls
30 lines (25 loc) · 860 Bytes
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
from math import tan
from wpilib import SerialPort
class Utils:
@staticmethod
def calculateDistanceToTargetMeters(
cameraHeightMeters: float,
targetHeightMeters: float,
cameraPitchRadians: float,
targetPitchRadians: float,
) -> float:
return (targetHeightMeters - cameraHeightMeters) / tan(
cameraPitchRadians + targetPitchRadians
)
@staticmethod
def readString(port: SerialPort) -> str:
port_bytes = port.getBytesReceived()
buffer = bytearray(port_bytes)
converted = port.read(buffer)
return buffer[:converted].decode("ascii")
@staticmethod
def clamp(value, min_value, max_value):
return max(min(value, max_value), min_value)
@staticmethod
def normalize(pixels, max_pixels):
return (pixels * 2 / max_pixels) -1