Line follower Zigzag py v2/fi
<languages />
Johdanto
Robotti
Ideat ja periaatteet toimivat lähes kaikille roboteille, mutta tämä on testattu Asimovilla.
Anturit
Käytetään värianturia reflected light intensity -moodissa, portissa numero 3.
An Illuminating Example
Teoriaa
ZigZag-viivanseuraajaa itseasiassa seuraa viivan jompaa kumpaa reunaa. Ajatus on, että jos anturin lukema on pienempi kuin jokin raja-arvo (esimerkiksi 50), robotti kääntyy vasemmalle. Jos anturin arvo on taas suurempi, se kääntyy oikealle.
Esimerkkikoodi
#!/usr/bin/env python3
# https://sites.google.com/site/ev3devpython/
#Sensor port convention:
#port 3 = color
#port 1 = touch, port 2 = gyro, port 3 = color, port 4 = infrared or ultrasonic.
#84 is Max
#30 is Min
from ev3dev2.sensor.lego import ColorSensor
from ev3dev2.motor import MoveSteering, OUTPUT_B, OUTPUT_C
from time import sleep
steer_pair = MoveSteering(OUTPUT_B, OUTPUT_C)
steer_pair.on(steering=0, speed=10)
cl = ColorSensor()
while True:
if cl.reflected_light_intensity > 50:
steer_pair.on(steering=55, speed=10)
else:
steer_pair.on(steering=-55, speed=10)
steer_pair.off()
sleep(5)
Harjoituksia
1. Robotin debuggaus on helpompaa, jos se puhuu meille. Käytä pythonin Sound.speak('White').wait() -komentoa tai vaikkapa komentoa sound.beep(), jolla saat sen puhumaan, kun anturi on valkoisen päällä. Muista importata käsky.
2. Laita robotti liikkumaan nopeammin. Huomaa, että parametrit riippuvat sekä viivasta, robotista että valaistuksesta. Yleensä kannattaa muuttaa yhtä arvoa kerrallaan. Kellota alkuperäinen aika, ja yritä puolittaa se.
3. Let the robot use the other side of the line.
4. Now the while loop is forever. Make the robot stop when the right has turned 3.4 revolutions. See ev3 Python for help.
5. Let the robot end when it encounters a silver tape (highly shiny).
6. The Rescue is robot game such that it needs to follow the dashed line. So, make a line with a segment missing, but make your robot to still overlap the missing segment and follow the line on the other side of the missing segment.
About
This course is supported by Meet and Code. The course is made in collaboration with Robotiikka- ja tiedekasvatus ry.
