Skip to content

Commit 9097128

Browse files
committed
Add sample Smart Motor component
1 parent f34a922 commit 9097128

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

external_samples/smart_motor.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
from component import Component, PortType, InvalidPortException
2+
from collections.abc import Callable
3+
4+
class SmartMotor(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.SMART_MOTOR_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 "DC Motor"
16+
def get_part_number(self) -> str:
17+
return "REV-xx-xxxx"
18+
def get_url(self) -> str:
19+
return "https://www.revrobotics.com/rev-xx-xxxx"
20+
def get_version(self) -> tuple[int, int, str]:
21+
return (1, 0, "")
22+
def stop(self) -> None:
23+
# send stop command to motor
24+
pass
25+
def reset(self) -> None:
26+
pass
27+
def get_connection_port_type(self) -> list[PortType]:
28+
return [PortType.SMART_MOTOR_PORT]
29+
def periodic(self) -> None:
30+
pass
31+
32+
# Component specific methods
33+
def set_speed(self, speed: float) -> None:
34+
'''Set the motor to a speed between -1 and 1'''
35+
# sends to the hardware the speed of the motor
36+
37+
def set_angle_degrees(self, angle: float) -> None:
38+
'''Set the motor to an angle between 0 and 270'''
39+
self.set_position(angle / 270.0)
40+
41+
def get_num_relative_encoder_ticks(self) -> int:
42+
'''Get the number of relative motor ticks since reset of encoder'''
43+
pass
44+
45+
def get_angle_degrees(self) -> float:
46+
'''Get the angle position of the motor'''
47+
pass
48+
49+
def reset_relative_encoder(self) -> None:
50+
'''Reset the relative encoder value to 0'''
51+
pass
52+

0 commit comments

Comments
 (0)