From a7080525fc4545afabac45f2830d24f316aaa779 Mon Sep 17 00:00:00 2001 From: Kevin Siegall Date: Mon, 27 Mar 2023 16:18:51 -0400 Subject: [PATCH 1/4] Fix imports --- WPILib/WPILib.py | 30 +++++++++++++++--------------- code.py | 7 ++++++- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/WPILib/WPILib.py b/WPILib/WPILib.py index 0f8c68f..f40bced 100755 --- a/WPILib/WPILib.py +++ b/WPILib/WPILib.py @@ -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 +from . import _ultrasonic_wrapper +from . import _reflectance_wrapper +from . import _servo +from . import _buttons +from . import _encoded_motor +from . import _led import time @@ -14,7 +14,7 @@ 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, @@ -22,7 +22,7 @@ doFlip=True, ticksPerRev=288) -_rightMotor = EncodedMotor( +_rightMotor = _encoded_motor.EncodedMotor( encoderPinA=_board.GP2, encoderPinB=_board.GP3, motorPin1=_board.GP10, @@ -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) diff --git a/code.py b/code.py index 0d9cdda..17aa6bc 100755 --- a/code.py +++ b/code.py @@ -4,5 +4,10 @@ from SampleCode.sample_miscellaneous import * from SampleCode.sample_sensor_access import * -ivp() +def main(): + # + # Your Code Here! + # + pass +main() \ No newline at end of file From 7fd07a02b569916de4f62da647d80072d26e8b39 Mon Sep 17 00:00:00 2001 From: Kevin Siegall Date: Mon, 27 Mar 2023 16:24:23 -0400 Subject: [PATCH 2/4] Add Encoder printouts to the ivp --- SampleCode/sample_miscellaneous.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/SampleCode/sample_miscellaneous.py b/SampleCode/sample_miscellaneous.py index 5015fbd..b63ae9a 100755 --- a/SampleCode/sample_miscellaneous.py +++ b/SampleCode/sample_miscellaneous.py @@ -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() 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() From 3c4335d7413fd8f97834a0712c79e975e2f5da23 Mon Sep 17 00:00:00 2001 From: Kevin Siegall Date: Thu, 30 Mar 2023 13:07:50 -0400 Subject: [PATCH 3/4] Fixing small mistakes; Cleaned up imports --- .vscode/settings.json | 6 +++--- SampleCode/sample_miscellaneous.py | 5 ++++- WPILib/WPILib.py | 30 +++++++++++++++--------------- code.py | 3 +-- 4 files changed, 23 insertions(+), 21 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 84ba96d..c37ea16 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,9 +5,9 @@ "reportMissingModuleSource": "none" }, "python.analysis.extraPaths": [ - "c:\\Users\\origi\\.vscode\\extensions\\joedevivo.vscode-circuitpython-0.1.19-win32-x64\\boards\\0x2E8A\\0x1000", - "c:\\Users\\origi\\.vscode\\extensions\\joedevivo.vscode-circuitpython-0.1.19-win32-x64\\stubs", - "c:\\Users\\origi\\AppData\\Roaming\\Code\\User\\globalStorage\\joedevivo.vscode-circuitpython\\bundle\\20221208\\adafruit-circuitpython-bundle-py-20221208\\lib" + "c:\\Users\\origi\\.vscode\\extensions\\joedevivo.vscode-circuitpython-0.1.20-win32-x64\\boards\\0x2E8A\\0x1000", + "c:\\Users\\origi\\.vscode\\extensions\\joedevivo.vscode-circuitpython-0.1.20-win32-x64\\stubs", + "c:\\Users\\origi\\AppData\\Roaming\\Code\\User\\globalStorage\\joedevivo.vscode-circuitpython\\bundle\\20230330\\adafruit-circuitpython-bundle-py-20230330\\lib" ], "circuitpython.board.version": "7.1.0", "circuitpython.board.vid": "0x2E8A", diff --git a/SampleCode/sample_miscellaneous.py b/SampleCode/sample_miscellaneous.py index b63ae9a..6fe970f 100755 --- a/SampleCode/sample_miscellaneous.py +++ b/SampleCode/sample_miscellaneous.py @@ -51,11 +51,14 @@ def ivp(): print(f"Left Reflectance: {reflectance.get_left()}, Right Reflectance: {reflectance.get_right()}") time.sleep(0.1) while (buttons.is_GP20_pressed() or buttons.is_GP21_pressed()): + # Wait until user to release button before continuing time.sleep(.01) while not buttons.is_GP20_pressed() and not buttons.is_GP21_pressed(): print(f"Ultrasonic Distance: {sonar.get_distance()}") time.sleep(0.1) - wait_for_button() + while (buttons.is_GP20_pressed() or buttons.is_GP21_pressed()): + # Wait until user to release button before continuing + time.sleep(.01) print("Testing Servo") test_servo() print("Testing LEDs") diff --git a/WPILib/WPILib.py b/WPILib/WPILib.py index f40bced..cb97b4f 100755 --- a/WPILib/WPILib.py +++ b/WPILib/WPILib.py @@ -1,11 +1,11 @@ import board as _board -from . import _drivetrain -from . import _ultrasonic_wrapper -from . import _reflectance_wrapper -from . import _servo -from . import _buttons -from . import _encoded_motor -from . import _led +from ._drivetrain import Drivetrain +from ._ultrasonic_wrapper import Ultrasonic +from ._reflectance_wrapper import Reflectance +from ._servo import Servo +from ._buttons import Buttons +from ._encoded_motor import EncodedMotor +from ._led import RGBLED import time @@ -14,7 +14,7 @@ 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 = _encoded_motor.EncodedMotor( +_leftMotor = EncodedMotor( encoderPinA=_board.GP4, encoderPinB=_board.GP5, motorPin1=_board.GP8, @@ -22,7 +22,7 @@ doFlip=True, ticksPerRev=288) -_rightMotor = _encoded_motor.EncodedMotor( +_rightMotor = EncodedMotor( encoderPinA=_board.GP2, encoderPinB=_board.GP3, motorPin1=_board.GP10, @@ -31,12 +31,12 @@ ticksPerRev=288) # Publicly-accessible objects -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() +drivetrain = Drivetrain(_leftMotor, _rightMotor) # units in cm +reflectance = Reflectance() +sonar = Ultrasonic() +led = RGBLED(_board.GP18) +servo = Servo(_board.GP12, actuationRange = 135) +buttons = Buttons() def set_legacy_mode(is_legacy: bool = True): drivetrain.set_legacy_mode(is_legacy) diff --git a/code.py b/code.py index 17aa6bc..be8bb62 100755 --- a/code.py +++ b/code.py @@ -8,6 +8,5 @@ def main(): # # Your Code Here! # - pass - + ivp() main() \ No newline at end of file From 9b06eca218d7bf0c315946fa45d69577ed53ca47 Mon Sep 17 00:00:00 2001 From: Kevin Siegall Date: Thu, 30 Mar 2023 13:11:25 -0400 Subject: [PATCH 4/4] Speed up LED testing --- SampleCode/sample_miscellaneous.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/SampleCode/sample_miscellaneous.py b/SampleCode/sample_miscellaneous.py index 6fe970f..2329def 100755 --- a/SampleCode/sample_miscellaneous.py +++ b/SampleCode/sample_miscellaneous.py @@ -27,12 +27,12 @@ def test_leds(): while brightness > 0: led.set_brightness(brightness) led.set_color(255,0,0) - time.sleep(0.5) + time.sleep(0.33) led.set_color(0,255,0) - time.sleep(0.5) + time.sleep(0.33) led.set_color(0,0,255) - time.sleep(0.5) - brightness -= 0.25 + time.sleep(0.33) + brightness -= 0.5 led.set_color(0,0,0) led.set_brightness(0)