curva a gradi e non di quanto si muove. mi chiamo giovanni ganci
This commit is contained in:
parent
5576e48642
commit
7eaa00e48b
2 changed files with 35 additions and 19 deletions
|
|
@ -7,26 +7,40 @@ from pybricks.tools import wait
|
|||
import batteria
|
||||
from assi import A
|
||||
|
||||
|
||||
def gira_fino_a_quando(gradi: int):
|
||||
posizione_iniziale = db.angle()
|
||||
gradi_mancanti = gradi - posizione_iniziale
|
||||
db.turn(gradi_mancanti)
|
||||
# dangolo = db.angle()
|
||||
# if angolo < gradi:
|
||||
# db.turn(gradi - angolo)
|
||||
|
||||
|
||||
left = Motor(Port.B, Direction.COUNTERCLOCKWISE)
|
||||
right = Motor(Port.A)
|
||||
|
||||
|
||||
hub = PrimeHub(top_side=A.UP, front_side=A.BACKWARD)
|
||||
db = DriveBase(left, right, wheel_diameter=56, axle_track=105)
|
||||
db.use_gyro(True)
|
||||
db.use_gyro(True) # abilitiamo il giroscopio
|
||||
# (mm/s, mm/s², deg/s, deg/s²)
|
||||
db.settings(100, 100, 90, 50)
|
||||
wait(300)
|
||||
db.reset(angle=0)
|
||||
|
||||
db.straight(100)
|
||||
gira_fino_a_quando(90)
|
||||
print(db.angle())
|
||||
db.straight(100)
|
||||
gira_fino_a_quando(180)
|
||||
print(db.angle())
|
||||
db.straight(100)
|
||||
gira_fino_a_quando(270)
|
||||
print(db.angle())
|
||||
db.straight(100)
|
||||
gira_fino_a_quando(360)
|
||||
print(db.angle())
|
||||
|
||||
db.straight(100)
|
||||
db.turn(90)
|
||||
db.straight(100)
|
||||
db.turn(90)
|
||||
db.straight(100)
|
||||
db.turn(90)
|
||||
db.straight(100)
|
||||
db.turn(90)
|
||||
|
||||
print(f"drived {db.distance()}")
|
||||
|
|
|
|||
22
leo/giro.py
22
leo/giro.py
|
|
@ -1,26 +1,26 @@
|
|||
from pybricks.hub import PrimHub
|
||||
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
|
||||
|
||||
# hub = InventorHub(top_side=vector(0, 0, 1), front_side=vector(0, 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)
|
||||
|
||||
|
||||
def vai_avanti(speed, gradi):
|
||||
def vai_avanti(speed: int, gradi: int):
|
||||
print(f"vado avanti di {gradi} a {speed}")
|
||||
mSinistra.run_angle(speed, gradi, then=Stop.NONE, wait=False)
|
||||
mDestra.run_angle(-speed, gradi, then=Stop.NONE, wait=True)
|
||||
|
||||
|
||||
# def turn(speed_L, speed_R, g):
|
||||
# print("girogiro")
|
||||
# mSinistra.run_angle(speed_L, g, then=Stop.NONE, wait=False)
|
||||
# mDestra.run_angle(speed_R, g, then=Stop.NONE, wait=True)
|
||||
def turn(speed_L, speed_R, g):
|
||||
print("girogiro")
|
||||
mSinistra.run_angle(speed_L, g, then=Stop.NONE, wait=False)
|
||||
mDestra.run_angle(speed_R, g, then=Stop.NONE, wait=True)
|
||||
|
||||
|
||||
def precision_turn(g):
|
||||
|
|
@ -41,5 +41,7 @@ def precision_turn(g):
|
|||
|
||||
|
||||
hub.imu.reset_heading(0)
|
||||
print("G: " + str(hub.imu.rotation(Axis.Z)))
|
||||
# precision_turn(90)
|
||||
a = hub.imu.heading()
|
||||
# print("G: " + str(hub.imu.rotation(Axis.Z)))
|
||||
print(a)
|
||||
precision_turn(90)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue