overvolt

Seguilinea con Alvik

Oct 15th, 2024
483
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.88 KB | None | 0 0
  1. from arduino_alvik import ArduinoAlvik
  2. from time import sleep_ms
  3. import sys
  4.  
  5. robottino = ArduinoAlvik()
  6. robottino.begin()
  7. sleep_ms(100)
  8.  
  9. soglia = 100
  10. velocita = 32
  11. kp = 38.0
  12. dovera=0
  13.  
  14.  
  15. def trova_linea(sx: int, centro: int, dx: int):
  16.     posiz = 0
  17.     totale = sx + centro + dx
  18.     ponderata = sx*1 + centro*2 + dx*3
  19.     if totale != 0:
  20.         posiz = ponderata / totale
  21.         posiz = posiz - 2
  22.     return posiz
  23.  
  24.  
  25. while True:
  26.     sensori = robottino.get_line_sensors()
  27.     scostamento = trova_linea(*sensori)
  28.     correzione = scostamento*kp
  29.     if sensori[0] + sensori[1] + sensori[2] > 200:
  30.         robottino.set_wheels_speed(velocita+correzione,velocita-correzione)
  31.         dovera = -1 if scostamento < 0 else 1
  32.     else:
  33.         robottino.set_wheels_speed(40*dovera,-40*dovera)
  34.         sleep_ms(800)
  35.         dovera=0
  36.         robottino.brake()
  37.     sleep_ms(5)
  38.  
Advertisement
Add Comment
Please, Sign In to add comment