From f4a83747c2da0d47a92e18d97b9e985795e2e834 Mon Sep 17 00:00:00 2001 From: leo Date: Sun, 28 Sep 2025 20:02:19 +0200 Subject: [PATCH] tentativo di aggiustare il giroscopio --- leo/giro.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/leo/giro.py b/leo/giro.py index 0b7e3d8..101957c 100644 --- a/leo/giro.py +++ b/leo/giro.py @@ -1,11 +1,11 @@ from pybricks.hubs import InventorHub from pybricks.parameters import Axis, Port, Stop from pybricks.pupdevices import Motor -from pybricks.tools import vector -# from pybricks.hub import PrimHub +##from pybricks.hub import PrimHub -hub = InventorHub(top_side=vector(1, 1, 0), front_side=vector(-1, 1, 0)) +# hub = InventorHub(top_side=vector(0, 0, 1), front_side=vector(0, 1, 0)) +hub = InventorHub(top_side=Axis.Z, front_side=Axis.Y) mDestra = Motor(Port.A) mSinistra = Motor(Port.B) @@ -25,20 +25,21 @@ def vai_avanti(speed, gradi): def precision_turn(g): while True: - gradi = hub.imu.rotation(Axis.Z) + gradi = hub.imu.heading() print(f"gradi: {gradi}") speed = g - gradi + print(speed) if g < 0: mSinistra.run_angle(speed, g, then=Stop.NONE, wait=False) - mDestra.run_angle(speed, g, then=Stop.NONE, wait=True) + mDestra.run_angle(speed, g, then=Stop.NONE, wait=False) elif g > 0: mSinistra.run_angle(speed, g, then=Stop.NONE, wait=False) - mDestra.run_angle(speed, g, then=Stop.NONE, wait=True) + mDestra.run_angle(speed, g, then=Stop.NONE, wait=False) - if gradi == g: + if speed < 1 and speed > -1: break -# reset_yaw() +hub.imu.reset_heading(0) print("G: " + str(hub.imu.rotation(Axis.Z))) -precision_turn(90) +# precision_turn(90)