diff options
author | Martin Možina <martin.mozina@fri.uni-lj.si> | 2015-10-14 18:08:44 +0200 |
---|---|---|
committer | Martin Možina <martin.mozina@fri.uni-lj.si> | 2015-10-14 18:08:44 +0200 |
commit | 531bde7a2fe3d643e9b6ffe690405b6cc07c4964 (patch) | |
tree | 9fcdd54ec25cacc32cd5aaacfb731c174278fab8 /robot/problems/introduction/rotateback/naloga11_rotateBack_old.py | |
parent | 1b936a961e39b2a71b5a773776474446f0c58447 (diff) | |
parent | b1deb24a05a380450ed9dc77c3155a16bd204dfc (diff) |
Merge branch 'master' of 192.168.15.97:codeq-problems
Diffstat (limited to 'robot/problems/introduction/rotateback/naloga11_rotateBack_old.py')
-rw-r--r-- | robot/problems/introduction/rotateback/naloga11_rotateBack_old.py | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/robot/problems/introduction/rotateback/naloga11_rotateBack_old.py b/robot/problems/introduction/rotateback/naloga11_rotateBack_old.py new file mode 100644 index 0000000..39ab3bb --- /dev/null +++ b/robot/problems/introduction/rotateback/naloga11_rotateBack_old.py @@ -0,0 +1,56 @@ +#!/usr/bin/python +# coding=utf-8 + +print """ +Naloga 11: +""" + +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]) |