From 6a3fb3f5026e38a22560e81af14eaa518dd9d9a1 Mon Sep 17 00:00:00 2001 From: POUDEROUX Tom Date: Sun, 22 Mar 2026 04:49:01 +0100 Subject: [PATCH] Epreuve 5 mk2 --- Interpreteur.py | 34 ++++++++++++++++--------- LED.asm | 0 Path.asm | 65 +++++++++++++++++++++++++----------------------- main.py | 36 ++++++--------------------- notes.txt | 4 +-- out.bin | Bin 48 -> 45 bytes 6 files changed, 65 insertions(+), 74 deletions(-) create mode 100644 LED.asm diff --git a/Interpreteur.py b/Interpreteur.py index 3c05627..2e79e0b 100644 --- a/Interpreteur.py +++ b/Interpreteur.py @@ -13,6 +13,8 @@ import sys, time +import uasyncio as asyncio + class CPU: pc: int = 0 @@ -37,12 +39,16 @@ class Simulator: self.cpu = CPU() self.program_size = len(program) self.motorCallback = None + self.registerCallback = None # ---- Getter / Setter pour interfacer le robot def setMotorCallback(self, callback): self.motorCallback = callback + def setRegisterCallback(self, callback): + self.registerCallback = callback + # ----------------- utilitaires mémoire / pile ----------------- @@ -126,6 +132,8 @@ class Simulator: r = b & 0b11 instr = f"POP R{r}" c.regs[r] = self.pop() + if (setRegisterCallback != None): + setRegisterCallback(r, c.regs[r]) # --- MOV Rx valeur / SUB Rx valeur / CMP Rx valeur --- elif (b & 0b11111100) == 0b11100000: # MOV Rx valeur @@ -134,6 +142,8 @@ class Simulator: size = 2 instr = f"MOV R{r}, {imm}" c.regs[r] = imm + if (setRegisterCallback != None): + setRegisterCallback(r, c.regs[r]) elif (b & 0b11111100) == 0b00010000: # SUB Rx valeur r = b & 0b11 @@ -141,6 +151,8 @@ class Simulator: size = 2 instr = f"SUB R{r}, {imm}" c.regs[r] = (c.regs[r] - imm) & 0xFF + if (setRegisterCallback != None): + setRegisterCallback(r, c.regs[r]) elif (b & 0b11111100) == 0b10010000: # CMP Rx valeur r = b & 0b11 @@ -157,12 +169,16 @@ class Simulator: src = b & 0b11 instr = f"MOV R{dst}, R{src}" c.regs[dst] = c.regs[src] + if (setRegisterCallback != None): + setRegisterCallback(dst, c.regs[dst]) elif (b & 0b11110000) == 0b11010000: # SUB Rx Ry dst = (b >> 2) & 0b11 src = b & 0b11 instr = f"SUB R{dst}, R{src}" c.regs[dst] = (c.regs[dst] - c.regs[src]) & 0xFF + if (setRegisterCallback != None): + setRegisterCallback(dst, c.regs[dst]) elif (b & 0b11110000) == 0b00110000: # CMP Rx Ry dst = (b >> 2) & 0b11 @@ -183,6 +199,8 @@ class Simulator: eff = (addr + c.regs[src]) & 0xFF c.regs[dst] = self.ram[eff] extra_cycles = 1 # 2 octets -> 2 cycles +1 = 3 + if (setRegisterCallback != None): + setRegisterCallback(dst, c.regs[dst]) elif (b & 0b11110000) == 0b01110000: # STR Rx Ry _label dst = (b >> 2) & 0b11 @@ -257,21 +275,13 @@ class Simulator: self.step() steps += 1 -def motorCallback(motG, motD): - sMotG = 1 - ((motG >> 2) & 0b10) - sMotD = 1 - ((motD >> 2) & 0b10) - motG = ((motG & 0b0111) * sMotG) * 100 / 7 - motD = ((motD & 0b0111) * sMotD) * 100 / 7 - print("Mot G :", motG) - print("Mot D :", motD) - - -def StartCPU(program, callback): +def StartCPU(program, callback, registerCallback): sim = Simulator(program) sim.setMotorCallback(callback) + sim.setRegisterCallback(setRegisterCallback) while sim.cpu.running: sim.run(max_steps = 1) - time.sleep(0.1) + #time.sleep(0.1) import time # --------------------------------------------------------- @@ -286,6 +296,6 @@ if __name__ == "__main__": print("filename: " + filename) with open(filename, "rb") as f: program = f.read() - StartCPU(program, motorCallback) + StartCPU(program, None, None) else: print("Needs *.bin as parameter") diff --git a/LED.asm b/LED.asm new file mode 100644 index 0000000..e69de29 diff --git a/Path.asm b/Path.asm index 1a1b273..1e32447 100644 --- a/Path.asm +++ b/Path.asm @@ -1,41 +1,44 @@ _main: ; Start - MOV R0 59 + + MOV R0 17 OUT R0 - TIM 132 ; Demi-tour OK + TIM 130 ; Slow Start OK + + MOV R0 34 + OUT R0 + TIM 130 ; Slow Start OK + + MOV R0 51 + OUT R0 + TIM 162 ; Ligne droite OK + + MOV R0 49 ; 0b 0011 0001 + OUT R0 + TIM 130 ; Rotation droite OK + + MOV R0 51 + OUT R0 + TIM 152 ; Ligne droite + + MOV R0 19 ; 0b 0001 0011 + OUT R0 + TIM 130 ; Rotation gauche + ;TIM 50 + + MOV R0 51 + OUT R0 + TIM 136 ; Ligne droite + + MOV R0 0 - OUT R0 - TIM 100 ; P'tite pause OK - - MOV R0 59 - OUT R0 - TIM 128 - TIM 100 ; Demi-tour pour marche arriere OK - - MOV R0 0 - OUT R0 - TIM 100 ; P'tite pause OK - - MOV R0 204 - OUT R0 - TIM 142 ; Michael Jackson OK - - MOV R0 0 - OUT R0 - TIM 100 ; P'tite pause OK - - MOV R0 179 - OUT R0 - TIM 132 ; Demi-tour + OUT R0 ; STOP + RET +_sleep: MOV R0 0 OUT R0 TIM 100 ; P'tite pause - - MOV R0 204 - OUT R0 - TIM 144 ; Michael Jackson - - RET + RET \ No newline at end of file diff --git a/main.py b/main.py index a3e09b1..730828d 100644 --- a/main.py +++ b/main.py @@ -10,12 +10,11 @@ import buzzer import binascii import uasyncio as asyncio import RobotBleServer -#import base64 - from Interpreteur import StartCPU motorSpeedFactor = 50 +motorDCompensation = 1.04 alphabot = AlphaBot_v2() oled = SSD1306_I2C(128, 64, alphabot.i2c) @@ -23,36 +22,19 @@ oled = SSD1306_I2C(128, 64, alphabot.i2c) oled.fill(0) oled.show() + def motorCallback(motG, motD): sMotG = 1 - ((motG >> 2) & 0b10) sMotD = 1 - ((motD >> 2) & 0b10) motG = ((motG & 0b0111) * sMotG) * motorSpeedFactor / 7 - motD = ((motD & 0b0111) * sMotD) * motorSpeedFactor / 7 + motD = (((motD & 0b0111) * sMotD) * motorSpeedFactor / 7) * motorDCompensation print("Mot G :", motG) print("Mot D :", motD) alphabot.setMotors(left=motG, right=motD) - -# while True: -# joystickButton = alphabot.getJoystickValue() -# if (joystickButton == "center"): -# oled.text("Coucou !", 0, 0) -# oled.show() -# utime.sleep(1) -# oled.fill(0) -# oled.show() -# if (joystickButton == "left"): -# alphabot.setMotors(left=-100, right=100) -# utime.sleep(1) -# alphabot.stop() -# if (joystickButton == "right"): -# StartCPU("./out.bin", motorCallback) -# alphabot.stop() - - - - - +def registerCallback(register, value): + print(f"Register R{register} changed to {value}") + pass @@ -70,13 +52,9 @@ def onMsgToRobot(data:str|bytes): :param data: message received""" checksum = binascii.crc32(data) print('received', data, '=>', checksum) - #data = data.encode("ascii") - #data = base64.decodebytes(data) print(data) - - - StartCPU(data, motorCallback) + StartCPU(data, motorCallback, registerCallback) alphabot.stop() diff --git a/notes.txt b/notes.txt index 23db984..95af3ae 100644 --- a/notes.txt +++ b/notes.txt @@ -162,7 +162,7 @@ toupie 76 100ms = 360 + 90° {"type": "connect", "name": "Nogard"} -{"type": "msg", "format": "base64", "string": "4Crw+FCA"} +{"type": "msg", "format": "base64", "string": "4Dvw+IKA"} Demi tour {"type": "msg", "format": "base64", "string": "4Dvw+IHgAPCA"} @@ -171,6 +171,6 @@ Demi tour + fuite {"type": "msg", "format": "base64", "string": "4Dvw+ID4MuAA8Phk4Mzw+KXgAPDgAPD4ZIA="} Parcours -{"type": "msg", "format": "base64", "string": "4Dvw+ITgAPD4ZOA78PiA+GTgAPD4ZODM8PiO4ADw+GTgs/D4hOAA8Phk4Mzw+JCA"} +{"type": "msg", "format": "base64", "string": "4BHw+ILgIvD4guAz8Pii4DHw+ILgM/D4mOAT8PiC4DPw+IjgAPCA4ADw+GSA"} diff --git a/out.bin b/out.bin index 9e9b4d0bac8725a61a016ce729d4bc8e5814a72a..983ba4197b0bf6ce9666e1f7cf2e2b80ee94d7cd 100644 GIT binary patch literal 45 ncmaDL_~A#>10@h){Ncx<2Zm7Aj0eI{R>uQ|4-G*4Bc%ZV$Cn;Y literal 48 mcmaE0{ozN;1BMSjQXT+V4L}OaKJ(#6AB43TE)Nu&&;S52>LJ_!