Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| eb13361f4f | |||
| d09222967b | |||
| 4f23a4d308 | |||
| c4b6ee5d97 | |||
| 9a192d8eb8 | |||
| 8c39974c5a | |||
| 2a555aedbc | |||
| b7bef93301 | |||
| f66438019e | |||
| 5e0925b540 | |||
| 129bd9af93 | |||
| 540ff62836 | |||
| f5b51cb3aa | |||
| 07bbba41e4 | |||
| 8c5e90e0ec |
@@ -1,11 +0,0 @@
|
|||||||
import usys
|
|
||||||
from pybricks import version
|
|
||||||
class MicroPythonDiagnostics:
|
|
||||||
def __init__(self, hub):
|
|
||||||
pass
|
|
||||||
def printAll():
|
|
||||||
print("[Hub Diagnostics - MicroPython] Hub version information:", version)
|
|
||||||
print("[Hub Diagnostics - MicroPython] MicroPython version:", usys.version)
|
|
||||||
print("[Hub Diagnostics - MicroPython] Pybricks version information:", usys.version_info)
|
|
||||||
print("[Hub Diagnostics - MicroPython] MicroPython information:", usys.implementation)
|
|
||||||
|
|
||||||
@@ -4,11 +4,11 @@ from pybricks.parameters import Button, Color, Direction, Port, Side, Stop
|
|||||||
from pybricks.robotics import DriveBase
|
from pybricks.robotics import DriveBase
|
||||||
from pybricks.tools import wait, StopWatch
|
from pybricks.tools import wait, StopWatch
|
||||||
HUB = PrimeHub()
|
HUB = PrimeHub()
|
||||||
from BatteryDiagnostics import BatteryDiagnostics
|
from battery_diagnostics import BatteryDiagnostics
|
||||||
from MotorDiagnostics import MotorDiagnostics
|
from motor_diagnostics import MotorDiagnostics
|
||||||
from ColorSensorDiagnostics import ColorSensorDiagnostics
|
from color_sensor_diagnostics import ColorSensorDiagnostics
|
||||||
from DriveBaseDiagnostics import DriveBaseDiagnostics
|
from drive_base_diagnostics import DriveBaseDiagnostics
|
||||||
from HubDiagnostics import HubDiagnostics
|
from hub_diagnostics import HubDiagnostics
|
||||||
battery = BatteryDiagnostics(HUB)
|
battery = BatteryDiagnostics(HUB)
|
||||||
motor = MotorDiagnostics(HUB, Motor)
|
motor = MotorDiagnostics(HUB, Motor)
|
||||||
colorsensor = ColorSensorDiagnostics(HUB, ColorSensor)
|
colorsensor = ColorSensorDiagnostics(HUB, ColorSensor)
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
from pybricks.tools import wait, StopWatch
|
from pybricks.tools import wait, StopWatch
|
||||||
from pybricks import version
|
from pybricks import version
|
||||||
import OtherFunctions as debug
|
import other_functions as debug
|
||||||
from MicroPythonDiagnostics import MicroPythonDiagnostics
|
from micropython_diagnostics import MicroPythonDiagnostics
|
||||||
from pybricks.parameters import Port
|
from pybricks.parameters import Port
|
||||||
class HubDiagnostics:
|
class HubDiagnostics:
|
||||||
def __init__(self, hub):
|
def __init__(self, hub):
|
||||||
42
diagnostics/micropython_diagnostics.py
Normal file
42
diagnostics/micropython_diagnostics.py
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
import usys
|
||||||
|
import micropython
|
||||||
|
from pybricks import version
|
||||||
|
class MicroPythonDiagnostics:
|
||||||
|
def __init__(self, hub):
|
||||||
|
pass
|
||||||
|
def printVersionDiagnostics():
|
||||||
|
print("[Hub Diagnostics - MicroPython - Version] Hub version information:", version)
|
||||||
|
print("[Hub Diagnostics - MicroPython - Version] MicroPython version:", usys.version)
|
||||||
|
print("[Hub Diagnostics - MicroPython - Version] Pybricks version information:", usys.version_info)
|
||||||
|
print("[Hub Diagnostics - MicroPython - Version] MicroPython information:", usys.implementation)
|
||||||
|
def performMemoryDiagnostics():
|
||||||
|
print("[Hub Diagnostics - MicroPython - Memory] Memory information (retrieved from the MicroPython environment):")
|
||||||
|
micropython.mem_info(1)
|
||||||
|
print("[Hub Diagnostics - MicroPython - Memory] Testing heap lock and unlock.")
|
||||||
|
print("[Hub Diagnostics - MicroPython - Memory] Allocating memory while heap is unlocked:")
|
||||||
|
try:
|
||||||
|
x = 5000
|
||||||
|
print("[Hub Diagnostics - MicroPython - Memory] [SUCCESS] There was no MemoryError raised. The value of the new variable x is", x)
|
||||||
|
except MemoryError:
|
||||||
|
print("[Hub Diagnostics - MicroPython - Memory] [FAIL] Allocation failed. Your memory may be faulty.")
|
||||||
|
print("[Hub Diagnostics - MicroPython - Memory] Locking the heap:")
|
||||||
|
micropython.heap_lock()
|
||||||
|
print("[Hub Diagnostics - MicroPython - Memory] Heap was locked. Attempting to allocate memory (this should fail):")
|
||||||
|
try:
|
||||||
|
y = 10000
|
||||||
|
print("[Hub Diagnostics - MicroPython - Memory] [FAIL] There was no MemoryError raised. Heap lock failed.")
|
||||||
|
except MemoryError:
|
||||||
|
print("[Hub Diagnostics - MicroPython - Memory] [SUCCESS] Allocation failed. Test successful. The heap was successfully locked.")
|
||||||
|
# Attempt to add gc to this for memory diagnostics, in addition test machine.soft_reset() and add that first to reset the heap.
|
||||||
|
print("[Hub Diagnostics - MicroPython - Memory] Unlocking the heap:")
|
||||||
|
micropython.heap_unlock()
|
||||||
|
print("[Hub Diagnostics - MicroPython - Memory] Heap was unlocked. Attempting to allocate memory (this should succeed):")
|
||||||
|
try:
|
||||||
|
z = 17000
|
||||||
|
print("[Hub Diagnostics - MicroPython - Memory] [SUCCESS] There was no MemoryError raised. The value of the new variable y is", x)
|
||||||
|
except MemoryError:
|
||||||
|
print("[Hub Diagnostics - MicroPython - Memory] [FAIL] Allocation failed. The heap failed to unlock.")
|
||||||
|
def printAll():
|
||||||
|
printVersionDiagnostics()
|
||||||
|
performMemoryDiagnostics()
|
||||||
|
|
||||||
Reference in New Issue
Block a user