Skip to content

Commit a1b1bac

Browse files
committed
Added servo example
1 parent 16b4ea5 commit a1b1bac

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

external_samples/servo.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
from component import Component, PortType, InvalidPortException
2+
from collections.abc import Callable
3+
4+
class Servo(Component):
5+
# Required methods
6+
def __init__(self, ports : list[tuple[PortType, int]]):
7+
self.is_pressed = None
8+
portType, port = ports[0]
9+
if portType != PortType.SERVO_PORT:
10+
raise InvalidPortException
11+
self.port = port
12+
def get_manufacturer(self) -> str:
13+
return "REV Robotics"
14+
def get_name(self) -> str:
15+
return "SRS Servo"
16+
def get_part_number(self) -> str:
17+
return "REV-41-1097"
18+
def get_url(self) -> str:
19+
return "https://www.revrobotics.com/rev-41-1097/"
20+
def get_version(self) -> tuple[int, int, str]:
21+
return (1, 0, "")
22+
def stop(self) -> None:
23+
# De-energize servo port
24+
pass
25+
def reset(self) -> None:
26+
pass
27+
def get_connection_port_type(self) -> list[PortType]:
28+
return [PortType.SERVO_PORT]
29+
def periodic(self) -> None:
30+
pass
31+
32+
# Component specific methods
33+
def set_position(self, pos: float) -> None:
34+
'''Set the servo to a position between 0 and 1'''
35+
# sends to the hardware the position of the servo
36+
pass
37+
def set_angle(self, angle: float) -> None:
38+
'''Set the servo to an angle between 0 and 270'''
39+
self.set_position(angle / 270.0)
40+
41+
42+

0 commit comments

Comments
 (0)