Line follower proportional py v2/fi: Difference between revisions

From wikiluntti
(Created page with "4. Yllä esityssä koodissa robotti jatkaa matkaansa ''ikuisesti''. Laita robotti pysähtymään, kun oikea rengas on kiertänyt 3,4 kierrosta. Katso [https://sites.google.com...")
(Created page with "5. Käske robottia pysähtymään, kun valoanturi on hopeateipin päällä.")
Line 78: Line 78:
4. Yllä esityssä koodissa robotti jatkaa matkaansa ''ikuisesti''. Laita robotti pysähtymään, kun oikea rengas on kiertänyt 3,4 kierrosta. Katso [https://sites.google.com/site/ev3devpython/learn_ev3_python/using-motors]-sivulta apua.
4. Yllä esityssä koodissa robotti jatkaa matkaansa ''ikuisesti''. Laita robotti pysähtymään, kun oikea rengas on kiertänyt 3,4 kierrosta. Katso [https://sites.google.com/site/ev3devpython/learn_ev3_python/using-motors]-sivulta apua.


5. Let the robot end when it encounters a silver tape (highly shiny).
5. Käske robottia pysähtymään, kun valoanturi on hopeateipin päällä.


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.
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.

Revision as of 18:00, 23 September 2020

<languages />


Johdanto

Robotti

Ideat ja periaatteet toimivat lähes kaikille roboteille, mutta tämä on testattu Asimovilla.

Anturit

Käytetään vrisensoria reflected light intensity -moodissa, ja portissa numero 3.

Esimerkki

Teoriaa

Itseasiassa verrannollinenkin viivanseuraajaa seuraa vain viivan toista puolta. Robotin kääntöarvo (lähes kääntösäde) lasketaan anturin suurimmasta, pienimmästä ja tämänhetkisestä arvosta. Verrannollisuuskerroin P kertoo, kuinka nopeasti robotti kääntyy.

Python v2:ssa ohjausfunktion arvot pitävät olla välillä -100...100, joka saadaan aikaiseksi Pythonin Min- ja Max-funktioilla.

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
import os

os.system('setfont Lat15-TerminusBold32x16') 

steer_pair = MoveSteering(OUTPUT_B, OUTPUT_C)
steer_pair.on(steering=0, speed=10)

cl = ColorSensor() 
clMax = 84
clMin = 30
clAve = (clMax + clMin)/2
P = 2.0

clN = clAve
steering = 0

while True:
    clN = cl.reflected_light_intensity
    #print( clN )
    #print( clAve )
    steering = P*( clN - clAve )
    steering = min(steering, 100)
    steering = max(steering, -100)
    print( steering )
    steer_pair.on(steering=steering, speed=20)

steer_pair.off()
sleep(5)

Harjoituksia

1. Robotin debuggaus helpottuu, kun saat sen puhumaan. Käytä Sound.speak("White").wait() -käskyä jotta saat kertomaan mitä se näkee. Voit käyttää myös sound.beep()-käskyä. Äänikirjasto pitää importata import Sound -käskyllä.

2. Optimoi robotti kulkemaan nopeammin. Huomaa, robotti, viiva ja valoisuus vaikuttavat nopeuteen. Yleensä kannattaa muuttaa vain yhtä arvoa koodista kerralla. Yritä puolittaa alkuperäinen aika.

3. Käytä viivan toista puolta.

4. Yllä esityssä koodissa robotti jatkaa matkaansa ikuisesti. Laita robotti pysähtymään, kun oikea rengas on kiertänyt 3,4 kierrosta. Katso [1]-sivulta apua.

5. Käske robottia pysähtymään, kun valoanturi on hopeateipin päällä.

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.


Meet and Code II: Python