Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions SampleCode/sample_miscellaneous.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,16 @@ def ivp():
while not buttons.is_GP20_pressed() and not buttons.is_GP21_pressed():
print(f"Ultrasonic Distance: {sonar.get_distance()}")
time.sleep(0.1)
while (buttons.is_GP20_pressed() or buttons.is_GP21_pressed()):
time.sleep(.01)
wait_for_button()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This waits for press + released now, is that intentional?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was intentional originally, but upon thinking about it a little more, I realized the initial implementation was correct. I've reverted that change and added comments for clarity

print("Testing Servo")
test_servo()
print("Testing LEDs")
wait_for_button()
test_leds()
print("Testing Motor Encoders:")
while not buttons.is_GP20_pressed() and not buttons.is_GP21_pressed():
print(f"Left: {drivetrain.get_left_encoder_position()}, Right: {drivetrain.get_right_encoder_position()}")
time.sleep(0.1)
print("Testing Drivetrain:")
wait_for_button()
test_drive()
30 changes: 15 additions & 15 deletions WPILib/WPILib.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import board as _board
from _drivetrain import Drivetrain
from _encoded_motor import EncodedMotor
from _ultrasonic_wrapper import Ultrasonic
from _reflectance_wrapper import Reflectance
from _servo import Servo
from _buttons import Buttons
from _led import RGBLED
from . import _drivetrain

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not do the following and avoid needing to change the code below? Is it a limitation of circuitpython?

from ._drivetrain import Drivetrain

Local imports: https://peps.python.org/pep-0008/#imports

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's nothing wrong with your recommendation, just that I'm not a primary python developer so I didn't know the exact syntax, and thus reverted to what I did know.

I've implemented your suggestion

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 both options work, I was just curious.

from . import _ultrasonic_wrapper
from . import _reflectance_wrapper
from . import _servo
from . import _buttons
from . import _encoded_motor
from . import _led

import time

Expand All @@ -14,15 +14,15 @@
If you need to change the encoder counts, alter the ticksPerRev values in the following two constructors.
Most robots have either 144 or 288 ticks per revolution, depending on which motors are used.
"""
_leftMotor = EncodedMotor(
_leftMotor = _encoded_motor.EncodedMotor(
encoderPinA=_board.GP4,
encoderPinB=_board.GP5,
motorPin1=_board.GP8,
motorPin2=_board.GP9,
doFlip=True,
ticksPerRev=288)

_rightMotor = EncodedMotor(
_rightMotor = _encoded_motor.EncodedMotor(
encoderPinA=_board.GP2,
encoderPinB=_board.GP3,
motorPin1=_board.GP10,
Expand All @@ -31,12 +31,12 @@
ticksPerRev=288)

# Publicly-accessible objects
drivetrain = Drivetrain(_leftMotor, _rightMotor) # units in cm
reflectance = Reflectance()
sonar = Ultrasonic()
led = RGBLED(_board.GP18)
servo = Servo(_board.GP12, actuationRange = 135)
buttons = Buttons()
drivetrain = _drivetrain.Drivetrain(_leftMotor, _rightMotor) # units in cm
reflectance = _reflectance_wrapper.Reflectance()
sonar = _ultrasonic_wrapper.Ultrasonic()
led = _led.RGBLED(_board.GP18)
servo = _servo.Servo(_board.GP12, actuationRange = 135)
buttons = _buttons.Buttons()

def set_legacy_mode(is_legacy: bool = True):
drivetrain.set_legacy_mode(is_legacy)
Expand Down
7 changes: 6 additions & 1 deletion code.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,10 @@
from SampleCode.sample_miscellaneous import *
from SampleCode.sample_sensor_access import *

ivp()
def main():
#
# Your Code Here!
#
pass

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this default to ivp() until the user edits it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it should. I've fixed it in one of the recent commits.


main()