From 1e5d42ba53ea0c631dbc6f21887839c91571ebca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=BDabkar?= Date: Tue, 13 Oct 2015 12:24:41 +0200 Subject: Uvodne vaje za robotiko --- .../introduction/countlines/naloga10_countLines.py | 37 ++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 robot/problems/introduction/countlines/naloga10_countLines.py (limited to 'robot/problems/introduction/countlines/naloga10_countLines.py') diff --git a/robot/problems/introduction/countlines/naloga10_countLines.py b/robot/problems/introduction/countlines/naloga10_countLines.py new file mode 100644 index 0000000..d1a8326 --- /dev/null +++ b/robot/problems/introduction/countlines/naloga10_countLines.py @@ -0,0 +1,37 @@ +#!/usr/bin/python +# coding=utf-8 + +print """ +Naloga 10: + Robot naj se pelje naravnost, pravokotno na crte in naj jih presteje. +""" + +import time +from ev3dev import * +from mindstorms_widgets import mindstorms_widgets + +color_table = ['none', 'black', 'blue', 'green', 'yellow', 'red', 'white', 'brown'] + +cs = color_sensor() +assert cs.connected +cs.mode = 'COL-COLOR' # values: 0-7 see the scale above + +robot = mindstorms_widgets() +robot.connect_motor( 'left' ) +robot.connect_motor( 'right' ) + +power = 30 + +robot.move_tank( 'on', lr_power=[power,power]) +start = time.time() +stevec = 0 +color = -1 +while time.time()-start < 2.1: + c = cs.value() + if c!=color: + print c, color_table[c] + if c!=6 and c!=0: + stevec += 1 + color = c +robot.move_tank( 'off', brake_at_end=True ) +print "Stevilo crt:", stevec \ No newline at end of file -- cgit v1.2.1