19 Commits
1.0.0 ... dev

Author SHA1 Message Date
181d7d35c7 Update tests/pynamics-logger.py 2026-04-10 16:42:16 +00:00
b3716b8cde Update tests/pynamics-logger.py 2026-04-10 16:41:10 +00:00
3b541f92f9 Update tests/pynamics-ansi.py 2026-04-10 16:29:41 +00:00
0e1c251ce7 Add tests/pynamics-ansi.py 2026-04-10 16:27:41 +00:00
eb13361f4f Update diagnostics/color_sensor_diagnostics.py 2026-02-13 13:22:50 +00:00
d09222967b Update diagnostics/drive_base_diagnostics.py 2026-02-13 13:22:40 +00:00
4f23a4d308 Update diagnostics/full_diagnostics.py 2026-02-13 13:22:31 +00:00
c4b6ee5d97 Update diagnostics/FullDiagnostics.py 2026-02-13 13:22:21 +00:00
9a192d8eb8 Update diagnostics/hub_diagnostics.py 2026-02-13 13:21:49 +00:00
8c39974c5a Update diagnostics/micropython_diagnostics.py 2026-02-13 13:21:10 +00:00
2a555aedbc Update diagnostics/motor_diagnostics.py 2026-02-13 13:20:52 +00:00
b7bef93301 Update diagnostics/other_functions.py 2026-02-13 13:20:40 +00:00
f66438019e Update diagnostics/battery_diagnostics.py 2026-02-13 13:20:17 +00:00
5e0925b540 Update templates/xbox_controller.py 2026-02-13 13:19:03 +00:00
129bd9af93 Update templates/color_sensor_start_logic.py 2026-02-13 13:18:53 +00:00
540ff62836 Update diagnostics/MicroPythonDiagnostics.py 2026-02-06 14:38:41 +00:00
f5b51cb3aa Update diagnostics/MicroPythonDiagnostics.py 2026-01-30 14:30:56 +00:00
07bbba41e4 Update diagnostics/MicroPythonDiagnostics.py 2026-01-30 13:49:03 +00:00
8c5e90e0ec Update diagnostics/MicroPythonDiagnostics.py 2026-01-29 19:17:50 +00:00
12 changed files with 113 additions and 18 deletions

View File

@@ -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)

View File

@@ -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)

View File

@@ -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):

View 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()

64
tests/pynamics-logger.py Normal file
View File

@@ -0,0 +1,64 @@
# Event codes:
#0: notify
#1: prgm_start
#2: prgm_end
#3: prgm_crash
#4: snsr_data
#5: mtr_data
#6: perf_smpl
#7: get_time
#8: breakpoint
lvldict = {
0: "FATAL",
1: "ALERT",
2: "CRIT",
3: "ERR",
4: "WARNING",
5: "NOTICE",
6: "INFO",
7: "DEBUG"
}
stpwtchtime = StopWatch()
stpwtchtime.pause()
def start():
self.time.reset()
self.time.resume()
def log(self, message, level, origin):
if level <= self.verboseness:
ms = self.time.time()
timestamp = "{:02d}:{:02d}.{:03d}".format(
(ms // 60000) % 60,
(ms // 1000) % 60,
ms % 1000
)
label = self.lvldict.get(level, "UNKNOWN")
padding = " " * (7 - len(label))
print("[{}] {}{} [{}] {}".format(timestamp, label, padding, origin, message))
def sendCommand(eventnum, level, msg, origin):
print(f"\x1b[?PYN;{str(eventnum)};{lvldict[level]};{msg}~")
def notify(level, msg, origin):
print(f"\x1b[?PYN;0;{lvldict[level]};{msg}~")
def fatal(self, message, origin): notify(message, 0, origin)
def alert(self, message, origin): notify(message, 1, origin)
def crit(self, message, origin): notify(message, 2, origin)
def err(self, message, origin): notify(message, 3, origin)
def warning(self, message, origin): notify(message, 4, origin)
def notice(self, message, origin): notify(message, 5, origin)
def info(self, message, origin): notify(message, 6, origin)
def debug(self, message, origin): notify(message, 7, origin)
def crash(self, message, origin):
sendCommand(3, 0, "program kinda crashed bc you suck at coding", origin)
raise FatalLoggerError("[FATAL] [{}] {}".format(origin, message))
sendCommand(0, 0, "hey you should probably know that your RAM is corrupted and you cant buy more because of the shortage. byeeeee", "test prgm")
sendCommand(0, 1, "UNRECOVERABLE PYTHON ERROR!!!!! Exiting gracefully... JUST KIDDING WHAT DID YOU THINK IT WAS GONNA DO", "test prgm")
sendCommand(0, 2, "so the program is running but it just started looping on the motor frying bit of your program.", "test prgm")
sendCommand(0, 3, "syntax error, you failure!!!! use an error checker", "test prgm")
sendCommand(0, 4, "wanted to just say that your motor is kinda being slow", "test prgm")
sendCommand(0, 5, "so your motor is like 1% slower than it should be but really no one cares", "test prgm")
sendCommand(0, 6, "hey everything in the program is going well just in case nothing in your life is", "test prgm")
sendCommand(0, 7, "nobody cares about me but you should know that", "test prgm")
def breakpoint():
#send a command 8 and also get all important info about the code here and print