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/wall1m/naloga06_wall1m_testing.py | 43 ++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 robot/problems/introduction/wall1m/naloga06_wall1m_testing.py (limited to 'robot/problems/introduction/wall1m/naloga06_wall1m_testing.py') diff --git a/robot/problems/introduction/wall1m/naloga06_wall1m_testing.py b/robot/problems/introduction/wall1m/naloga06_wall1m_testing.py new file mode 100644 index 0000000..a7e449c --- /dev/null +++ b/robot/problems/introduction/wall1m/naloga06_wall1m_testing.py @@ -0,0 +1,43 @@ +#!/usr/bin/python +# coding=utf-8 + +print (""" +Naloga 6: + Robota postavi pred zid, tako da bo od njega oddaljen vsaj 1 m; vmes naj ne bo ovir. + Napisi program, s katerim bo robot vozil naravnost proti zidu z 80% mocjo. + Na razdalji 50 cm od zida naj robot zmanjsa hitrost na 20%, na razdalji 20 cm od zida pa naj se ustavi. +""") +import sys +sys.path.append('/home/user/codeq') +import time +from ev3dev import * +from mindstorms_widgets import mindstorms_widgets + +robot = mindstorms_widgets() +robot.connect_motor( 'left' ) +robot.connect_motor( 'right' ) + +mw=True + +if mw: + robot.connect_sensor( 'ultrasonic' ) + robot.move_steering( 'on', power=80 ) + while robot.ultrasonic_sensor_measure( 'distance-cm' ) > 500: + print(robot.ultrasonic_sensor_measure( 'distance-cm' ) ) + print(robot.ultrasonic_sensor_measure( 'distance-cm' ) ) + robot.move_steering( 'on', power=20 ) + while robot.ultrasonic_sensor_measure( 'distance-cm' ) > 200: + print(robot.ultrasonic_sensor_measure( 'distance-cm' ) ) + robot.move_steering( 'off' ) +else: + us = ultrasonic_sensor() + assert us.connected + us.mode = 'US-DIST-CM' # Continuous measurement of distance (0-2550 mm) + robot.move_steering( 'on', power=80 ) + while us.value()>500: + print( us.value() ) + print( us.value() ) + robot.move_steering( 'on', power=20 ) + while us.value()>200: + print( us.value() ) + robot.move_steering( 'off' ) -- cgit v1.2.1