-
Notifications
You must be signed in to change notification settings - Fork 9
Quick pass at sample components #97
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
04af614
Quick pass at external sample
alan412 d8365ee
change to snake case
alan412 6e0362d
Fix callable syntax
alan412 388dd1e
Change register to be first word
alan412 2858717
Add periodic method
alan412 ce3c119
Changed str in version to be an empty string
alan412 e39579a
Resolve review comments
alan412 6a36371
Add callback and docstrings
alan412 5032c3e
Fix review comment
alan412 8ae7c5d
Added InvalidPortException and init
alan412 16b4ea5
Added init
alan412 a1b1bac
Added servo example
alan412 f34a922
Specify degrees for set angle
alan412 9097128
Add sample Smart Motor component
alan412 a1175de
Added EmptyCallable
alan412 f1799cf
remove unused import
alan412 7e94387
Change EmptyCallable to be void
alan412 2ab2b1c
Add color range sensor
alan412 841cc4e
Address review comments
alan412 f2905fd
starting to put sample blocks in
alan412 7192398
Merge branch 'main' into sample_components
alan412 ce19ae0
Remove non working toolbox for sample components
alan412 920aa01
Add licenses
alan412 6dda055
remove no longer needed import
alan412 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| from abc import ABC, abstractmethod | ||
| from enum import Enum | ||
|
|
||
| class PortType(Enum): | ||
| CAN_PORT = 1 | ||
| SMART_IO_PORT = 2 | ||
| SMART_MOTOR_PORT = 3 | ||
| SERVO_PORT = 4 | ||
| I2C_PORT = 5 | ||
| USB_PORT = 6 | ||
|
|
||
| # This is an abstract class | ||
| class Component: | ||
| # This is the manufacturer of the component | ||
| @abstractmethod | ||
| def get_manufacturer(self) -> str: | ||
| pass | ||
| # This is the name of the component | ||
| @abstractmethod | ||
| def get_name(self) -> str: | ||
| pass | ||
| # This is the part number of the component | ||
| @abstractmethod | ||
| def get_part_number(self) -> str: | ||
| pass | ||
| # This is the URL of the component | ||
| @abstractmethod | ||
| def get_url(self) -> str: | ||
| pass | ||
| # This is the version of the software (returned as a (major, minor, revision) tuple where | ||
| # major and minor are positive integers | ||
| # revision is an optional string | ||
alan412 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| @abstractmethod | ||
| def get_version(self) -> tuple[int, int, str]: | ||
| pass | ||
|
|
||
| # This stops all movement (if any) for the component | ||
| @abstractmethod | ||
| def stop(self) -> None: | ||
| pass | ||
|
|
||
| # any reset required (if any) at the beginning of each opmode | ||
alan412 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| # This might remove any registered callbacks | ||
| @abstractmethod | ||
| def reset(self) -> None: | ||
| pass | ||
|
|
||
| # This returns a list (can be empty, one, or multipe) of the ports this connects to | ||
alan412 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| # of the PortType enumeration | ||
| @abstractmethod | ||
| def get_connection_port_type(self) -> list[PortType]: | ||
| pass | ||
|
|
||
| # This is called periodically when an opmode is running | ||
| @abstractmethod | ||
| def periodic(self) -> None: | ||
alan412 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| pass | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| from component import Component, PortType | ||
| from _collections_abc import Callable | ||
alan412 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| class RevTouchSensor(Component): | ||
| # Required methods | ||
| def get_manufacturer(self) -> str: | ||
| return "REV Robotics" | ||
| def get_name(self) -> str: | ||
| return "Touch Sensor" | ||
| def get_part_number(self) -> str: | ||
| return "REV-31-1425" | ||
| def get_url(self) -> str: | ||
| return "https://www.revrobotics.com/rev-31-1425/" | ||
| def get_version(self) -> tuple[int, int, str]: | ||
| return (1, 0, "") | ||
| def stop(self) -> None: | ||
| pass | ||
| def reset(self) -> None: | ||
| pass | ||
| def get_connection_port_type(self) -> list[PortType]: | ||
| return [PortType.SMART_IO_PORT] | ||
| def periodic(self) -> None: | ||
| # This would poll the hardware and see if it needs to fire any events | ||
alan412 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| pass | ||
|
|
||
| # Methods | ||
| def is_pressed(self) -> bool: | ||
| # Code to communicate using WPILib would go here | ||
| return True | ||
|
|
||
| # Events | ||
| def register_when_pressed(callback: Callable[[], None]) -> None: | ||
| # Code to register callback here | ||
| pass | ||
|
|
||
| def register_when_released(callback: Callable[[], None]) -> None: | ||
| # Code to register callback here | ||
| pass | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.