Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
30 changes: 29 additions & 1 deletion XRPLib/board.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ def are_motors_powered(self) -> bool:
:return: Returns true if the batteries are connected and powering the motors, false otherwise
:rytpe: bool
"""
return self.on_switch.read_u16() > 20000
if "NanoXRP" in sys.implementation._machine:
return True

threshold_voltage = 4.272
return self.get_battery_voltage() > threshold_voltage

def is_button_pressed(self) -> bool:
"""
Expand Down Expand Up @@ -125,3 +129,27 @@ def set_rgb_led(self, r:int, g:int, b:int):
self.rgb_led.write()
else:
raise NotImplementedError("Board.set_rgb_led not implemented for the XRP Beta")

def get_battery_voltage(self, vin_pin="BOARD_VIN_MEASURE") -> float:
"""
Returns the current battery voltage in volts.

:param vin_pin: The pin the on/off switch is connected to
:type vin_pin: int
:return: Battery voltage in volts
:rtype: float
"""

if "NanoXRP" in sys.implementation._machine:
# VIN pin on NanoXRP is also used for RM2.
self.on_switch = ADC(Pin(vin_pin))

battery_voltage = self.on_switch.read_u16() * (4.09 / 26000.0)

Pin(vin_pin, Pin.OUT)
else:
# RP2040 ADC is 0-4095, MicroPython scales it to 0-65535.
# The voltage divider is calibrated to a 14V full-scale reading.
battery_voltage = self.on_switch.read_u16() / ((1024 * 64) / 14)

return battery_voltage
7 changes: 2 additions & 5 deletions XRPLib/resetbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,11 @@ def reset_hard():
if "XRPLib.board" in sys.modules:
reset_led()

if "XRPLib.buzzer" in sys.modules:
if hasattr(Pin.board, "BOARD_BUZZER"):
reset_buzzer()

if "XRPLib.servo" in sys.modules:
reset_servos()

if "XRPLib.webserver" in sys.modules:
reset_webserver()

if "NanoXRP" in sys.implementation._machine:
Pin("BOARD_VIN_MEASURE", Pin.OUT)
reset_webserver()
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"urls": [
["XRPLib/__init__.py", "github:Open-STEM/XRP_Micropython/XRPLib/__init__.py"],
["XRPLib/board.py", "github:Open-STEM/XRP_Micropython/XRPLib/board.py"],
["XRPLib/buzzer.py", "github:Open-STEM/XRP_Micropython/XRPLib/buzzer.py"],
["XRPLib/controller.py", "github:Open-STEM/XRP_Micropython/XRPLib/controller.py"],
["XRPLib/defaults.py", "github:Open-STEM/XRP_Micropython/XRPLib/defaults.py"],
["XRPLib/differential_drive.py", "github:Open-STEM/XRP_Micropython/XRPLib/differential_drive.py"],
Expand All @@ -20,6 +21,7 @@
["XRPLib/timeout.py", "github:Open-STEM/XRP_Micropython/XRPLib/timeout.py"],
["XRPLib/webserver.py", "github:Open-STEM/XRP_Micropython/XRPLib/webserver.py"],
["XRPExamples/__init__.py", "github:Open-STEM/XRP_Micropython/XRPExamples/__init__.py"],
["XRPExamples/buzzer_examples.py", "github:Open-STEM/XRP_Micropython/XRPExamples/buzzer_examples.py"],
["XRPExamples/drive_examples.py", "github:Open-STEM/XRP_Micropython/XRPExamples/drive_examples.py"],
["XRPExamples/gamepad_example.blocks", "github:Open-STEM/XRP_Micropython/XRPExamples/gamepad_example.blocks"],
["XRPExamples/installation_verification.py", "github:Open-STEM/XRP_Micropython/XRPExamples/installation_verification.py"],
Expand All @@ -30,5 +32,5 @@
"deps": [
["github:pimoroni/phew", "latest"]
],
"version": "2.1.3"
"version": "2.1.4"
}