-
Notifications
You must be signed in to change notification settings - Fork 26
autodiscover opmodes + opmode example #260
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
Open
virtuald
wants to merge
8
commits into
main
Choose a base branch
from
opmode-discovery
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
571e42c
feat: add Python opmode decorators and discovery
virtuald cf18107
feat: validate discovered Python opmodes
virtuald 639f593
Add OpMode user controls injection
virtuald 9d25f61
Document OpMode decorators and discovery
virtuald 12e6836
Limit OpMode auto-discovery scope
virtuald 5dc5709
Document DefaultUserControls.getGamepad
virtuald c2445ec
Reject non-OpMode classes in decorators
virtuald 7226c87
Formatting
virtuald 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,31 @@ | ||
| # | ||
| # Copyright (c) FIRST and other WPILib contributors. | ||
| # Open Source Software; you can modify and/or share it under the terms of | ||
| # the WPILib BSD license file in the root directory of this project. | ||
| # | ||
|
|
||
| from wpilib import PeriodicOpMode, Timer | ||
| from wpilib.opmoderobot import autonomous | ||
|
|
||
|
|
||
| @autonomous | ||
| class DefaultAutoMode(PeriodicOpMode): | ||
| def __init__(self, robot): | ||
| super().__init__() | ||
| self.robot = robot | ||
| self.timer = Timer() | ||
|
|
||
| def start(self): | ||
| self.timer.reset() | ||
| self.timer.start() | ||
|
|
||
| def periodic(self): | ||
| if self.timer.get() < 2.0: | ||
| self.robot.motor0.setThrottle(0.5) | ||
| self.robot.motor1.setThrottle(0.5) | ||
| elif self.timer.get() < 4.0: | ||
| self.robot.motor0.setThrottle(0.9) | ||
| self.robot.motor1.setThrottle(0.9) | ||
| else: | ||
| self.robot.motor0.setThrottle(0.0) | ||
| self.robot.motor1.setThrottle(0.0) |
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,24 @@ | ||
| # | ||
| # Copyright (c) FIRST and other WPILib contributors. | ||
| # Open Source Software; you can modify and/or share it under the terms of | ||
| # the WPILib BSD license file in the root directory of this project. | ||
| # | ||
|
|
||
| from wpilib import Gamepad, PeriodicOpMode | ||
| from wpilib.opmoderobot import teleop | ||
|
|
||
|
|
||
| @teleop | ||
| class DefaultTeleMode(PeriodicOpMode): | ||
| def __init__(self, robot): | ||
| super().__init__() | ||
| self.robot = robot | ||
| self.gamepad = Gamepad(0) | ||
|
|
||
| def periodic(self): | ||
| self.robot.motor0.setThrottle(-self.gamepad.getLeftY()) | ||
| self.robot.motor1.setThrottle(-self.gamepad.getRightY()) | ||
| self.robot.motor2.setThrottle(-self.gamepad.getLeftX()) | ||
| self.robot.motor3.setThrottle(-self.gamepad.getRightX()) | ||
| self.robot.servo0.setPosition(self.gamepad.getLeftTriggerAxis()) | ||
| self.robot.servo1.setPosition(self.gamepad.getRightTriggerAxis()) | ||
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,20 @@ | ||
| #!/usr/bin/env python3 | ||
| # | ||
| # Copyright (c) FIRST and other WPILib contributors. | ||
| # Open Source Software; you can modify and/or share it under the terms of | ||
| # the WPILib BSD license file in the root directory of this project. | ||
| # | ||
|
|
||
| from wpilib import ExpansionHubMotor, ExpansionHubServo | ||
| from wpilib.opmoderobot import OpModeRobot | ||
|
|
||
|
|
||
| class Robot(OpModeRobot): | ||
| def __init__(self): | ||
| super().__init__() | ||
| self.motor0 = ExpansionHubMotor(0, 0) | ||
| self.motor1 = ExpansionHubMotor(0, 1) | ||
| self.motor2 = ExpansionHubMotor(0, 2) | ||
| self.motor3 = ExpansionHubMotor(0, 3) | ||
| self.servo0 = ExpansionHubServo(0, 0) | ||
| self.servo1 = ExpansionHubServo(0, 1) |
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.