@@ -13,6 +13,10 @@ class Motor(ComponentBase):
1313 This acts as an abstract base class for any drivers representing specific
1414 motor implementations. This cannot be used on its own. If the ``__init__()`` function is
1515 overridden, it must call the ``super().__init__()`` function.
16+
17+ ::
18+
19+ from viam.components.motor import Motor
1620 """
1721
1822 @dataclass
@@ -36,6 +40,13 @@ async def set_power(
3640 Sets the "percentage" of power the motor should employ between -1 and 1.
3741 When ``power`` is negative, the rotation will be in the backward direction.
3842
43+ ::
44+
45+ my_motor = Motor.from_robot(robot=robot, name="my_motor")
46+
47+ # Set the power to 40% forwards.
48+ await my_motor.set_power(power=0.4)
49+
3950 Args:
4051 power (float): Power between -1 and 1
4152 (negative implies backwards).
@@ -57,6 +68,13 @@ async def go_for(
5768 When ``rpm`` or ``revolutions`` is a negative value, the rotation will be in the backward direction.
5869 Note: if both ``rpm`` and ``revolutions`` are negative, the motor will spin in the forward direction.
5970
71+ ::
72+
73+ my_motor = Motor.from_robot(robot=robot, name="my_motor")
74+
75+ # Turn the motor 7.2 revolutions at 60 RPM.
76+ await my_motor.go_for(rpm=60, revolutions=7.2)
77+
6078 Args:
6179 rpm (float): Speed at which the motor should move in rotations per minute
6280 (negative implies backwards).
@@ -81,6 +99,13 @@ async def go_to(
8199 Regardless of the directionality of the ``rpm`` this function will move
82100 the motor towards the specified position.
83101
102+ ::
103+
104+ my_motor = Motor.from_robot(robot=robot, name="my_motor")
105+
106+ # Turn the motor to 8.3 revolutions from home at 75 RPM.
107+ await my_motor.go_to(rpm=75, revolutions=8.3)
108+
84109 Args:
85110 rpm (float): Speed at which the motor should rotate (absolute value).
86111 position_revolutions (float): Target position relative to home/zero, in revolutions.
@@ -99,6 +124,13 @@ async def reset_zero_position(
99124 """
100125 Set the current position (modified by ``offset``) to be the new zero (home) position.
101126
127+ ::
128+
129+ my_motor = Motor.from_robot(robot=robot, name="my_motor")
130+
131+ # Set the current position as the new home position with no offset.
132+ await my_motor.reset_zero_position(offset=0.0)
133+
102134 Args:
103135 offset (float): The offset from the current position to new home/zero position.
104136 """
@@ -117,6 +149,13 @@ async def get_position(
117149 The value returned is the number of revolutions relative to its zero position.
118150 This method will raise an exception if position reporting is not supported by the motor.
119151
152+ ::
153+
154+ my_motor = Motor.from_robot(robot=robot, name="my_motor")
155+
156+ # Get the current position of the motor.
157+ position = await my_motor.get_position()
158+
120159 Returns:
121160 float: Number of revolutions the motor is away from zero/home.
122161 """
@@ -134,6 +173,17 @@ async def get_properties(
134173 Report a dictionary mapping optional properties to
135174 whether it is supported by this motor.
136175
176+ ::
177+
178+ my_motor = Motor.from_robot(robot=robot, name="my_motor")
179+
180+ # Report a dictionary mapping optional properties to whether it is supported by
181+ # this motor.
182+ properties = await my_motor.get_properties()
183+
184+ # Print out the properties.
185+ print(f'Properties: {properties}')
186+
137187 Returns:
138188 Properties: Map of feature names to supported status.
139189 """
@@ -149,6 +199,13 @@ async def stop(
149199 ):
150200 """
151201 Stop the motor immediately, without any gradual step down.
202+
203+ ::
204+
205+ my_motor = Motor.from_robot(robot=robot, name="my_motor")
206+
207+ # Stop the motor.
208+ await my_motor.stop()
152209 """
153210 ...
154211
@@ -163,6 +220,15 @@ async def is_powered(
163220 """
164221 Returns whether or not the motor is currently running.
165222
223+ ::
224+
225+ my_motor = Motor.from_robot(robot=robot, name="my_motor")
226+
227+ # Check whether the motor is currently running.
228+ powered = await my_motor.is_powered()
229+
230+ print('Powered: ', powered)
231+
166232 Returns:
167233 bool: Indicates whether the motor is currently powered.
168234 float: The current power percentage of the motor
@@ -174,6 +240,14 @@ async def is_moving(self) -> bool:
174240 """
175241 Get if the motor is currently moving.
176242
243+ ::
244+
245+ my_motor = Motor.from_robot(robot=robot, name="my_motor")
246+
247+ # Check whether the motor is currently moving.
248+ moving = await my_motor.is_moving()
249+ print('Moving: ', moving)
250+
177251 Returns:
178252 bool: Whether the motor is moving.
179253 """
0 commit comments