Stop at line py v2

From wikiluntti
Revision as of 17:10, 9 June 2020 by Mol (talk | contribs) (Created page with "<languages /> <translate> == Introduction == Stop at line is a simple program to demonstrate forwarding moving and color sensor. The robot stops when the color sensor finds...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

<languages />

<translate>

Introduction

Stop at line is a simple program to demonstrate forwarding moving and color sensor. The robot stops when the color sensor finds a darker area.

Robot

This works for almost any robot but the example is made for Asimov.

Sensors

The color sensor is needed. The sensor convention is

  1. port 1 = touch,
  2. port 2 = gyro,
  3. port 3 = color,
  4. port 4 = infrared or ultrasonic

An Illuminating Example Video

Theory

The program uses steering.on() function to set the robot going forward. The while loop checkes if the colour sensor finds a darker area, and quits after finding. There is a small pause in the loop.

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.

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 cl.reflected_light_intensity > 50:
    sleep( 0.01 )

steer_pair.off()
sleep(5)

Exercises

1. Try the script with different velocities. Does it always stop? What is the sampling frequency of the color sensor?

2. Change the program to stop on fourth line. How about tenth line? Does the velocity of the robot change your results?

3. The robot goes a bit over the line. Change the code such that it will stop exactly at the beginning of the line.

</translate>