Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from arduino_alvik import ArduinoAlvik
- from time import sleep_ms
- import sys
- robottino = ArduinoAlvik()
- robottino.begin()
- sleep_ms(100)
- soglia = 100
- velocita = 32
- kp = 38.0
- dovera=0
- def trova_linea(sx: int, centro: int, dx: int):
- posiz = 0
- totale = sx + centro + dx
- ponderata = sx*1 + centro*2 + dx*3
- if totale != 0:
- posiz = ponderata / totale
- posiz = posiz - 2
- return posiz
- while True:
- sensori = robottino.get_line_sensors()
- scostamento = trova_linea(*sensori)
- correzione = scostamento*kp
- if sensori[0] + sensori[1] + sensori[2] > 200:
- robottino.set_wheels_speed(velocita+correzione,velocita-correzione)
- dovera = -1 if scostamento < 0 else 1
- else:
- robottino.set_wheels_speed(40*dovera,-40*dovera)
- sleep_ms(800)
- dovera=0
- robottino.brake()
- sleep_ms(5)
Advertisement
Add Comment
Please, Sign In to add comment