-
Notifications
You must be signed in to change notification settings - Fork 226
feat: Added RoboticArm #255
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,8 @@ | |
| >>> servo.angle = 30 # Turn motor to 30 degrees position. | ||
| """ | ||
|
|
||
| import time | ||
| from typing import List | ||
| from typing import Union | ||
|
|
||
| from pslab.instrument.waveform_generator import PWMGenerator | ||
|
|
@@ -70,3 +72,21 @@ def _get_duty_cycle(self, angle): | |
| angle *= self._max_angle_pulse - self._min_angle_pulse # Scale | ||
| angle += self._min_angle_pulse # Offset | ||
| return angle / (self._frequency**-1 * MICROSECONDS) | ||
|
|
||
|
|
||
| class RoboticArm: | ||
| MAX_SERVOS = 4 | ||
|
|
||
| def __init__(self, servos: List[Servo]) -> None: | ||
| if len(servos) > RoboticArm.MAX_SERVOS: | ||
| raise ValueError( | ||
| f"At most {RoboticArm.MAX_SERVOS} servos can be used, got {len(servos)}" | ||
| ) | ||
| self.servos = servos | ||
|
|
||
| def run_schedule(self, timeline: List[List[int]]) -> None: | ||
| for i in range(len(timeline)): | ||
| for j in range(len(self.servos)): | ||
| angle = timeline[i][j] | ||
| self.servos[j].angle = angle | ||
bessman marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| time.sleep(1) | ||
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (bug_risk): Consider validating timeline dimensions in run_schedule.
Currently, run_schedule may raise an IndexError or ignore extra values if a sublist's length doesn't match self.servos. Adding a check for sublist length would improve robustness.