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 --- .../rotateback/old_naloga11_rotateBack.py | 53 ++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 robot/problems/introduction/rotateback/old_naloga11_rotateBack.py (limited to 'robot/problems/introduction/rotateback/old_naloga11_rotateBack.py') diff --git a/robot/problems/introduction/rotateback/old_naloga11_rotateBack.py b/robot/problems/introduction/rotateback/old_naloga11_rotateBack.py new file mode 100644 index 0000000..a14c91d --- /dev/null +++ b/robot/problems/introduction/rotateback/old_naloga11_rotateBack.py @@ -0,0 +1,53 @@ +#!/usr/bin/python +# coding=utf-8 +import sys +sys.path.append('/home/user/codeq') +import time +from ev3dev import * +from mindstorms_widgets import mindstorms_widgets + +# the sensor should be perfectly still while resetting the gyro +def resetGyro(gyro): + gyro.mode = 'GYRO-RATE' + gyro.mode = 'GYRO-ANG' + +def sgn(x): + return -1 if x<0 else (1 if x>0 else 0) + +gyro = gyro_sensor() +assert gyro.connected +gyro.mode = 'GYRO-ANG' + +touch = touch_sensor() +assert touch.connected + +robot = mindstorms_widgets() +robot.connect_motor( 'left' ) +robot.connect_motor( 'right' ) + +smer = hitrost = 0 +resetGyro(gyro) +prev_smer = -1 +while 1: + smer = gyro.value() + if smer!=prev_smer: + print ("Kot:", smer) + prev_smer = smer + + if touch.value(): + resetGyro(gyro) + print( gyro.value()) + + if abs(smer) < 10: + hitrost = 10*sgn(smer) + else: + if abs(smer) > 100: + hitrost = 100*sgn(smer) + else: + hitrost = smer + + if abs(smer) > 1: + L, R = -hitrost, hitrost + else: + L = R = 0 + robot.move_tank('on', lr_power=[L,R]) -- cgit v1.2.1