Line follower Zigzag py v2: Difference between revisions
(Created page with "<languages /> <translate> == Introduction == === Robot === The idea and principle works for almost any robot thought this is tested using Asimov. === Sensors === The color...") |
No edit summary |
||
Line 72: | Line 72: | ||
[[Category: Color sensor py v2]] | [[Category: Color sensor py v2]] | ||
[[Category: Asimov]] | [[Category: Asimov]] | ||
== About == | |||
This course is supported by [https://meet-and-code.org/ Meet and Code]. The course is made in collaboration with [http://www.fllsuomi.org/ Robotiikka- ja tiedekasvatus ry]. | |||
[[File:MeetAndcodeLogo.png|thumb]] | |||
</translate> | </translate> | ||
[[Meet_and_Code_2020_II:_Python | Meet and Code II: Python]] |
Revision as of 21:33, 22 September 2020
<languages />
<translate>
Introduction
Robot
The idea and principle works for almost any robot thought this is tested using Asimov.
Sensors
The color sensor in reflected light intensity mode is used. The sensor convention is
- port 1 = touch,
- port 2 = gyro,
- port 3 = color,
- port 4 = infrared or ultrasonic
An Illuminating Example
Theory
The zigzag line follower actually follows the other side of the line. If the intensity obtained by the sensor is greater than some threshold value (now 50), it will turn right some amount (now 55). Otherwise, if the the intensity is lower the robot turns steering to left (negative value).
An Example Code
#!/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)
Exercises
1. It is difficult to debug the robot as it is silent. Let it say if it is in dark or light area. Use Sound.speak('White').wait() command or e.g. sound.beep() command. Sound is imported using import Sound command.
2. Make the robot move faster. Note that you need to change the parameters according to your line to follow (and robot). Generally, it is advised to change only one value at time. Time your original time and try to make it half.
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.
</translate>