From 1a7678b37a25a76aeaef7ebb225f85406b19f928 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=BDabkar?= Date: Mon, 12 Oct 2015 14:16:14 +0200 Subject: malenkosti... --- robot/problems/introduction/forward/common.py | 52 ++++++++++++++++++++------- robot/problems/introduction/forward/en.py | 21 ++++------- robot/problems/introduction/forward/sl.py | 31 ++++++++-------- 3 files changed, 62 insertions(+), 42 deletions(-) (limited to 'robot/problems') diff --git a/robot/problems/introduction/forward/common.py b/robot/problems/introduction/forward/common.py index 5023d7f..d1e1193 100644 --- a/robot/problems/introduction/forward/common.py +++ b/robot/problems/introduction/forward/common.py @@ -1,6 +1,8 @@ # coding=utf-8 -from server.hints import Hint +from python.util import has_token_sequence, string_almost_equal, \ + string_contains_number, get_tokens, get_numbers, get_exception_desc +from server.hints import Hint, HintSequence id = 202 group = 'introduction' @@ -13,21 +15,47 @@ from ev3dev import * from mindstorms_widgets import mindstorms_widgets robot = mindstorms_widgets() -robot.connect_motor('left') -robot.connect_motor('right') +robot.connect_motor( 'left' ) +robot.connect_motor( 'right' ) -robot.move_steering('on', power=50) -time.sleep(3) -robot.move_steering('off', brake_at_end=True) +robot.move_steering( 'on_for_seconds', direction=0, seconds=3 ) ''' hint_type = { - 'ev3dev': Hint('ev3dev'), - 'mindWidgets': Hint('mindWidgets'), + 'mW_init': Hint('mW_init'), + 'connectMotorLeft': Hint('connectMotorLeft'), + 'connectMotorRight': Hint('connectMotorRight'), + 'moveSteering': Hint('moveSteering'), + 'onForSeconds': Hint('onForSeconds'), + 'direction': Hint('direction'), + 'seconds': Hint('seconds'), } -def test(program): - return False, [] +def hint( code): + tokens = get_tokens(code) -def hint(program): - return [] + # if code does not include mindstorms_widgets(), a student gets a hint that the robot should be somehow represented in the program + if not has_token_sequence(tokens, ['mindstorms_widgets', '(',')']): + return [{'id': 'mW_init'}] + + # if code does not include connect_motor statement, a student needs to learn about how to connect the motors + if not has_token_sequence(tokens, ['connect_motor']) and not has_token_sequence(tokens, ['left']): + return [{'id': 'connectMotorLeft'}] + + # if code does not include connect_motor statement, a student needs to learn about how to connect the motors + if not has_token_sequence(tokens, ['connect_motor']) and not has_token_sequence(tokens, ['right']): + return [{'id': 'connectMotorRight'}] + + if not has_token_sequence(tokens, ['move_steering']): + return [{'id': 'moveSteering'}] + + if not has_token_sequence(tokens, ['on_for_seconds']): + return [{'id': 'onForSeconds'}] + + if not has_token_sequence(tokens, ['direction']): + return [{'id': 'direction'}] + + if not has_token_sequence(tokens, ['seconds']): + return [{'id': 'seconds'}] + + return None diff --git a/robot/problems/introduction/forward/en.py b/robot/problems/introduction/forward/en.py index d943867..f8e1730 100644 --- a/robot/problems/introduction/forward/en.py +++ b/robot/problems/introduction/forward/en.py @@ -1,24 +1,15 @@ # coding=utf-8 +import server +mod = server.problems.load_language('python', 'en') id = 202 -name = 'Forward' -slug = 'Forward' +name = 'Forward 3s' +slug = 'Forward 3s' description = '''\ -

Robot should drive forward in a straight line and stop after three -seconds.

+

Write a program that would make the robot drive straight forward for 3 seconds and stop

''' -plan = [] - hint = { - 'ev3dev': '''\ -

To work with the robot you should import the ev3dev module: -from ev3dev import *.

-''', - - 'mindWidgets': '''\ -

To work with the robot you should import the mindstorms_widgets module: -from mindstorms_widgets import mindstorms_widgets.

-''', + } diff --git a/robot/problems/introduction/forward/sl.py b/robot/problems/introduction/forward/sl.py index 98f3a8d..9a37b3c 100644 --- a/robot/problems/introduction/forward/sl.py +++ b/robot/problems/introduction/forward/sl.py @@ -1,23 +1,24 @@ # coding=utf-8 +import server +mod = server.problems.load_language('python', 'sl') id = 202 -name = 'Naprej' -slug = 'Naprej' +name = 'Naprej 3s' +slug = 'Naprej 3s' description = '''\ -

Robot naj pelje naravnost naprej in se po treh sekundah ustavi.

-''' - -plan = [] +

Napiši program, da bo robot peljal naravnost naprej 3 sekunde in se nato ustavil.

''' hint = { - 'ev3dev': '''\ -

Za delo z robotom moramo uvoziti modul ev3dev: -from ev3dev import *.

-''', - - 'mindWidgets': '''\ -

Za delo z robotom moramo uvoziti modul mindstorms_widgets: -from mindstorms_widgets import mindstorms_widgets.

-''', + 'mW_init':['''

Robota v programu predstavimo z mindstorms_widgets(): robot = mindstorms_widgets().

'''], + 'connectMotorLeft':['''

Robotu moramo priključiti levi motor: robot.connect_motor( 'left' ).

'''], + 'connectMotorRight':['''

Robotu moramo priključiti desni motor: robot.connect_motor( 'right' ).

'''], + 'moveSteering':['''

Sinhroniziraj motorja in ju zaženi za 3 sekunde.

''', + '''

Za sinhronizirano vožnjo je najbolj primerna metoda robot.move_steering( ... ).

'''], + 'onForSeconds':['''

Prvi argument metode robot.move_steering naj pove, da bo delovanje motorjev časovno omejeno.

''', + '''

robot.move_steering('on_for_seconds', ... ).

'''], + 'direction':['''

Navedi smer premikanja motorjev, naravnost = 0.

''', + '''

robot.move_steering( 'on_for_seconds', direction=0, ... ).

'''], + 'seconds':['''

Napiši časovno omejitev v sekundah.

''', + '''

robot.move_steering( 'on_for_seconds', direction=0, seconds=3 ).

'''], } -- cgit v1.2.1 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 --- robot/problems/introduction/circle20/common.py | 62 ++++ robot/problems/introduction/circle20/common.py~ | 63 ++++ robot/problems/introduction/circle20/en.py | 14 + .../introduction/circle20/naloga05_circle20.py | 13 + robot/problems/introduction/circle20/sl.py | 26 ++ robot/problems/introduction/circle20/sl.py~ | 24 ++ robot/problems/introduction/countlines/common.py | 79 ++++ robot/problems/introduction/countlines/common.py~ | 79 ++++ robot/problems/introduction/countlines/en.py | 14 + .../introduction/countlines/naloga10_countLines.py | 37 ++ robot/problems/introduction/countlines/sl.py | 26 ++ robot/problems/introduction/countlines/sl.py~ | 29 ++ robot/problems/introduction/followline/common.py | 85 +++++ robot/problems/introduction/followline/common.py~ | 85 +++++ robot/problems/introduction/followline/en.py | 14 + .../introduction/followline/naloga12_followLine.py | 31 ++ robot/problems/introduction/followline/sl.py | 34 ++ robot/problems/introduction/followline/sl.py~ | 35 ++ robot/problems/introduction/forward/common.py | 7 +- robot/problems/introduction/forward/common.py~ | 60 ++++ robot/problems/introduction/forward/en.py~ | 20 ++ robot/problems/introduction/forward/sl.py | 6 +- robot/problems/introduction/forward/sl.py~ | 23 ++ robot/problems/introduction/forward1m/common.py | 60 ++++ robot/problems/introduction/forward1m/common.py~ | 61 ++++ robot/problems/introduction/forward1m/en.py | 15 + robot/problems/introduction/forward1m/sl.py | 23 ++ robot/problems/introduction/forward1m/sl.py~ | 24 ++ robot/problems/introduction/gyro90/common.py | 80 +++++ robot/problems/introduction/gyro90/common.py~ | 80 +++++ robot/problems/introduction/gyro90/en.py | 15 + .../introduction/gyro90/naloga07_gyro90.py | 25 ++ .../introduction/gyro90/naloga07_gyro90.py~ | 34 ++ robot/problems/introduction/gyro90/sl.py | 29 ++ robot/problems/introduction/gyro90/sl.py~ | 32 ++ robot/problems/introduction/gyrosquare/common.py | 103 ++++++ robot/problems/introduction/gyrosquare/common.py~ | 103 ++++++ robot/problems/introduction/gyrosquare/en.py | 14 + .../introduction/gyrosquare/naloga08_gyroSquare.py | 33 ++ robot/problems/introduction/gyrosquare/sl.py | 38 ++ robot/problems/introduction/gyrosquare/sl.py~ | 40 +++ robot/problems/introduction/inline.py | 19 + .../introduction/mindstorms_widgets_OLD.py | 398 +++++++++++++++++++++ robot/problems/introduction/printcolors/common.py | 80 +++++ robot/problems/introduction/printcolors/common.py~ | 80 +++++ robot/problems/introduction/printcolors/en.py | 15 + .../printcolors/naloga09_printColors.py | 42 +++ robot/problems/introduction/printcolors/sl.py | 36 ++ robot/problems/introduction/printcolors/sl.py~ | 37 ++ robot/problems/introduction/rotateback/common.py | 111 ++++++ robot/problems/introduction/rotateback/common.py~ | 111 ++++++ robot/problems/introduction/rotateback/en.py | 15 + .../introduction/rotateback/naloga11_rotateBack.py | 48 +++ .../rotateback/naloga11_rotateBack_old.py | 56 +++ .../rotateback/old_naloga11_rotateBack.py | 53 +++ robot/problems/introduction/rotateback/sl.py | 33 ++ robot/problems/introduction/rotateback/sl.py~ | 36 ++ robot/problems/introduction/spotturn90/common.py | 60 ++++ robot/problems/introduction/spotturn90/common.py~ | 61 ++++ robot/problems/introduction/spotturn90/en.py | 14 + .../spotturn90/naloga03_turnOnSpotRight90.py | 23 ++ robot/problems/introduction/spotturn90/sl.py | 21 ++ robot/problems/introduction/spotturn90/sl.py~ | 24 ++ robot/problems/introduction/square20/common.py | 76 ++++ robot/problems/introduction/square20/common.py~ | 76 ++++ robot/problems/introduction/square20/en.py | 14 + .../introduction/square20/naloga04_square20.py | 21 ++ robot/problems/introduction/square20/sl.py | 29 ++ robot/problems/introduction/square20/sl.py~ | 27 ++ robot/problems/introduction/wall1m/common.py | 80 +++++ robot/problems/introduction/wall1m/common.py~ | 80 +++++ robot/problems/introduction/wall1m/en.py | 14 + .../introduction/wall1m/naloga06_wall1m.py | 27 ++ .../introduction/wall1m/naloga06_wall1m.py~ | 31 ++ .../introduction/wall1m/naloga06_wall1m_testing.py | 43 +++ robot/problems/introduction/wall1m/sl.py | 31 ++ robot/problems/introduction/wall1m/sl.py~ | 31 ++ 77 files changed, 3622 insertions(+), 6 deletions(-) create mode 100644 robot/problems/introduction/circle20/common.py create mode 100644 robot/problems/introduction/circle20/common.py~ create mode 100644 robot/problems/introduction/circle20/en.py create mode 100644 robot/problems/introduction/circle20/naloga05_circle20.py create mode 100644 robot/problems/introduction/circle20/sl.py create mode 100644 robot/problems/introduction/circle20/sl.py~ create mode 100644 robot/problems/introduction/countlines/common.py create mode 100644 robot/problems/introduction/countlines/common.py~ create mode 100644 robot/problems/introduction/countlines/en.py create mode 100644 robot/problems/introduction/countlines/naloga10_countLines.py create mode 100644 robot/problems/introduction/countlines/sl.py create mode 100644 robot/problems/introduction/countlines/sl.py~ create mode 100644 robot/problems/introduction/followline/common.py create mode 100644 robot/problems/introduction/followline/common.py~ create mode 100644 robot/problems/introduction/followline/en.py create mode 100644 robot/problems/introduction/followline/naloga12_followLine.py create mode 100644 robot/problems/introduction/followline/sl.py create mode 100644 robot/problems/introduction/followline/sl.py~ create mode 100644 robot/problems/introduction/forward/common.py~ create mode 100644 robot/problems/introduction/forward/en.py~ create mode 100644 robot/problems/introduction/forward/sl.py~ create mode 100644 robot/problems/introduction/forward1m/common.py create mode 100644 robot/problems/introduction/forward1m/common.py~ create mode 100644 robot/problems/introduction/forward1m/en.py create mode 100644 robot/problems/introduction/forward1m/sl.py create mode 100644 robot/problems/introduction/forward1m/sl.py~ create mode 100644 robot/problems/introduction/gyro90/common.py create mode 100644 robot/problems/introduction/gyro90/common.py~ create mode 100644 robot/problems/introduction/gyro90/en.py create mode 100644 robot/problems/introduction/gyro90/naloga07_gyro90.py create mode 100644 robot/problems/introduction/gyro90/naloga07_gyro90.py~ create mode 100644 robot/problems/introduction/gyro90/sl.py create mode 100644 robot/problems/introduction/gyro90/sl.py~ create mode 100644 robot/problems/introduction/gyrosquare/common.py create mode 100644 robot/problems/introduction/gyrosquare/common.py~ create mode 100644 robot/problems/introduction/gyrosquare/en.py create mode 100644 robot/problems/introduction/gyrosquare/naloga08_gyroSquare.py create mode 100644 robot/problems/introduction/gyrosquare/sl.py create mode 100644 robot/problems/introduction/gyrosquare/sl.py~ create mode 100644 robot/problems/introduction/inline.py create mode 100644 robot/problems/introduction/mindstorms_widgets_OLD.py create mode 100644 robot/problems/introduction/printcolors/common.py create mode 100644 robot/problems/introduction/printcolors/common.py~ create mode 100644 robot/problems/introduction/printcolors/en.py create mode 100644 robot/problems/introduction/printcolors/naloga09_printColors.py create mode 100644 robot/problems/introduction/printcolors/sl.py create mode 100644 robot/problems/introduction/printcolors/sl.py~ create mode 100644 robot/problems/introduction/rotateback/common.py create mode 100644 robot/problems/introduction/rotateback/common.py~ create mode 100644 robot/problems/introduction/rotateback/en.py create mode 100644 robot/problems/introduction/rotateback/naloga11_rotateBack.py create mode 100644 robot/problems/introduction/rotateback/naloga11_rotateBack_old.py create mode 100644 robot/problems/introduction/rotateback/old_naloga11_rotateBack.py create mode 100644 robot/problems/introduction/rotateback/sl.py create mode 100644 robot/problems/introduction/rotateback/sl.py~ create mode 100644 robot/problems/introduction/spotturn90/common.py create mode 100644 robot/problems/introduction/spotturn90/common.py~ create mode 100644 robot/problems/introduction/spotturn90/en.py create mode 100644 robot/problems/introduction/spotturn90/naloga03_turnOnSpotRight90.py create mode 100644 robot/problems/introduction/spotturn90/sl.py create mode 100644 robot/problems/introduction/spotturn90/sl.py~ create mode 100644 robot/problems/introduction/square20/common.py create mode 100644 robot/problems/introduction/square20/common.py~ create mode 100644 robot/problems/introduction/square20/en.py create mode 100644 robot/problems/introduction/square20/naloga04_square20.py create mode 100644 robot/problems/introduction/square20/sl.py create mode 100644 robot/problems/introduction/square20/sl.py~ create mode 100644 robot/problems/introduction/wall1m/common.py create mode 100644 robot/problems/introduction/wall1m/common.py~ create mode 100644 robot/problems/introduction/wall1m/en.py create mode 100644 robot/problems/introduction/wall1m/naloga06_wall1m.py create mode 100644 robot/problems/introduction/wall1m/naloga06_wall1m.py~ create mode 100644 robot/problems/introduction/wall1m/naloga06_wall1m_testing.py create mode 100644 robot/problems/introduction/wall1m/sl.py create mode 100644 robot/problems/introduction/wall1m/sl.py~ (limited to 'robot/problems') diff --git a/robot/problems/introduction/circle20/common.py b/robot/problems/introduction/circle20/common.py new file mode 100644 index 0000000..661d43a --- /dev/null +++ b/robot/problems/introduction/circle20/common.py @@ -0,0 +1,62 @@ +# coding=utf-8 + +from python.util import has_token_sequence, string_almost_equal, \ + string_contains_number, get_tokens, get_numbers, get_exception_desc +from server.hints import Hint, HintSequence + +id = 205 +group = 'introduction' +number = 5 +visible = True + +solution = '''\ +from ev3dev import * +from mindstorms_widgets import mindstorms_widgets + +robot = mindstorms_widgets() +robot.connect_motor( 'left' ) +robot.connect_motor( 'right' ) + +fct = 9 # full circle time +rad = 20 # Direction to make a good radius for the circle +robot.move_steering( 'on_for_seconds', direction=rad, power=40, seconds=fct ) +''' + +hint_type = { + 'mW_init': Hint('mW_init'), + 'connectMotorLeft': Hint('connectMotorLeft'), + 'connectMotorRight': Hint('connectMotorRight'), + 'moveSteering': Hint('moveSteering'), + 'onForSeconds': Hint('onForSeconds'), + 'direction': Hint('direction'), + 'seconds': Hint('seconds'), +} + +def hint( code): + tokens = get_tokens(code) + + # if code does not include mindstorms_widgets(), a student gets a hint that the robot should be somehow represented in the program + if not has_token_sequence(tokens, ['mindstorms_widgets', '(',')']): + return [{'id': 'mW_init'}] + + # if code does not include connect_motor statement, a student needs to learn about how to connect the motors + if not has_token_sequence(tokens, ['connect_motor']) and not has_token_sequence(tokens, ['left']): + return [{'id': 'connectMotorLeft'}] + + # if code does not include connect_motor statement, a student needs to learn about how to connect the motors + if not has_token_sequence(tokens, ['connect_motor']) and not has_token_sequence(tokens, ['right']): + return [{'id': 'connectMotorRight'}] + + if not has_token_sequence(tokens, ['move_steering']): + return [{'id': 'moveSteering'}] + + if not 'on_for_seconds' in code: + return [{'id': 'onForSeconds'}] + + if not 'direction' in code: + return [{'id': 'direction'}] + + if not 'seconds' in code: + return [{'id': 'seconds'}] + + return None diff --git a/robot/problems/introduction/circle20/common.py~ b/robot/problems/introduction/circle20/common.py~ new file mode 100644 index 0000000..eb171ae --- /dev/null +++ b/robot/problems/introduction/circle20/common.py~ @@ -0,0 +1,63 @@ +# coding=utf-8 + +from python.util import has_token_sequence, string_almost_equal, \ + string_contains_number, get_tokens, get_numbers, get_exception_desc +from server.hints import Hint, HintSequence + +id = 205 +group = 'introduction' +number = 5 +visible = True + +solution = '''\ +import time +from ev3dev import * +from mindstorms_widgets import mindstorms_widgets + +robot = mindstorms_widgets() +robot.connect_motor( 'left' ) +robot.connect_motor( 'right' ) + +fct = 9 # full circle time +rad = 20 # Direction to make a good radius for the circle +robot.move_steering( 'on_for_seconds', direction=rad, power=40, seconds=fct ) +''' + +hint_type = { + 'mW_init': Hint('mW_init'), + 'connectMotorLeft': Hint('connectMotorLeft'), + 'connectMotorRight': Hint('connectMotorRight'), + 'moveSteering': Hint('moveSteering'), + 'onForSeconds': Hint('onForSeconds'), + 'direction': Hint('direction'), + 'seconds': Hint('seconds'), +} + +def hint( code): + tokens = get_tokens(code) + + # if code does not include mindstorms_widgets(), a student gets a hint that the robot should be somehow represented in the program + if not has_token_sequence(tokens, ['mindstorms_widgets', '(',')']): + return [{'id': 'mW_init'}] + + # if code does not include connect_motor statement, a student needs to learn about how to connect the motors + if not has_token_sequence(tokens, ['connect_motor']) and not has_token_sequence(tokens, ['left']): + return [{'id': 'connectMotorLeft'}] + + # if code does not include connect_motor statement, a student needs to learn about how to connect the motors + if not has_token_sequence(tokens, ['connect_motor']) and not has_token_sequence(tokens, ['right']): + return [{'id': 'connectMotorRight'}] + + if not has_token_sequence(tokens, ['move_steering']): + return [{'id': 'moveSteering'}] + + if not has_token_sequence(tokens, ['on_for_seconds']): + return [{'id': 'onForSeconds'}] + + if not has_token_sequence(tokens, ['direction']): + return [{'id': 'direction'}] + + if not has_token_sequence(tokens, ['seconds']): + return [{'id': 'seconds'}] + + return None diff --git a/robot/problems/introduction/circle20/en.py b/robot/problems/introduction/circle20/en.py new file mode 100644 index 0000000..8210d71 --- /dev/null +++ b/robot/problems/introduction/circle20/en.py @@ -0,0 +1,14 @@ +# coding=utf-8 +import server +mod = server.problems.load_language('python', 'en') + +id = 205 +name = 'Circle 20 cm' +slug = 'Circle 20 cm' + +description = '''\ +''' + +hint = { + +} diff --git a/robot/problems/introduction/circle20/naloga05_circle20.py b/robot/problems/introduction/circle20/naloga05_circle20.py new file mode 100644 index 0000000..e95d4f4 --- /dev/null +++ b/robot/problems/introduction/circle20/naloga05_circle20.py @@ -0,0 +1,13 @@ +#!/usr/bin/python + +import time +from ev3dev import * +from mindstorms_widgets import mindstorms_widgets + +robot = mindstorms_widgets() +robot.connect_motor( 'left' ) +robot.connect_motor( 'right' ) + +fct = 9 # full circle time +rad = 20 # Direction to make a good radius for the circle +robot.move_steering( 'on_for_seconds', direction=rad, power=40, seconds=fct ) \ No newline at end of file diff --git a/robot/problems/introduction/circle20/sl.py b/robot/problems/introduction/circle20/sl.py new file mode 100644 index 0000000..219f9c7 --- /dev/null +++ b/robot/problems/introduction/circle20/sl.py @@ -0,0 +1,26 @@ +# coding=utf-8 + +id = 205 +name = 'Krog 20 cm' +slug = 'Krog 20 cm' + +description = '''\ +

Napiši program, s katerim bo robot enkrat prevozil krog s polmerom 20 cm in se nato ustavil.

''' + +hint = { + 'mW_init':['''

Robota v programu predstavimo z mindstorms_widgets(): robot = mindstorms_widgets().

'''], + 'connectMotorLeft':['''

Robotu priključi levi motor

''', + '''

robot.connect_motor( 'left' ).

'''], + 'connectMotorRight':['''

Robotu priključi desni motor

''', + '''

robot.connect_motor( 'right' ).

'''], + 'moveSteering':['''

Sinhroniziraj motorja in ju zaženi za 3 sekunde.

''', + '''

Za sinhronizirano vožnjo je najbolj primerna metoda robot.move_steering( ... ).

'''], + 'onForSeconds':['''

Prvi argument metode robot.move_steering naj pove, da bo delovanje motorjev časovno omejeno.

''', + '''

robot.move_steering('on_for_seconds', ... ).

'''], + 'direction':['''

Navedi smer premikanja motorjev; pozitivne vrednosti pomenijo zavoj v desno.

''', + '''

Določi vrednost parametra direction tako, da bo robot krožil po krogu s polmerom 20cm. Vrednost je odvisna od konstrukcije robota in podlage.

''', + '''

robot.move_steering( 'on_for_seconds', direction=20, ... ).

'''], + 'seconds':['''

Napiši časovno omejitev v sekundah.

''', + '''

Za dani polmer izmeri čas, ki ga robot potrebuje za en obhod.

''', + '''

robot.move_steering( 'on_for_seconds', direction=0, seconds=3 ).

'''], +} diff --git a/robot/problems/introduction/circle20/sl.py~ b/robot/problems/introduction/circle20/sl.py~ new file mode 100644 index 0000000..656253d --- /dev/null +++ b/robot/problems/introduction/circle20/sl.py~ @@ -0,0 +1,24 @@ +# coding=utf-8 + +id = 205 +name = 'Krog 20 cm' +slug = 'Krog 20 cm' + +description = '''\ +

Napiši program, s katerim bo robot enkrat prevozil krog s polmerom 20 cm in se nato ustavil.

''' + +hint = { + 'mW_init':['''

Robota v programu predstavimo z mindstorms_widgets(): robot = mindstorms_widgets().

'''], + 'connectMotorLeft':['''

Robotu moramo priključiti levi motor: robot.connect_motor( 'left' ).

'''], + 'connectMotorRight':['''

Robotu moramo priključiti desni motor: robot.connect_motor( 'right' ).

'''], + 'moveSteering':['''

Sinhroniziraj motorja in ju zaženi za 3 sekunde.

''', + '''

Za sinhronizirano vožnjo je najbolj primerna metoda robot.move_steering( ... ).

'''], + 'onForSeconds':['''

Prvi argument metode robot.move_steering naj pove, da bo delovanje motorjev časovno omejeno.

''', + '''

robot.move_steering('on_for_seconds', ... ).

'''], + 'direction':['''

Navedi smer premikanja motorjev; pozitivne vrednosti pomenijo zavoj v desno.

''', + '''

Določi vrednost parametra direction tako, da bo robot krožil po krogu s polmerom 20cm. Vrednost je odvisna od konstrukcije robota in podlage.

''', + '''

robot.move_steering( 'on_for_seconds', direction=20, ... ).

'''], + 'seconds':['''

Napiši časovno omejitev v sekundah.

''', + '''

Za dani polmer izmeri čas, ki ga robot potrebuje za en obhod.

''', + '''

robot.move_steering( 'on_for_seconds', direction=0, seconds=3 ).

'''], +} diff --git a/robot/problems/introduction/countlines/common.py b/robot/problems/introduction/countlines/common.py new file mode 100644 index 0000000..29f5383 --- /dev/null +++ b/robot/problems/introduction/countlines/common.py @@ -0,0 +1,79 @@ +# coding=utf-8 + +from python.util import has_token_sequence, string_almost_equal, \ + string_contains_number, get_tokens, get_numbers, get_exception_desc +from server.hints import Hint, HintSequence + +id = 206 +group = 'introduction' +number = 10 +visible = True + +solution = '''\ +import time +from ev3dev import * +from mindstorms_widgets import mindstorms_widgets + +color_table = ['none', 'black', 'blue', 'green', 'yellow', 'red', 'white', 'brown'] + +robot = mindstorms_widgets() +robot.connect_motor( 'left' ) +robot.connect_motor( 'right' ) +robot.connect_sensor( 'color' ) + +robot.move_steering( 'on' ) +start = time.time() +stevec = 0 +color = -1 +while time.time()-start < 2.1: + c = robot.color_sensor_measure( 'color' ) # values: 0-7 see the scale above + if c!=color: + if c!=6 and c!=0: + stevec += 1 + color = c +robot.move_steering( 'off' ) +print( "Stevilo crt:", stevec ) +''' + +hint_type = { + 'mW_init': Hint('mW_init'), + 'connectMotorLeft': Hint('connectMotorLeft'), + 'connectMotorRight': Hint('connectMotorRight'), + 'moveSteeringOn': Hint('moveSteeringOn'), + 'moveSteeringOff': Hint('moveSteeringOff'), + 'connectColorSensor': Hint('connectColorSensor'), + 'colorSensorMeasure': Hint('colorSensorMeasure'), + 'while': Hint('while') +} + +def hint( code ): + tokens = get_tokens(code) + + # if code does not include mindstorms_widgets(), a student gets a hint that the robot should be somehow represented in the program + if not has_token_sequence(tokens, ['mindstorms_widgets', '(',')']): + return [{'id': 'mW_init'}] + + # if code does not include connect_motor statement, a student needs to learn about how to connect the motors + if not has_token_sequence(tokens, ['connect_motor']) and not has_token_sequence(tokens, ['left']): + return [{'id': 'connectMotorLeft'}] + + # if code does not include connect_motor statement, a student needs to learn about how to connect the motors + if not has_token_sequence(tokens, ['connect_motor']) and not has_token_sequence(tokens, ['right']): + return [{'id': 'connectMotorRight'}] + + if not (has_token_sequence(tokens, ['connect_sensor', '(' ]) and 'color' in code): + return [{'id': 'connectColorSensor'}] + + if not (has_token_sequence(tokens, ['move_steering', '(']) and 'on' in code): + return [{'id': 'moveSteeringOn'}] + + if not (has_token_sequence(tokens, ['move_steering', '(']) and 'off' in code): + return [{'id': 'moveSteeringOff'}] + + if not (has_token_sequence(tokens, ['color_sensor_measure', '(']) and 'color' in code): + return [{'id': 'colorSensorMeasure'}] + + if not has_token_sequence(tokens, ['while']): + return [{'id': 'while'}] + + return None diff --git a/robot/problems/introduction/countlines/common.py~ b/robot/problems/introduction/countlines/common.py~ new file mode 100644 index 0000000..6e5d135 --- /dev/null +++ b/robot/problems/introduction/countlines/common.py~ @@ -0,0 +1,79 @@ +# coding=utf-8 + +from python.util import has_token_sequence, string_almost_equal, \ + string_contains_number, get_tokens, get_numbers, get_exception_desc +from server.hints import Hint, HintSequence + +id = 206 +group = 'introduction' +number = 10 +visible = True + +solution = '''\ +import time +from ev3dev import * +from mindstorms_widgets import mindstorms_widgets + +color_table = ['none', 'black', 'blue', 'green', 'yellow', 'red', 'white', 'brown'] + +robot = mindstorms_widgets() +robot.connect_motor( 'left' ) +robot.connect_motor( 'right' ) +robot.connect_sensor( 'color' ) + +robot.move_steering( 'on' ) +start = time.time() +stevec = 0 +color = -1 +while time.time()-start < 2.1: + c = robot.color_sensor_measure( 'color' ) # values: 0-7 see the scale above + if c!=color: + if c!=6 and c!=0: + stevec += 1 + color = c +robot.move_steering( 'off' ) +print( "Stevilo crt:", stevec ) +''' + +hint_type = { + 'mW_init': Hint('mW_init'), + 'connectMotorLeft': Hint('connectMotorLeft'), + 'connectMotorRight': Hint('connectMotorRight'), + 'moveSteeringOn': Hint('moveSteeringOn'), + 'moveSteeringOff': Hint('moveSteeringOff'), + 'connectColorSensor': Hint('connectColorSensor'), + 'colorSensorMeasure': Hint('colorSensorMeasure'), + 'while': Hint('while') +} + +def hint( code): + tokens = get_tokens(code) + + # if code does not include mindstorms_widgets(), a student gets a hint that the robot should be somehow represented in the program + if not has_token_sequence(tokens, ['mindstorms_widgets', '(',')']): + return [{'id': 'mW_init'}] + + # if code does not include connect_motor statement, a student needs to learn about how to connect the motors + if not has_token_sequence(tokens, ['connect_motor']) and not has_token_sequence(tokens, ['left']): + return [{'id': 'connectMotorLeft'}] + + # if code does not include connect_motor statement, a student needs to learn about how to connect the motors + if not has_token_sequence(tokens, ['connect_motor']) and not has_token_sequence(tokens, ['right']): + return [{'id': 'connectMotorRight'}] + + if not (has_token_sequence(tokens, ['connect_sensor', '(' ]) and 'color' in code): + return [{'id': 'connectColorSensor'}] + + if not has_token_sequence(tokens, ['move_steering', '(', 'on', ')']): + return [{'id': 'moveSteeringOn'}] + + if not has_token_sequence(tokens, ['move_steering', '(', 'off', ')']): + return [{'id': 'moveSteeringOff'}] + + if not (has_token_sequence(tokens, ['color_sensor_measure', '(']) and 'color' in code): + return [{'id': 'colorSensorMeasure'}] + + if not has_token_sequence(tokens, ['while']): + return [{'id': 'while'}] + + return None diff --git a/robot/problems/introduction/countlines/en.py b/robot/problems/introduction/countlines/en.py new file mode 100644 index 0000000..8b3b275 --- /dev/null +++ b/robot/problems/introduction/countlines/en.py @@ -0,0 +1,14 @@ +# coding=utf-8 +import server +mod = server.problems.load_language('python', 'en') + +id = 206 +name = 'Count lines' +slug = 'Count lines' + +description = '''\ +''' + +hint = { + +} 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 diff --git a/robot/problems/introduction/countlines/sl.py b/robot/problems/introduction/countlines/sl.py new file mode 100644 index 0000000..4e1c3d4 --- /dev/null +++ b/robot/problems/introduction/countlines/sl.py @@ -0,0 +1,26 @@ +# coding=utf-8 + +name = 'Preštej črte' +slug = 'Preštej črte' + +description = '''\ +

Robot naj pelje naravnost, pravokotno na črte in naj jih prešteje.

''' + +hint = { + 'mW_init':['''

Robota v programu predstavimo z mindstorms_widgets(): robot = mindstorms_widgets().

'''], + 'connectMotorLeft':['''

Robotu priključi levi motor

''', + '''

robot.connect_motor( 'left' ).

'''], + 'connectMotorRight':['''

Robotu priključi desni motor

''', + '''

robot.connect_motor( 'right' ).

'''], + 'moveSteeringOn':['''

Sinhroniziraj motorja in ju zaženi.

''', + '''

Za sinhronizirano vožnjo je najbolj primerna metoda robot.move_steering( 'on' ).

'''], + 'moveSteeringOff':['''

Ustavi motorja.

''', + '''

robot.move_steering( 'off' ).

'''], + 'connectColorSensor':['''

Robotu moramo priključiti barvni senzor.

''', + '''

robot.connect_sensor( 'color' ).

'''], + 'colorSensorMeasure':['''

Medtem ko se robot pomika naprej, naj uporabi barvni senzor v načinu 'color', s katerim pove, katero barvo trenutno vidi.

''', + '''

robot.color_sensor_measure( 'color' ).

'''], + 'while':['''

Uporabi zanko, znotraj katere robot odčitava barve in povečuje števec.

''', + '''

Zanka je lahko časovno omejena, npr. z uporabo metode time.time().

''', + '''

while time.time()-start < 1.1:.

'''], +} diff --git a/robot/problems/introduction/countlines/sl.py~ b/robot/problems/introduction/countlines/sl.py~ new file mode 100644 index 0000000..6b759ad --- /dev/null +++ b/robot/problems/introduction/countlines/sl.py~ @@ -0,0 +1,29 @@ +# coding=utf-8 +import server +mod = server.problems.load_language('python', 'sl') + +id = 206 +name = 'Preštej črte' +slug = 'Preštej črte' + +description = '''\ +

Robot naj pelje naravnost, pravokotno na črte in naj jih prešteje.

''' + +hint = { + 'mW_init':['''

Robota v programu predstavimo z mindstorms_widgets(): robot = mindstorms_widgets().

'''], + 'connectMotorLeft':['''

Robotu priključi levi motor

''', + '''

robot.connect_motor( 'left' ).

'''], + 'connectMotorRight':['''

Robotu priključi desni motor

''', + '''

robot.connect_motor( 'right' ).

'''], + 'moveSteeringOn':['''

Sinhroniziraj motorja in ju zaženi.

''', + '''

Za sinhronizirano vožnjo je najbolj primerna metoda robot.move_steering( 'on' ).

'''], + 'moveSteeringOff':['''

Ustavi motorja.

''', + '''

robot.move_steering( 'off' ).

'''], + 'connectColorSensor':['''

Robotu moramo priključiti barvni senzor.

''', + '''

robot.connect_sensor( 'color' ).

'''], + 'colorSensorMeasure':['''

Medtem ko se robot pomika naprej, naj uporabi barvni senzor v načinu 'color', s katerim pove, katero barvo trenutno vidi.

''', + '''

robot.color_sensor_measure( 'color' ).

'''], + 'while':['''

Uporabi zanko, znotraj katere robot odčitava barve in povečuje števec.

''', + '''

Zanka je lahko časovno omejena, npr. z uporabo metode time.time().

''', + '''

while time.time()-start < 1.1:.

'''], +} diff --git a/robot/problems/introduction/followline/common.py b/robot/problems/introduction/followline/common.py new file mode 100644 index 0000000..0fc6704 --- /dev/null +++ b/robot/problems/introduction/followline/common.py @@ -0,0 +1,85 @@ +# coding=utf-8 + +from python.util import has_token_sequence, string_almost_equal, \ + string_contains_number, get_tokens, get_numbers, get_exception_desc +from server.hints import Hint, HintSequence + +id = 207 +group = 'introduction' +number = 12 +visible = True + +solution = '''\ +import time +from ev3dev import * +from mindstorms_widgets import mindstorms_widgets + +robot = mindstorms_widgets() +robot.connect_motor( 'left' ) +robot.connect_motor( 'right' ) +robot.connect_sensor( 'color' ) + +start = time.time() +while time.time()-start < 10: + if robot.color_sensor_measure('reflected_light_intensity') < 30: + L, R = 0, 20 + else: + L, R = 20, 0 + robot.move_tank( 'on', lr_power=[L,R]) +robot.move_tank( 'off' ) +''' + +hint_type = { + 'mW_init': Hint('mW_init'), + 'connectMotorLeft': Hint('connectMotorLeft'), + 'connectMotorRight': Hint('connectMotorRight'), + 'moveTankOn': Hint('moveTankOn'), + 'lrPower': Hint('lr_power'), + 'moveTankOff': Hint('moveTankOff'), + 'connectColorSensor': Hint('connectColorSensor'), + 'colorSensorMeasureRLI': Hint('colorSensorMeasureRLI'), + 'while': Hint('while'), + 'time': Hint('time'), + 'if': Hint('if') +} + +def hint( code): + tokens = get_tokens(code) + + # if code does not include mindstorms_widgets(), a student gets a hint that the robot should be somehow represented in the program + if not has_token_sequence(tokens, ['mindstorms_widgets', '(',')']): + return [{'id': 'mW_init'}] + + # if code does not include connect_motor statement, a student needs to learn about how to connect the motors + if not has_token_sequence(tokens, ['connect_motor']) and not has_token_sequence(tokens, ['left']): + return [{'id': 'connectMotorLeft'}] + + # if code does not include connect_motor statement, a student needs to learn about how to connect the motors + if not has_token_sequence(tokens, ['connect_motor']) and not has_token_sequence(tokens, ['right']): + return [{'id': 'connectMotorRight'}] + + if not (has_token_sequence(tokens, ['connect_sensor', '(' ]) and 'color' in code): + return [{'id': 'connectColorSensor'}] + + if not (has_token_sequence(tokens, ['move_steering', '(']) and 'on' in code): + return [{'id': 'moveTankOn'}] + + if not 'lr_power' in code: + return [{'id': 'lrPower'}] + + if not (has_token_sequence(tokens, ['move_steering', '(']) and 'off' in code): + return [{'id': 'moveTankOff'}] + + if not (has_token_sequence(tokens, ['color_sensor_measure', '(']) and 'reflected_light_intensity' in code): + return [{'id': 'colorSensorMeasureRLI'}] + + if not has_token_sequence(tokens, ['while']): + return [{'id': 'while'}] + + if not has_token_sequence(tokens, ['time']): + return [{'id': 'time'}] + + if not has_token_sequence(tokens, ['if']): + return [{'id': 'if'}] + + return None diff --git a/robot/problems/introduction/followline/common.py~ b/robot/problems/introduction/followline/common.py~ new file mode 100644 index 0000000..5a3db5b --- /dev/null +++ b/robot/problems/introduction/followline/common.py~ @@ -0,0 +1,85 @@ +# coding=utf-8 + +from python.util import has_token_sequence, string_almost_equal, \ + string_contains_number, get_tokens, get_numbers, get_exception_desc +from server.hints import Hint, HintSequence + +id = 207 +group = 'introduction' +number = 12 +visible = True + +solution = '''\ +import time +from ev3dev import * +from mindstorms_widgets import mindstorms_widgets + +robot = mindstorms_widgets() +robot.connect_motor( 'left' ) +robot.connect_motor( 'right' ) +robot.connect_sensor( 'color' ) + +start = time.time() +while time.time()-start < 10: + if robot.color_sensor_measure('reflected_light_intensity') < 30: + L, R = 0, 20 + else: + L, R = 20, 0 + robot.move_tank( 'on', lr_power=[L,R]) +robot.move_tank( 'off' ) +''' + +hint_type = { + 'mW_init': Hint('mW_init'), + 'connectMotorLeft': Hint('connectMotorLeft'), + 'connectMotorRight': Hint('connectMotorRight'), + 'moveTankOn': Hint('moveTankOn'), + 'lrPower': Hint('lr_power'), + 'moveTankOff': Hint('moveTankOff'), + 'connectColorSensor': Hint('connectColorSensor'), + 'colorSensorMeasureRLI': Hint('colorSensorMeasureRLI'), + 'while': Hint('while'), + 'time': Hint('time'), + 'if': Hint('if') +} + +def hint( code): + tokens = get_tokens(code) + + # if code does not include mindstorms_widgets(), a student gets a hint that the robot should be somehow represented in the program + if not has_token_sequence(tokens, ['mindstorms_widgets', '(',')']): + return [{'id': 'mW_init'}] + + # if code does not include connect_motor statement, a student needs to learn about how to connect the motors + if not has_token_sequence(tokens, ['connect_motor']) and not has_token_sequence(tokens, ['left']): + return [{'id': 'connectMotorLeft'}] + + # if code does not include connect_motor statement, a student needs to learn about how to connect the motors + if not has_token_sequence(tokens, ['connect_motor']) and not has_token_sequence(tokens, ['right']): + return [{'id': 'connectMotorRight'}] + + if not has_token_sequence(tokens, ['connect_sensor', '(', 'color', ')' ]): + return [{'id': 'connectColorSensor'}] + + if not has_token_sequence(tokens, ['move_tank', '(', 'on', ')']): + return [{'id': 'moveTankOn'}] + + if not has_token_sequence(tokens, ['lr_power']): + return [{'id': 'lrPower'}] + + if not has_token_sequence(tokens, ['move_tank', '(', 'off', ')']): + return [{'id': 'moveTankOff'}] + + if not has_token_sequence(tokens, ['color_sensor_measure', '(', 'reflected_light_intensity', ')']): + return [{'id': 'colorSensorMeasureRLI'}] + + if not has_token_sequence(tokens, ['while']): + return [{'id': 'while'}] + + if not has_token_sequence(tokens, ['time']): + return [{'id': 'time'}] + + if not has_token_sequence(tokens, ['if']): + return [{'id': 'if'}] + + return None diff --git a/robot/problems/introduction/followline/en.py b/robot/problems/introduction/followline/en.py new file mode 100644 index 0000000..3f816fe --- /dev/null +++ b/robot/problems/introduction/followline/en.py @@ -0,0 +1,14 @@ +# coding=utf-8 +import server +mod = server.problems.load_language('python', 'en') + +id = 207 +name = 'Line following' +slug = 'Line following' + +description = '''\ +''' + +hint = { + +} diff --git a/robot/problems/introduction/followline/naloga12_followLine.py b/robot/problems/introduction/followline/naloga12_followLine.py new file mode 100644 index 0000000..347e89e --- /dev/null +++ b/robot/problems/introduction/followline/naloga12_followLine.py @@ -0,0 +1,31 @@ +#!/usr/bin/python +# coding=utf-8 + +print( """ +Naloga 12: + Robot naj 10 sekund sledi crni crti na beli podlagi; pri tem naj si pomaga z barvnim senzorjem. +""") +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' ) +robot.connect_sensor( 'color' ) + +start = time.time() +# CALIBRATION +# print 'black', robot.color_sensor_measure('reflected_light_intensity') +# print "move to white" +# time.sleep(5) +# print 'white', robot.color_sensor_measure('reflected_light_intensity') +while time.time()-start < 10: + if robot.color_sensor_measure('reflected_light_intensity') < 30: + L, R = 0, 20 + else: + L, R = 20, 0 + robot.move_tank( 'on', lr_power=[L,R]) +robot.move_tank( 'off' ) diff --git a/robot/problems/introduction/followline/sl.py b/robot/problems/introduction/followline/sl.py new file mode 100644 index 0000000..848fe2b --- /dev/null +++ b/robot/problems/introduction/followline/sl.py @@ -0,0 +1,34 @@ +# coding=utf-8 + +name = 'Sledenje črti' +slug = 'Sledenje črti' + +description = '''\ +

Robot naj 10 sekund sledi črni črti na beli podlagi; pri tem naj si pomaga z barvnim senzorjem.

''' + +hint = { + 'mW_init':['''

Robota v programu predstavimo z mindstorms_widgets(): robot = mindstorms_widgets().

'''], + 'connectMotorLeft':['''

Robotu priključi levi motor

''', + '''

robot.connect_motor( 'left' ).

'''], + 'connectMotorRight':['''

Robotu priključi desni motor

''', + '''

robot.connect_motor( 'right' ).

'''], + + 'moveTankOn':['''

Uporabi metodo za ločen nadzor motorjev, s katero vsakemu od motorjev nastavljaš drugačno moč.

''', + '''

Za to je najbolj primerna metoda robot.move_tank( ... ).

''', + '''

robot.move_tank( 'on', ...)

'''], + 'lrPower': ['''

Nastavi parameter s katerim nastaviš moči levega in desnega motorja.

''', + '''

robot.move_tank( 'on', lr_power=[ ... ])

'''], + 'moveTankOff': ['''Ustavi robota.''', + '''

robot.move_tank( 'off' )

'''], + 'connectColorSensor':['''

Robotu moramo priključiti barvni senzor.

''', + '''

robot.connect_sensor( 'color' ).

'''], + 'colorSensorMeasureRLI':['''

Medtem ko se robot pomika naprej, naj uporabi barvni senzor v načinu 'reflected_light_intensity', za zaznavanje jakosti odbite svetlobe.

''', + '''

robot.color_sensor_measure( 'reflected_light_intensity' ).

'''], + 'while':['''

Uporabi zanko, znotraj katere robot sledi črti.

''', + '''

Zanka naj bo časovno omejena, npr. z uporabo metode time.time().

''', + '''

start = time.time()\nwhile time.time()-start < 10:.

'''], + 'time': ['''Uporabi metodo time() za merjenje časa.''', + '''

start = time.time()\nwhile time.time()-start < 10:

'''], + 'if': ['''

V zanki uporabi pogojni stavek...

''', + '''

Če robot vidi črto, naj zavije z nje; če vidi podlago, naj zavije proti črti.

'''] +} diff --git a/robot/problems/introduction/followline/sl.py~ b/robot/problems/introduction/followline/sl.py~ new file mode 100644 index 0000000..5d201fe --- /dev/null +++ b/robot/problems/introduction/followline/sl.py~ @@ -0,0 +1,35 @@ +# coding=utf-8 +import server +mod = server.problems.load_language('python', 'sl') + +id = 207 +name = 'Sledenje črti' +slug = 'Sledenje črti' + +description = '''\ +

Robot naj 10 sekund sledi črni črti na beli podlagi; pri tem naj si pomaga z barvnim senzorjem.

''' + +hint = { + 'mW_init':['''

Robota v programu predstavimo z mindstorms_widgets(): robot = mindstorms_widgets().

'''], + 'connectMotorLeft':['''

Robotu moramo priključiti levi motor: robot.connect_motor( 'left' ).

'''], + 'connectMotorRight':['''

Robotu moramo priključiti desni motor: robot.connect_motor( 'right' ).

'''], + + 'moveTankOn':['''

Uporabi metodo za ločen nadzor motorjev, s katero vsakemu od motorjev nastavljaš drugačno moč.

''', + '''

Za to je najbolj primerna metoda robot.move_tank( ... ).

''', + '''

robot.move_tank( 'on', ...)

'''], + 'lrPower': ['''

Nastavi parameter s katerim nastaviš moči levega in desnega motorja.

''', + '''

robot.move_tank( 'on', lr_power=[ ... ])

'''], + 'moveTankOff': ['''Ustavi robota.''', + '''

robot.move_tank( 'off' )

'''], + 'connectColorSensor':['''

Robotu moramo priključiti barvni senzor.

''', + '''

robot.connect_sensor( 'color' ).

'''], + 'colorSensorMeasureRLI':['''

Medtem ko se robot pomika naprej, naj uporabi barvni senzor v načinu 'reflected_light_intensity', za zaznavanje jakosti odbite svetlobe.

''', + '''

robot.color_sensor_measure( 'reflected_light_intensity' ).

'''], + 'while':['''

Uporabi zanko, znotraj katere robot sledi črti.

''', + '''

Zanka naj bo časovno omejena, npr. z uporabo metode time.time().

''', + '''

start = time.time()\nwhile time.time()-start < 10:.

'''], + 'time': ['''Uporabi metodo time() za merjenje časa.''', + '''

start = time.time()\nwhile time.time()-start < 10:

'''], + 'if': ['''

V zanki uporabi pogojni stavek...

''', + '''

Če robot vidi črto, naj zavije z nje; če vidi podlago, naj zavije proti črti.

'''] +} \ No newline at end of file diff --git a/robot/problems/introduction/forward/common.py b/robot/problems/introduction/forward/common.py index f6330fd..b3fa8a9 100644 --- a/robot/problems/introduction/forward/common.py +++ b/robot/problems/introduction/forward/common.py @@ -9,7 +9,6 @@ number = 1 visible = True solution = '''\ -import time from ev3dev import * from mindstorms_widgets import mindstorms_widgets @@ -48,13 +47,13 @@ def hint( code): if not has_token_sequence(tokens, ['move_steering']): return [{'id': 'moveSteering'}] - if not has_token_sequence(tokens, ['on_for_seconds']): + if not 'on_for_seconds' in code: return [{'id': 'onForSeconds'}] - if not has_token_sequence(tokens, ['direction']): + if not 'direction' in code: return [{'id': 'direction'}] - if not has_token_sequence(tokens, ['seconds']): + if not 'seconds' in code: return [{'id': 'seconds'}] return None diff --git a/robot/problems/introduction/forward/common.py~ b/robot/problems/introduction/forward/common.py~ new file mode 100644 index 0000000..f6330fd --- /dev/null +++ b/robot/problems/introduction/forward/common.py~ @@ -0,0 +1,60 @@ +# coding=utf-8 + +from python.util import has_token_sequence, string_almost_equal, \ + string_contains_number, get_tokens, get_numbers, get_exception_desc +from server.hints import Hint, HintSequence + +id = 202 +number = 1 +visible = True + +solution = '''\ +import time +from ev3dev import * +from mindstorms_widgets import mindstorms_widgets + +robot = mindstorms_widgets() +robot.connect_motor( 'left' ) +robot.connect_motor( 'right' ) + +robot.move_steering( 'on_for_seconds', direction=0, seconds=3 ) +''' + +hint_type = { + 'mW_init': Hint('mW_init'), + 'connectMotorLeft': Hint('connectMotorLeft'), + 'connectMotorRight': Hint('connectMotorRight'), + 'moveSteering': Hint('moveSteering'), + 'onForSeconds': Hint('onForSeconds'), + 'direction': Hint('direction'), + 'seconds': Hint('seconds'), +} + +def hint( code): + tokens = get_tokens(code) + + # if code does not include mindstorms_widgets(), a student gets a hint that the robot should be somehow represented in the program + if not has_token_sequence(tokens, ['mindstorms_widgets', '(',')']): + return [{'id': 'mW_init'}] + + # if code does not include connect_motor statement, a student needs to learn about how to connect the motors + if not has_token_sequence(tokens, ['connect_motor']) and not has_token_sequence(tokens, ['left']): + return [{'id': 'connectMotorLeft'}] + + # if code does not include connect_motor statement, a student needs to learn about how to connect the motors + if not has_token_sequence(tokens, ['connect_motor']) and not has_token_sequence(tokens, ['right']): + return [{'id': 'connectMotorRight'}] + + if not has_token_sequence(tokens, ['move_steering']): + return [{'id': 'moveSteering'}] + + if not has_token_sequence(tokens, ['on_for_seconds']): + return [{'id': 'onForSeconds'}] + + if not has_token_sequence(tokens, ['direction']): + return [{'id': 'direction'}] + + if not has_token_sequence(tokens, ['seconds']): + return [{'id': 'seconds'}] + + return None diff --git a/robot/problems/introduction/forward/en.py~ b/robot/problems/introduction/forward/en.py~ new file mode 100644 index 0000000..4337ac5 --- /dev/null +++ b/robot/problems/introduction/forward/en.py~ @@ -0,0 +1,20 @@ +# coding=utf-8 +import server +mod = server.problems.load_language('python', 'en') + +<<<<<<< HEAD +id = 202 +name = 'Forward 3s' +slug = 'Forward 3s' +======= +name = 'Forward' +slug = 'Forward' +>>>>>>> 5a01c2bb184152c6ccc3c536e9b857d247bc55ad + +description = '''\ +

Write a program that would make the robot drive straight forward for 3 seconds and stop

+''' + +hint = { + +} diff --git a/robot/problems/introduction/forward/sl.py b/robot/problems/introduction/forward/sl.py index 837380b..a6f7e86 100644 --- a/robot/problems/introduction/forward/sl.py +++ b/robot/problems/introduction/forward/sl.py @@ -8,8 +8,10 @@ description = '''\ hint = { 'mW_init':['''

Robota v programu predstavimo z mindstorms_widgets(): robot = mindstorms_widgets().

'''], - 'connectMotorLeft':['''

Robotu moramo priključiti levi motor: robot.connect_motor( 'left' ).

'''], - 'connectMotorRight':['''

Robotu moramo priključiti desni motor: robot.connect_motor( 'right' ).

'''], + 'connectMotorLeft':['''

Robotu priključi levi motor

''', + '''

robot.connect_motor( 'left' ).

'''], + 'connectMotorRight':['''

Robotu priključi desni motor

''', + '''

robot.connect_motor( 'right' ).

'''], 'moveSteering':['''

Sinhroniziraj motorja in ju zaženi za 3 sekunde.

''', '''

Za sinhronizirano vožnjo je najbolj primerna metoda robot.move_steering( ... ).

'''], 'onForSeconds':['''

Prvi argument metode robot.move_steering naj pove, da bo delovanje motorjev časovno omejeno.

''', diff --git a/robot/problems/introduction/forward/sl.py~ b/robot/problems/introduction/forward/sl.py~ new file mode 100644 index 0000000..a6f7e86 --- /dev/null +++ b/robot/problems/introduction/forward/sl.py~ @@ -0,0 +1,23 @@ +# coding=utf-8 + +name = 'Naprej 3s' +slug = 'Naprej 3s' + +description = '''\ +

Napiši program, da bo robot peljal naravnost naprej 3 sekunde in se nato ustavil.

''' + +hint = { + 'mW_init':['''

Robota v programu predstavimo z mindstorms_widgets(): robot = mindstorms_widgets().

'''], + 'connectMotorLeft':['''

Robotu priključi levi motor

''', + '''

robot.connect_motor( 'left' ).

'''], + 'connectMotorRight':['''

Robotu priključi desni motor

''', + '''

robot.connect_motor( 'right' ).

'''], + 'moveSteering':['''

Sinhroniziraj motorja in ju zaženi za 3 sekunde.

''', + '''

Za sinhronizirano vožnjo je najbolj primerna metoda robot.move_steering( ... ).

'''], + 'onForSeconds':['''

Prvi argument metode robot.move_steering naj pove, da bo delovanje motorjev časovno omejeno.

''', + '''

robot.move_steering('on_for_seconds', ... ).

'''], + 'direction':['''

Navedi smer premikanja motorjev, naravnost = 0.

''', + '''

robot.move_steering( 'on_for_seconds', direction=0, ... ).

'''], + 'seconds':['''

Napiši časovno omejitev v sekundah.

''', + '''

robot.move_steering( 'on_for_seconds', direction=0, seconds=3 ).

'''], +} diff --git a/robot/problems/introduction/forward1m/common.py b/robot/problems/introduction/forward1m/common.py new file mode 100644 index 0000000..ea2f7a0 --- /dev/null +++ b/robot/problems/introduction/forward1m/common.py @@ -0,0 +1,60 @@ +# coding=utf-8 + +from python.util import has_token_sequence, string_almost_equal, \ + string_contains_number, get_tokens, get_numbers, get_exception_desc +from server.hints import Hint, HintSequence + +id = 208 +group = 'introduction' +number = 2 +visible = True + +solution = '''\ +from ev3dev import * +from mindstorms_widgets import mindstorms_widgets + +robot = mindstorms_widgets() +robot.connect_motor( 'left' ) +robot.connect_motor( 'right' ) + +robot.move_steering( 'on_for_rotations', direction=0, rotations=5.71 ) +''' + +hint_type = { + 'mW_init': Hint('mW_init'), + 'connectMotorLeft': Hint('connectMotorLeft'), + 'connectMotorRight': Hint('connectMotorRight'), + 'moveSteering': Hint('moveSteering'), + 'onForRotations': Hint('onForRotations'), + 'direction': Hint('direction'), + 'rotations': Hint('rotations'), +} + +def hint(code): + tokens = get_tokens(code) + + # if code does not include mindstorms_widgets(), a student gets a hint that the robot should be somehow represented in the program + if not has_token_sequence(tokens, ['mindstorms_widgets', '(',')']): + return [{'id': 'mW_init'}] + + # if code does not include connect_motor statement, a student needs to learn about how to connect the motors + if not has_token_sequence(tokens, ['connect_motor']) and not has_token_sequence(tokens, ['left']): + return [{'id': 'connectMotorLeft'}] + + # if code does not include connect_motor statement, a student needs to learn about how to connect the motors + if not has_token_sequence(tokens, ['connect_motor']) and not has_token_sequence(tokens, ['right']): + return [{'id': 'connectMotorRight'}] + + if not has_token_sequence(tokens, ['move_steering']): + return [{'id': 'moveSteering'}] + + if not 'on_for_rotations' in code: + return [{'id': 'onForRotations'}] + + if not 'direction' in code: + return [{'id': 'direction'}] + + if not 'rotations' in code: + return [{'id': 'rotations'}] + + return None diff --git a/robot/problems/introduction/forward1m/common.py~ b/robot/problems/introduction/forward1m/common.py~ new file mode 100644 index 0000000..809fe9d --- /dev/null +++ b/robot/problems/introduction/forward1m/common.py~ @@ -0,0 +1,61 @@ +# coding=utf-8 + +from python.util import has_token_sequence, string_almost_equal, \ + string_contains_number, get_tokens, get_numbers, get_exception_desc +from server.hints import Hint, HintSequence + +id = 208 +group = 'introduction' +number = 2 +visible = True + +solution = '''\ +import time +from ev3dev import * +from mindstorms_widgets import mindstorms_widgets + +robot = mindstorms_widgets() +robot.connect_motor( 'left' ) +robot.connect_motor( 'right' ) + +robot.move_steering( 'on_for_rotations', direction=0, rotations=5.71 ) +''' + +hint_type = { + 'mW_init': Hint('mW_init'), + 'connectMotorLeft': Hint('connectMotorLeft'), + 'connectMotorRight': Hint('connectMotorRight'), + 'moveSteering': Hint('moveSteering'), + 'onForRotations': Hint('onForRotations'), + 'direction': Hint('direction'), + 'rotations': Hint('rotations'), +} + +def hint(code): + tokens = get_tokens(code) + + # if code does not include mindstorms_widgets(), a student gets a hint that the robot should be somehow represented in the program + if not has_token_sequence(tokens, ['mindstorms_widgets', '(',')']): + return [{'id': 'mW_init'}] + + # if code does not include connect_motor statement, a student needs to learn about how to connect the motors + if not has_token_sequence(tokens, ['connect_motor']) and not has_token_sequence(tokens, ['left']): + return [{'id': 'connectMotorLeft'}] + + # if code does not include connect_motor statement, a student needs to learn about how to connect the motors + if not has_token_sequence(tokens, ['connect_motor']) and not has_token_sequence(tokens, ['right']): + return [{'id': 'connectMotorRight'}] + + if not has_token_sequence(tokens, ['move_steering']): + return [{'id': 'moveSteering'}] + + if not has_token_sequence(tokens, ['on_for_rotations']): + return [{'id': 'onForRotations'}] + + if not has_token_sequence(tokens, ['direction']): + return [{'id': 'direction'}] + + if not has_token_sequence(tokens, ['rotations']): + return [{'id': 'rotations'}] + + return None diff --git a/robot/problems/introduction/forward1m/en.py b/robot/problems/introduction/forward1m/en.py new file mode 100644 index 0000000..bdf2a45 --- /dev/null +++ b/robot/problems/introduction/forward1m/en.py @@ -0,0 +1,15 @@ +# coding=utf-8 +import server +mod = server.problems.load_language('python', 'en') + +id = 208 +name = 'Forward 1m' +slug = 'Forward 1m' + +description = '''\ + +''' + +hint = { + +} diff --git a/robot/problems/introduction/forward1m/sl.py b/robot/problems/introduction/forward1m/sl.py new file mode 100644 index 0000000..8045d58 --- /dev/null +++ b/robot/problems/introduction/forward1m/sl.py @@ -0,0 +1,23 @@ +# coding=utf-8 + +name = 'Naprej 1m' +slug = 'Naprej 1m' + +description = '''\ +

Napiši program, da bo robot peljal naravnost naprej 3 sekunde in se nato ustavil.

''' + +hint = { + 'mW_init':['''

Robota v programu predstavimo z mindstorms_widgets(): robot = mindstorms_widgets().

'''], + 'connectMotorLeft':['''

Robotu priključi levi motor

''', + '''

robot.connect_motor( 'left' ).

'''], + 'connectMotorRight':['''

Robotu priključi desni motor

''', + '''

robot.connect_motor( 'right' ).

'''], + 'moveSteering':['''

Sinhroniziraj motorja in ju zaženi za 3 sekunde.

''', + '''

Za sinhronizirano vožnjo je najbolj primerna metoda robot.move_steering( ... ).

'''], + 'onForRotations':['''

Prvi argument metode robot.move_steering naj pove, da bo delovanje motorjev določeno s številom obratov.

''', + '''

robot.move_steering('on_for_rotations', ... ).

'''], + 'direction':['''

Navedi smer premikanja motorjev, naravnost = 0.

''', + '''

robot.move_steering( 'on_for_rotations', direction=0, ... ).

'''], + 'rotations':['''

Določi število obratov; za koliko obratov naj se zavrtita motorja? Izmeri dolžino 1m, izpisuj obrate print(robot.motor['left'].count_per_rot, robot.motor['right'].count_per_rot) in tako določi ustrezno število obratov.

''', + '''

robot.move_steering( 'on_for_rotations', direction=0, rotations=5 ).

'''], +} diff --git a/robot/problems/introduction/forward1m/sl.py~ b/robot/problems/introduction/forward1m/sl.py~ new file mode 100644 index 0000000..e8071ee --- /dev/null +++ b/robot/problems/introduction/forward1m/sl.py~ @@ -0,0 +1,24 @@ +# coding=utf-8 +import server +mod = server.problems.load_language('python', 'sl') + +id = 208 +name = 'Naprej 1m' +slug = 'Naprej 1m' + +description = '''\ +

Napiši program, da bo robot peljal naravnost naprej 3 sekunde in se nato ustavil.

''' + +hint = { + 'mW_init':['''

Robota v programu predstavimo z mindstorms_widgets(): robot = mindstorms_widgets().

'''], + 'connectMotorLeft':['''

Robotu moramo priključiti levi motor: robot.connect_motor( 'left' ).

'''], + 'connectMotorRight':['''

Robotu moramo priključiti desni motor: robot.connect_motor( 'right' ).

'''], + 'moveSteering':['''

Sinhroniziraj motorja in ju zaženi za 3 sekunde.

''', + '''

Za sinhronizirano vožnjo je najbolj primerna metoda robot.move_steering( ... ).

'''], + 'onForRotations':['''

Prvi argument metode robot.move_steering naj pove, da bo delovanje motorjev določeno s številom obratov.

''', + '''

robot.move_steering('on_for_rotations', ... ).

'''], + 'direction':['''

Navedi smer premikanja motorjev, naravnost = 0.

''', + '''

robot.move_steering( 'on_for_rotations', direction=0, ... ).

'''], + 'rotations':['''

Določi število obratov; za koliko obratov naj se zavrtita motorja? Izmeri dolžino 1m, izpisuj obrate print(robot.motor['left'].count_per_rot, robot.motor['right'].count_per_rot) in tako določi ustrezno število obratov.

''', + '''

robot.move_steering( 'on_for_rotations', direction=0, rotations=5 ).

'''], +} diff --git a/robot/problems/introduction/gyro90/common.py b/robot/problems/introduction/gyro90/common.py new file mode 100644 index 0000000..b44d15d --- /dev/null +++ b/robot/problems/introduction/gyro90/common.py @@ -0,0 +1,80 @@ +# coding=utf-8 + +from python.util import has_token_sequence, string_almost_equal, \ + string_contains_number, get_tokens, get_numbers, get_exception_desc +from server.hints import Hint, HintSequence + +id = 209 +group = 'introduction' +number = 7 +visible = True + +solution = '''\ +from ev3dev import * +from mindstorms_widgets import mindstorms_widgets + +robot = mindstorms_widgets() +robot.connect_motor( 'left' ) +robot.connect_motor( 'right' ) +robot.connect_sensor( 'gyro' ) + +robot.gyro_set_mode( 'angle' ) +robot.reset_gyro() + +power = 15 +robot.move_tank( 'on', lr_power=[power,-power] ) +while robot.gyro_sensor_measure() < 90: + pass +robot.move_tank( 'off' ) +''' + +hint_type = { + 'mW_init': Hint('mW_init'), + 'connectMotorLeft': Hint('connectMotorLeft'), + 'connectMotorRight': Hint('connectMotorRight'), + 'connectGyro': Hint('connectGyro'), + 'resetGyro': Hint('resetGyro'), + 'setGyroMode': Hint('setGyroMode'), + 'gyroMeasure': Hint('gyroMeasure'), + 'moveTank': Hint('moveTank'), + 'lrPower': Hint('lrPower'), + 'while': Hint('while') +} + +def hint( code): + tokens = get_tokens(code) + + # if code does not include mindstorms_widgets(), a student gets a hint that the robot should be somehow represented in the program + if not has_token_sequence(tokens, ['mindstorms_widgets', '(',')']): + return [{'id': 'mW_init'}] + + # if code does not include connect_motor statement, a student needs to learn about how to connect the motors + if not has_token_sequence(tokens, ['connect_motor']) and not has_token_sequence(tokens, ['left']): + return [{'id': 'connectMotorLeft'}] + + # if code does not include connect_motor statement, a student needs to learn about how to connect the motors + if not has_token_sequence(tokens, ['connect_motor']) and not has_token_sequence(tokens, ['right']): + return [{'id': 'connectMotorRight'}] + + if not (has_token_sequence(tokens, ['connect_gyro','(']) and 'gyro' in code): + return [{'id': 'connectGyro'}] + + if not has_token_sequence(tokens, ['reset_gyro()']): + return [{'id': 'resetGyro'}] + + if not has_token_sequence(tokens, ['gyro_set_mode']): + return [{'id': 'setGyroMode'}] + + if not has_token_sequence(tokens, ['gyro_sensor_measure()']): + return [{'id': 'gyroMeasure'}] + + if not has_token_sequence(tokens, ['move_tank']): + return [{'id': 'moveTank'}] + + if not 'lr_power' in code: + return [{'id': 'lrPower'}] + + if not has_token_sequence(tokens, ['while']): + return [{'id': 'while'}] + + return None diff --git a/robot/problems/introduction/gyro90/common.py~ b/robot/problems/introduction/gyro90/common.py~ new file mode 100644 index 0000000..c02a2c4 --- /dev/null +++ b/robot/problems/introduction/gyro90/common.py~ @@ -0,0 +1,80 @@ +# coding=utf-8 + +from python.util import has_token_sequence, string_almost_equal, \ + string_contains_number, get_tokens, get_numbers, get_exception_desc +from server.hints import Hint, HintSequence + +id = 209 +group = 'introduction' +number = 7 +visible = True + +solution = '''\ +from ev3dev import * +from mindstorms_widgets import mindstorms_widgets + +robot = mindstorms_widgets() +robot.connect_motor( 'left' ) +robot.connect_motor( 'right' ) +robot.connect_sensor( 'gyro' ) + +robot.gyro_set_mode( 'angle' ) +robot.reset_gyro() + +power = 15 +robot.move_tank( 'on', lr_power=[power,-power] ) +while robot.gyro_sensor_measure() < 90: + pass +robot.move_tank( 'off' ) +''' + +hint_type = { + 'mW_init': Hint('mW_init'), + 'connectMotorLeft': Hint('connectMotorLeft'), + 'connectMotorRight': Hint('connectMotorRight'), + 'connectGyro': Hint('connectGyro'), + 'resetGyro': Hint('resetGyro'), + 'setGyroMode': Hint('setGyroMode'), + 'gyroMeasure': Hint('gyroMeasure'), + 'moveTank': Hint('moveTank'), + 'lrPower': Hint('lrPower'), + 'while': Hint('while') +} + +def hint( code): + tokens = get_tokens(code) + + # if code does not include mindstorms_widgets(), a student gets a hint that the robot should be somehow represented in the program + if not has_token_sequence(tokens, ['mindstorms_widgets', '(',')']): + return [{'id': 'mW_init'}] + + # if code does not include connect_motor statement, a student needs to learn about how to connect the motors + if not has_token_sequence(tokens, ['connect_motor']) and not has_token_sequence(tokens, ['left']): + return [{'id': 'connectMotorLeft'}] + + # if code does not include connect_motor statement, a student needs to learn about how to connect the motors + if not has_token_sequence(tokens, ['connect_motor']) and not has_token_sequence(tokens, ['right']): + return [{'id': 'connectMotorRight'}] + + if not has_token_sequence(tokens, ['connect_gyro','(', 'gyro', ')']): + return [{'id': 'connectGyro'}] + + if not has_token_sequence(tokens, ['reset_gyro()']): + return [{'id': 'resetGyro'}] + + if not has_token_sequence(tokens, ['gyro_set_mode']): + return [{'id': 'setGyroMode'}] + + if not has_token_sequence(tokens, ['gyro_sensor_measure()']): + return [{'id': 'gyroMeasure'}] + + if not has_token_sequence(tokens, ['move_tank']): + return [{'id': 'moveTank'}] + + if not has_token_sequence(tokens, ['lr_power']): + return [{'id': 'lrPower'}] + + if not has_token_sequence(tokens, ['while']): + return [{'id': 'while'}] + + return None diff --git a/robot/problems/introduction/gyro90/en.py b/robot/problems/introduction/gyro90/en.py new file mode 100644 index 0000000..12c782c --- /dev/null +++ b/robot/problems/introduction/gyro90/en.py @@ -0,0 +1,15 @@ +# coding=utf-8 +import server +mod = server.problems.load_language('python', 'en') + +id = 209 +name = 'Gyro 90' +slug = 'Gyro 90' + +description = '''\ + +''' + +hint = { + +} diff --git a/robot/problems/introduction/gyro90/naloga07_gyro90.py b/robot/problems/introduction/gyro90/naloga07_gyro90.py new file mode 100644 index 0000000..84d4ca1 --- /dev/null +++ b/robot/problems/introduction/gyro90/naloga07_gyro90.py @@ -0,0 +1,25 @@ +#!/usr/bin/python +# coding=utf-8 + +print (""" +Naloga 7: + Robot naj se na mestu obrne za 90 stopinj v desno; pri tem naj si pomaga z ziroskopom. +""") +import sys +sys.path.append('/home/user/codeq') +from ev3dev import * +from mindstorms_widgets import mindstorms_widgets + +robot = mindstorms_widgets() +robot.connect_motor( 'left' ) +robot.connect_motor( 'right' ) +robot.connect_sensor( 'gyro' ) + +robot.gyro_set_mode( 'angle' ) +robot.reset_gyro() + +power = 15 +robot.move_tank( 'on', lr_power=[power,-power] ) +while robot.gyro_sensor_measure() < 90: + pass +robot.move_tank( 'off' ) diff --git a/robot/problems/introduction/gyro90/naloga07_gyro90.py~ b/robot/problems/introduction/gyro90/naloga07_gyro90.py~ new file mode 100644 index 0000000..97e42ee --- /dev/null +++ b/robot/problems/introduction/gyro90/naloga07_gyro90.py~ @@ -0,0 +1,34 @@ +#!/usr/bin/python +# coding=utf-8 + +print """ +Naloga 7: + Robot naj se na mestu obrne za 90 stopinj v desno; pri tem naj si pomaga z ziroskopom. +""" + +import time +from ev3dev import * +from mindstorms_widgets import mindstorms_widgets + +gs = gyro_sensor(); +assert gs.connected +gs.mode = 'GYRO-ANG' # Angle (degrees), value: (-32768 to 32767) + +# for m in us.modes: +# print "\t",m +#exit() +robot = mindstorms_widgets() +robot.connect_motor( 'left' ) +robot.connect_motor( 'right' ) + +power = 15 +robot.move_tank( 'on', lr_power=[power,-power] ) +while gs.value()<90: + pass +robot.move_tank( 'off', brake_at_end=True ) +# print gs.value() +# gs = gyro_sensor(); +# assert gs.connected +# gs.mode = 'GYRO-ANG' +# +# print "--->",gs.value() \ No newline at end of file diff --git a/robot/problems/introduction/gyro90/sl.py b/robot/problems/introduction/gyro90/sl.py new file mode 100644 index 0000000..0a82c6d --- /dev/null +++ b/robot/problems/introduction/gyro90/sl.py @@ -0,0 +1,29 @@ +# coding=utf-8 + +name = 'Žiroskop 90' +slug = 'Žiroskop 90' + +description = '''\ +

Robot naj se na mestu obrne za 90 stopinj v desno; pri tem naj si pomaga z žiroskopom.

''' + +hint = { + 'mW_init':['''

Robota v programu predstavimo z mindstorms_widgets(): robot = mindstorms_widgets().

'''], + 'connectMotorLeft':['''

Robotu priključi levi motor.

''', + '''

robot.connect_motor( 'left' ).

'''], + 'connectMotorRight':['''

Robotu priključi desni motor.

''', + '''

robot.connect_motor( 'right' ).

'''], + 'connectGyro':['''

Robotu priključi žiroskop.

''', + '''

robot.connect_sensor( 'gyro' ).

'''], + 'resetGyro':['''

Žiroskop na začetku resetiraj.

''', + '''

robot.reset_gyro().

'''], + 'setGyroMode':['''

Žiroskopu nastavi način delovanja na merjenje kotov.

''', + '''

robot.gyro_set_mode('angle').

'''], + 'gyroMeasure':['''

Preberi vrednost žiroskopa.

''', + '''

robot.gyro_sensor_measure().

'''], + 'lrPower':['''

Za obrat na mestu se morata kolesi vrteti z enako močjo in v nasprotni smeri.

''', + '''

robot.move_tank( 'on', lr_power=[hitrost, -hitrost], ... ).

'''], + 'moveTank':['''

Robot naj se obrne na mestu.

''', + '''

Najprimernejša metoda za to je move_tank

'''], + 'while':['''

Program naj teče dokler je kot zasuka manjši od 90 stopinj.

''', + '''

robot.gyro_sensor_measure() < 90:

'''], +} diff --git a/robot/problems/introduction/gyro90/sl.py~ b/robot/problems/introduction/gyro90/sl.py~ new file mode 100644 index 0000000..76939f7 --- /dev/null +++ b/robot/problems/introduction/gyro90/sl.py~ @@ -0,0 +1,32 @@ +# coding=utf-8 +import server +mod = server.problems.load_language('python', 'sl') + +id = 209 +name = 'Žiroskop 90' +slug = 'Žiroskop 90' + +description = '''\ +

Robot naj se na mestu obrne za 90 stopinj v desno; pri tem naj si pomaga z žiroskopom.

''' + +hint = { + 'mW_init':['''

Robota v programu predstavimo z mindstorms_widgets(): robot = mindstorms_widgets().

'''], + 'connectMotorLeft':['''

Robotu priključi levi motor.

''', + '''

robot.connect_motor( 'left' ).

'''], + 'connectMotorRight':['''

Robotu priključi desni motor.

''', + '''

robot.connect_motor( 'right' ).

'''], + 'connectGyro':['''

Robotu priključi žiroskop.

''', + '''

robot.connect_sensor( 'gyro' ).

'''], + 'resetGyro':['''

Žiroskop na začetku resetiraj.

''', + '''

robot.reset_gyro().

'''], + 'setGyroMode':['''

Žiroskopu nastavi način delovanja na merjenje kotov.

''', + '''

robot.gyro_set_mode('angle').

'''], + 'gyroMeasure':['''

Preberi vrednost žiroskopa.

''', + '''

robot.gyro_sensor_measure().

'''], + 'lrPower':['''

Za obrat na mestu se morata kolesi vrteti z enako močjo in v nasprotni smeri.

''', + '''

robot.move_tank( 'on', lr_power=[hitrost, -hitrost], ... ).

'''], + 'moveTank':['''

Robot naj se obrne na mestu.

''', + '''

Najprimernejša metoda za to je move_tank

'''], + 'while':['''

Program naj teče dokler je kot zasuka manjši od 90 stopinj.

''', + '''

robot.gyro_sensor_measure() < 90:

'''], +} \ No newline at end of file diff --git a/robot/problems/introduction/gyrosquare/common.py b/robot/problems/introduction/gyrosquare/common.py new file mode 100644 index 0000000..4c06247 --- /dev/null +++ b/robot/problems/introduction/gyrosquare/common.py @@ -0,0 +1,103 @@ +# coding=utf-8 + +from python.util import has_token_sequence, string_almost_equal, \ + string_contains_number, get_tokens, get_numbers, get_exception_desc +from server.hints import Hint, HintSequence + +id = 210 +group = 'introduction' +number = 8 +visible = True + +solution = '''\ +from ev3dev import * +from mindstorms_widgets import mindstorms_widgets + +robot = mindstorms_widgets() +robot.connect_motor( 'left' ) +robot.connect_motor( 'right' ) +robot.connect_sensor( 'gyro' ) + +robot.gyro_set_mode( 'angle' ) +robot.reset_gyro() + +power = 20 +def forward_and_turnRight(power, angle): + robot.move_steering( 'on_for_seconds', direction=0, power=power, seconds=2 ) + robot.move_tank( 'on', lr_power=[power,-power] ) + while robot.gyro_sensor_measure( 'angle' ) < angle: + pass + robot.move_tank( 'off' ) + +forward_and_turnRight(power, 89) +forward_and_turnRight(power, 179) +forward_and_turnRight(power, 269) +forward_and_turnRight(power, 359) +''' + +hint_type = { + 'mW_init': Hint('mW_init'), + 'connectMotorLeft': Hint('connectMotorLeft'), + 'connectMotorRight': Hint('connectMotorRight'), + 'moveSteering': Hint('moveSteering'), + 'onForSeconds': Hint('onForSeconds'), + 'direction': Hint('direction'), + 'seconds': Hint('seconds'), + 'connectGyro': Hint('connectGyro'), + 'resetGyro': Hint('resetGyro'), + 'setGyroMode': Hint('setGyroMode'), + 'gyroMeasure': Hint('gyroMeasure'), + 'moveTank': Hint('moveTank'), + 'lrPower': Hint('lrPower'), + 'while': Hint('while') +} + +def hint( code): + tokens = get_tokens(code) + + # if code does not include mindstorms_widgets(), a student gets a hint that the robot should be somehow represented in the program + if not has_token_sequence(tokens, ['mindstorms_widgets', '(',')']): + return [{'id': 'mW_init'}] + + # if code does not include connect_motor statement, a student needs to learn about how to connect the motors + if not has_token_sequence(tokens, ['connect_motor']) and not has_token_sequence(tokens, ['left']): + return [{'id': 'connectMotorLeft'}] + + # if code does not include connect_motor statement, a student needs to learn about how to connect the motors + if not has_token_sequence(tokens, ['connect_motor']) and not has_token_sequence(tokens, ['right']): + return [{'id': 'connectMotorRight'}] + + if not (has_token_sequence(tokens, ['connect_gyro','(']) and 'gyro' in code): + return [{'id': 'connectGyro'}] + + if not has_token_sequence(tokens, ['reset_gyro()']): + return [{'id': 'resetGyro'}] + + if not has_token_sequence(tokens, ['gyro_set_mode']): + return [{'id': 'setGyroMode'}] + + if not has_token_sequence(tokens, ['gyro_sensor_measure()']): + return [{'id': 'gyroMeasure'}] + + if not has_token_sequence(tokens, ['move_tank']): + return [{'id': 'moveTank'}] + + if not has_token_sequence(tokens, ['move_steering']): + return [{'id': 'moveSteering'}] + + if not 'on_for_seconds' in code: + return [{'id': 'onForSeconds'}] + + if not 'direction' in code: + return [{'id': 'direction'}] + + if not 'seconds' in code: + return [{'id': 'seconds'}] + + if not 'lr_power' in code: + return [{'id': 'lrPower'}] + + if not has_token_sequence(tokens, ['while']): + return [{'id': 'while'}] + + return None diff --git a/robot/problems/introduction/gyrosquare/common.py~ b/robot/problems/introduction/gyrosquare/common.py~ new file mode 100644 index 0000000..1c31f92 --- /dev/null +++ b/robot/problems/introduction/gyrosquare/common.py~ @@ -0,0 +1,103 @@ +# coding=utf-8 + +from python.util import has_token_sequence, string_almost_equal, \ + string_contains_number, get_tokens, get_numbers, get_exception_desc +from server.hints import Hint, HintSequence + +id = 210 +group = 'introduction' +number = 8 +visible = True + +solution = '''\ +from ev3dev import * +from mindstorms_widgets import mindstorms_widgets + +robot = mindstorms_widgets() +robot.connect_motor( 'left' ) +robot.connect_motor( 'right' ) +robot.connect_sensor( 'gyro' ) + +robot.gyro_set_mode( 'angle' ) +robot.reset_gyro() + +power = 20 +def forward_and_turnRight(power, angle): + robot.move_steering( 'on_for_seconds', direction=0, power=power, seconds=2 ) + robot.move_tank( 'on', lr_power=[power,-power] ) + while robot.gyro_sensor_measure( 'angle' ) < angle: + pass + robot.move_tank( 'off' ) + +forward_and_turnRight(power, 89) +forward_and_turnRight(power, 179) +forward_and_turnRight(power, 269) +forward_and_turnRight(power, 359) +''' + +hint_type = { + 'mW_init': Hint('mW_init'), + 'connectMotorLeft': Hint('connectMotorLeft'), + 'connectMotorRight': Hint('connectMotorRight'), + 'moveSteering': Hint('moveSteering'), + 'onForSeconds': Hint('onForSeconds'), + 'direction': Hint('direction'), + 'seconds': Hint('seconds'), + 'connectGyro': Hint('connectGyro'), + 'resetGyro': Hint('resetGyro'), + 'setGyroMode': Hint('setGyroMode'), + 'gyroMeasure': Hint('gyroMeasure'), + 'moveTank': Hint('moveTank'), + 'lrPower': Hint('lrPower'), + 'while': Hint('while') +} + +def hint( code): + tokens = get_tokens(code) + + # if code does not include mindstorms_widgets(), a student gets a hint that the robot should be somehow represented in the program + if not has_token_sequence(tokens, ['mindstorms_widgets', '(',')']): + return [{'id': 'mW_init'}] + + # if code does not include connect_motor statement, a student needs to learn about how to connect the motors + if not has_token_sequence(tokens, ['connect_motor']) and not has_token_sequence(tokens, ['left']): + return [{'id': 'connectMotorLeft'}] + + # if code does not include connect_motor statement, a student needs to learn about how to connect the motors + if not has_token_sequence(tokens, ['connect_motor']) and not has_token_sequence(tokens, ['right']): + return [{'id': 'connectMotorRight'}] + + if not has_token_sequence(tokens, ['connect_gyro','(', 'gyro', ')']): + return [{'id': 'connectGyro'}] + + if not has_token_sequence(tokens, ['reset_gyro()']): + return [{'id': 'resetGyro'}] + + if not has_token_sequence(tokens, ['gyro_set_mode']): + return [{'id': 'setGyroMode'}] + + if not has_token_sequence(tokens, ['gyro_sensor_measure()']): + return [{'id': 'gyroMeasure'}] + + if not has_token_sequence(tokens, ['move_tank']): + return [{'id': 'moveTank'}] + + if not has_token_sequence(tokens, ['move_steering']): + return [{'id': 'moveSteering'}] + + if not 'on_for_seconds' in code: + return [{'id': 'onForSeconds'}] + + if not 'direction' in code: + return [{'id': 'direction'}] + + if not 'seconds' in code: + return [{'id': 'seconds'}] + + if not 'lr_power' in code: + return [{'id': 'lrPower'}] + + if not has_token_sequence(tokens, ['while']): + return [{'id': 'while'}] + + return None diff --git a/robot/problems/introduction/gyrosquare/en.py b/robot/problems/introduction/gyrosquare/en.py new file mode 100644 index 0000000..bbd389c --- /dev/null +++ b/robot/problems/introduction/gyrosquare/en.py @@ -0,0 +1,14 @@ +# coding=utf-8 +import server +mod = server.problems.load_language('python', 'en') + +id = 210 +name = 'Gyro square' +slug = 'Gyro square' + +description = '''\ +''' + +hint = { + +} diff --git a/robot/problems/introduction/gyrosquare/naloga08_gyroSquare.py b/robot/problems/introduction/gyrosquare/naloga08_gyroSquare.py new file mode 100644 index 0000000..ec0dd2f --- /dev/null +++ b/robot/problems/introduction/gyrosquare/naloga08_gyroSquare.py @@ -0,0 +1,33 @@ +#!/usr/bin/python +# coding=utf-8 + +print (""" +Naloga 8: + Robot naj prevozi kvadrat s stranico 20 cm; pri tem naj si pomaga z ziroskopom. +""") +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' ) +robot.connect_sensor( 'gyro' ) + +robot.gyro_set_mode( 'angle' ) +robot.reset_gyro() + +power = 20 +def forward_and_turnRight(power, angle): + robot.move_steering( 'on_for_seconds', direction=0, power=power, seconds=2 ) + robot.move_tank( 'on', lr_power=[power,-power] ) + while robot.gyro_sensor_measure( 'angle' ) < angle: + pass + robot.move_tank( 'off' ) + +forward_and_turnRight(power, 89) +forward_and_turnRight(power, 179) +forward_and_turnRight(power, 269) +forward_and_turnRight(power, 359) diff --git a/robot/problems/introduction/gyrosquare/sl.py b/robot/problems/introduction/gyrosquare/sl.py new file mode 100644 index 0000000..16b2c94 --- /dev/null +++ b/robot/problems/introduction/gyrosquare/sl.py @@ -0,0 +1,38 @@ +# coding=utf-8 + +name = 'Kvadrat z žiroskopom' +slug = 'Kvadrat z žiroskopom' + +description = '''\ +

Robot naj prevozi kvadrat s stranico 20 cm; pri tem naj si pomaga z žiroskopom.

''' + +hint = { + 'mW_init':['''

Robota v programu predstavimo z mindstorms_widgets(): robot = mindstorms_widgets().

'''], + 'connectMotorLeft':['''

Robotu priključi levi motor

''', + '''

robot.connect_motor( 'left' ).

'''], + 'connectMotorRight':['''

Robotu priključi desni motor

''', + '''

robot.connect_motor( 'right' ).

'''], + 'connectGyro':['''

Robotu priključi žiroskop.

''', + '''

robot.connect_sensor( 'gyro' ).

'''], + 'resetGyro':['''

Žiroskop na začetku resetiraj.

''', + '''

robot.reset_gyro().

'''], + 'setGyroMode':['''

Žiroskopu nastavi način delovanja na merjenje kotov.

''', + '''

robot.gyro_set_mode('angle').

'''], + 'gyroMeasure':['''

Preberi vrednost žiroskopa.

''', + '''

robot.gyro_sensor_measure().

'''], + 'lrPower':['''

Za obrat na mestu se morata kolesi vrteti z enako močjo in v nasprotni smeri.

''', + '''

robot.move_tank( 'on', lr_power=[hitrost, -hitrost], ... ).

'''], + 'moveTank':['''

Robot naj se obrne na mestu.

''', + '''

Najprimernejša metoda za to je move_tank

'''], + 'while':['''

Program naj čaka dokler je kot zasuka manjši od 90 stopinj.

''', + '''

robot.gyro_sensor_measure() < 90:

'''], + + 'moveSteering':['''

Sinhroniziraj motorja in ju zaženi.

''', + '''

Za sinhronizirano vožnjo je najbolj primerna metoda robot.move_steering( ... ).

'''], + 'onForSeconds':['''

Prvi argument metode robot.move_steering naj pove, da bo delovanje motorjev časovno omejeno.

''', + '''

robot.move_steering('on_for_seconds', ... ).

'''], + 'direction':['''

Navedi smer premikanja motorjev, naravnost = 0.

''', + '''

robot.move_steering( 'on_for_seconds', direction=0, ... ).

'''], + 'seconds':['''

Napiši časovno omejitev v sekundah.

''', + '''

robot.move_steering( 'on_for_seconds', direction=0, seconds=3 ).

'''], +} diff --git a/robot/problems/introduction/gyrosquare/sl.py~ b/robot/problems/introduction/gyrosquare/sl.py~ new file mode 100644 index 0000000..00171e8 --- /dev/null +++ b/robot/problems/introduction/gyrosquare/sl.py~ @@ -0,0 +1,40 @@ +# coding=utf-8 +import server +mod = server.problems.load_language('python', 'sl') + +id = 210 +name = 'Kvadrat z žiroskopom' +slug = 'Kvadrat z žiroskopom' + +description = '''\ +

Robot naj prevozi kvadrat s stranico 20 cm; pri tem naj si pomaga z žiroskopom.

''' + +hint = { + 'mW_init':['''

Robota v programu predstavimo z mindstorms_widgets(): robot = mindstorms_widgets().

'''], + 'connectMotorLeft':['''

Robotu moramo priključiti levi motor: robot.connect_motor( 'left' ).

'''], + 'connectMotorRight':['''

Robotu moramo priključiti desni motor: robot.connect_motor( 'right' ).

'''], + + 'connectGyro':['''

Robotu priključi žiroskop.

''', + '''

robot.connect_sensor( 'gyro' ).

'''], + 'resetGyro':['''

Žiroskop na začetku resetiraj.

''', + '''

robot.reset_gyro().

'''], + 'setGyroMode':['''

Žiroskopu nastavi način delovanja na merjenje kotov.

''', + '''

robot.gyro_set_mode('angle').

'''], + 'gyroMeasure':['''

Preberi vrednost žiroskopa.

''', + '''

robot.gyro_sensor_measure().

'''], + 'lrPower':['''

Za obrat na mestu se morata kolesi vrteti z enako močjo in v nasprotni smeri.

''', + '''

robot.move_tank( 'on', lr_power=[hitrost, -hitrost], ... ).

'''], + 'moveTank':['''

Robot naj se obrne na mestu.

''', + '''

Najprimernejša metoda za to je move_tank

'''], + 'while':['''

Program naj čaka dokler je kot zasuka manjši od 90 stopinj.

''', + '''

robot.gyro_sensor_measure() < 90:

'''], + + 'moveSteering':['''

Sinhroniziraj motorja in ju zaženi.

''', + '''

Za sinhronizirano vožnjo je najbolj primerna metoda robot.move_steering( ... ).

'''], + 'onForSeconds':['''

Prvi argument metode robot.move_steering naj pove, da bo delovanje motorjev časovno omejeno.

''', + '''

robot.move_steering('on_for_seconds', ... ).

'''], + 'direction':['''

Navedi smer premikanja motorjev, naravnost = 0.

''', + '''

robot.move_steering( 'on_for_seconds', direction=0, ... ).

'''], + 'seconds':['''

Napiši časovno omejitev v sekundah.

''', + '''

robot.move_steering( 'on_for_seconds', direction=0, seconds=3 ).

'''], +} diff --git a/robot/problems/introduction/inline.py b/robot/problems/introduction/inline.py new file mode 100644 index 0000000..67a6f06 --- /dev/null +++ b/robot/problems/introduction/inline.py @@ -0,0 +1,19 @@ +solution = '''\ +from ev3dev import * +from mindstorms_widgets import mindstorms_widgets + +robot = mindstorms_widgets() +robot.connect_motor( 'left' ) +robot.connect_motor( 'right' ) +robot.connect_sensor( 'ultrasonic' ) +robot.move_steering( 'on', power=80 ) +while robot.ultrasonic_sensor_measure( 'distance-cm' ) > 500: + pass +robot.move_steering( 'on', power=20 ) +while robot.ultrasonic_sensor_measure( 'distance-cm' ) > 200: + pass +robot.move_steering( 'off' ) +''' + +print (any(('power' in s and '80' in s and '=' in s) for s in solution.split('\n'))) + diff --git a/robot/problems/introduction/mindstorms_widgets_OLD.py b/robot/problems/introduction/mindstorms_widgets_OLD.py new file mode 100644 index 0000000..4151133 --- /dev/null +++ b/robot/problems/introduction/mindstorms_widgets_OLD.py @@ -0,0 +1,398 @@ +#!/usr/bin/python + +import sys, time +from ev3dev import * +# The mindstorms_widgets class is a wrapper for the python-ev3dev +# language binding. It implements interfaces that correspond directly +# to the action and sensor programming blocks (widgets) from the +# mindstorms LabVIEW software. This allows leverage from the amazing +# documentation already provided by Lego. Some exceptions are: +# * It doesn't auto-detect the devices. You need to call +# connect_motor or connect_sensor first for each device you use +# * Only two large motors and one medium motor are supported. +# This simplifies the interfaces. The motors are referenced by +# the following names in the interfaces: +# 'medium' motor, default Port A +# 'right' large motor, default Port B +# 'left' large motor, default Port C +# * degrees and rotations inputs must always be positive +# use negative power to go backward +# * Rather than having a separate unregulated_motor widget, regulated is an +# an optional input parameter (default = True) +# * motor_rotation_measure, 'current_power' returns both the duty_cycle_sp +# (the actual power level being applied to the motor) and speed_sp +# * sound includes an option to give a sentence and have the robot speak + +# Known issues/limitations +# * The degrees, rotations, speed and invert values provided as inputs do +# not map directly to the values programmed to the sysfs attributes i.e. +# if you don't use mindstorm_widgets methods exclusively to control the +# motors you will need to explicitly initialize all the relevant sysfs +# attributes each time you program the motor from outside mindstorms_widgets +# * led_flash +# * no error handling/recovery +# * volume for tones doesn't work very well (seems to have only 2 levels) +# * when reading the heading and proximity in beacon mode, ir_sensor_measure +# returns good values at first but continuing to poll it seems to result +# in inconsistent values +# * ultrasonic and gyro sensors are not implemented + +# Mindstorms uses the following coefficients to compute speed_sp +# based on a power input in range 0-100 i.e. speed_sp = x * power +# medium motor: x = 16.4 +# large motor : x = 10.3 +# e.g. power of 10 sets medium motor speed_sp to 160 (deg/sec) + +MEDIUM_MOTOR_SPEED_COEFFICIENT = 16.4 +LARGE_MOTOR_SPEED_COEFFICIENT = 10.3 + +class mindstorms_widgets: + def __init__(self): + self.motor = { + 'medium':None, + 'left' :None, + 'right' :None + } + + def _set_motor_attribs( self, size, motors, powers, + invert, regulated, brake_at_end ): + # For regulated speed, speed_sp is tacho counts per + # second which for lego EV3 motors is also degrees per second. + # To provide a mindstorms 0-100 power value for regulated + # speed we need to convert it. + speed_x = LARGE_MOTOR_SPEED_COEFFICIENT + if size == 'medium': + speed_x = MEDIUM_MOTOR_SPEED_COEFFICIENT + + for m,p in zip ( motors, powers ): + # When using run_forever() the sign of speed_sp or duty_cycle_sp + # determines the direction the motor runs. When using + # run_to_rel_pos() the sign of position_sp determines the + # direction and the sign of speed_sp/duty_cycle_sp is ignored by + # the driver. + + # In either case the polarity reverses the direction. + + # When using move_steering, providing a negative power should + # result in reversing along the same path of a positive power + # in the same direction. If the steering is sharp the power of + # one motor is opposite sign of the other. + + # This all combines to make for overly complicated logic when the + # intent is to set motor attribs independent of knowing what + # methods are being used. To avoid this complexity I devised the + # following scheme: + # * Use the motor polarity as the common attribute to determine + # direction since it works the same for run_forever() and + # run_to_rel_pos() + # * Always program duty_cycle_sp and speed_sp to positive values + # * Always program position_sp to a positive value + pol = ['normal','inversed'] + brk = ['coast', 'brake'] + inv = invert + if p < 0: + inv = not invert + p = abs( p ) + if m: + m.polarity = pol[int( inv )] #e.g. True=1='inversed' + m.stop_command = brk[int( brake_at_end )] + #print ('speed: '+str(p)+' inv: '+str(inv)) + if regulated: + m.speed_regulation_enabled = 'on' + m.speed_sp = int( p*speed_x ) + else: + m.speed_regulation_enabled = 'off' + m.duty_cycle_sp = p + + def _move_wait( self ): + # wait for any running motors to finish their movement then stop + # all the motors. + left_is_off = False + right_is_off = False + if 'running' not in self.motor['left'].state: + left_is_off = True + if 'running' not in self.motor['right'].state: + right_is_off = True + while ((left_is_off or 'running' in self.motor['left'].state) and + (right_is_off or 'running' in self.motor['right'].state)): + time.sleep(0.1) + self.motor['left'].stop() + self.motor['right'].stop() + + def _move( self, mode, seconds, degrees, rotations ): + if mode == 'off': + self.motor['left'].stop() + self.motor['right'].stop() + elif mode == 'on': + self.motor['left'].run_forever() + self.motor['right'].run_forever() + elif mode == 'on_for_seconds': + self.motor['left'].run_forever() + self.motor['right'].run_forever() + time.sleep(seconds) + self.motor['left'].stop() + self.motor['right'].stop() + elif mode == 'on_for_degrees': + self.motor['left'].run_to_rel_pos(position_sp=degrees) + self.motor['right'].run_to_rel_pos(position_sp=degrees) + self._move_wait() + elif mode == 'on_for_rotations': + self.motor['left'].run_to_rel_pos( position_sp=int(rotations*360) ) + self.motor['right'].run_to_rel_pos( position_sp=int(rotations*360) ) + self._move_wait() + + def _validate_inputs( self, degrees, rotations ): + if (degrees < 0 or rotations < 0): + print( 'degrees and rotations should be positive. ' + 'Use negative power to go backward' ) + + def _run_motor( self, motor, mode, power, + seconds, degrees, rotations, + invert, regulated, brake_at_end ): + self._validate_inputs( degrees, rotations ) + self._set_motor_attribs( 'medium', [motor], [power], invert, regulated, + brake_at_end ) + if mode == 'off': + motor.stop() + elif mode == 'on': + motor.run_forever() + elif mode == 'on_for_seconds': + motor.run_forever() + time.sleep(seconds) + motor.stop() + elif mode == 'on_for_degrees': + motor.run_to_rel_pos(position_sp=degrees) + while 'running' in motor.state: + time.sleep(0.1) + elif motor and mode == 'on_for_rotations': + motor.run_to_rel_pos(position_sp=int(rotations*360)) + while 'running' in motor.state: + time.sleep(0.1) + + def _led_pulse( self, color ): + # Note that calling flash() multiple times on a LED causes an error + # Disable this routine for now + return + + if color == 'green': + led.green_left.flash( 200, 200 ) + led.green_right.flash( 200, 200 ) + elif color == 'orange': + led.green_left.flash( 200, 200 ) + led.red_left.flash( 200, 200 ) + led.green_right.flash( 200, 200 ) + led.red_right.flash( 200, 200 ) + elif color == 'red': + led.red_left.flash( 200, 200 ) + led.red_right.flash( 200, 200 ) + + + # Begin public methods + + def connect_motor( self, motor, port=None ): + default_port = { + 'medium':'A', + 'left' :'B', + 'right' :'C' + } + + port_enum = { + 'A' :OUTPUT_A, + 'B' :OUTPUT_B, + 'C' :OUTPUT_C, + 'D' :OUTPUT_D + } + if not port: + port = default_port[motor] + port = port.upper() + + if motor == 'medium': + self.motor['medium'] = medium_motor(port_enum[port]) + if not self.motor['medium'].connected: + print("Medium motor not connected to port " + port) + elif motor == 'right': + self.motor['right'] = large_motor(port_enum[port]) + if not self.motor['right'].connected: + print("Large right motor not connected to port " + port) + elif motor == 'left': + self.motor['left'] = large_motor(port_enum[port]) + if not self.motor['left'].connected: + print("Large left motor not connected to port " + port) + + def connect_sensor( self, sensor ): + if sensor == 'color': + self.cs = color_sensor() + if not self.cs.connected: + print("Color sensor not connected") + elif sensor == 'touch': + self.ts = touch_sensor() + if not self.ts.connected: + print("Touch sensor not connected") + elif sensor == 'infrared': + self.irs = infrared_sensor() + if not self.irs.connected: + print("Infrared sensor not connected") + elif sensor == 'gyro': + self.gs = gyro_sensor() + if not self.gs.connected: + print("Gyro sensor not connected") + elif sensor == 'ultrasonic': + self.us = ultrasonic_sensor() + if not self.us.connected: + print("Ultrasonic sensor not connected") + + + def large_motor( self, motor, mode, power=50, + seconds=0, degrees=0, rotations=0, + invert=False, regulated=True, brake_at_end=True ): + self._run_motor( self.motor[motor], mode, power, + seconds, degrees, rotations, + invert, regulated, brake_at_end ) + + def medium_motor( self, mode, power=50, + seconds=0, degrees=0, rotations=0, + invert=False, regulated=True, brake_at_end=True ): + self._run_motor( self.motor['medium'], mode, power, + seconds, degrees, rotations, + invert, regulated, brake_at_end ) + + def move_steering( self, mode, direction=0, power=50, + seconds=0, degrees=0, rotations=0, + invert=False, regulated=True, brake_at_end=True ): + ''' + direction [-100, 100]: + * -100 = pivot left i.e. right motor = power + * left motor = -power + * -50 = sharp left i.e. right motor = power + * left motor = 0 + * -25 = turn left i.e. right motor = power + * left motor = 1/2 power + * 0 = straight + * 25 = turn right + * 50 = sharp right + * 100 = pivot right + ''' + self._validate_inputs( degrees, rotations ) + powers = steering( direction, power ) + self._set_motor_attribs( 'large', + [self.motor['left'], self.motor['right']], + powers, invert, regulated, brake_at_end ) + self._move( mode, seconds, degrees, rotations ) + + def move_tank( self, mode, direction=0, lr_power=None, + seconds=0, degrees=0, rotations=0, + invert=False, regulated=True, brake_at_end=True ): + self._validate_inputs( degrees, rotations ) + if not lr_power: + lr_power=[50,50] + self._set_motor_attribs( 'large', + [self.motor['left'], self.motor['right']], + lr_power, invert, regulated, brake_at_end ) + self._move( mode, seconds, degrees, rotations ) + + def brick_status_light( self, mode, color='green', pulse=False ): + led.all_off() + if mode == 'on': + if color == 'green': + led.green_on() + elif color == 'orange': + led.all_on() + elif color == 'red': + led.red_on() + if mode == 'on' and pulse: + self._led_pulse( color ) + pass + # the sensor should be perfectly still while resetting the gyro + def resetGyro(self): + self.gs.mode = 'GYRO-RATE' + self.gs.mode = 'GYRO-ANG' + + def gyro_sensor_measure( self, mode ): + if mode == 'angle': + self.gs.mode = 'GYRO-ANG' # Angle (degrees), value: (-32768 to 32767) + elif mode == 'rate': + self.gs.mode = 'GYRO-RATE' + return self.gs.value() + + def ultrasonic_sensor_measure( self, mode ): + if mode == 'distance-cm': + self.gs.mode = 'US-DIST-CM' # Continuous measurement of distance (0-2550 mm) + return self.us.value() + + def color_sensor_measure( self, mode ): + if mode == 'color': + self.cs.mode = 'COL-COLOR' + elif mode == 'reflected_light_intensity': + self.cs.mode = 'COL-REFLECT' + elif mode == 'ambient_light_intensity': + self.cs.mode = 'COL-AMBIENT' + return self.cs.value() + + def ir_sensor_measure( self, mode, channel=1 ): + # value(n) returns the given value. See + # http://www.ev3dev.org/docs/sensors/lego-ev3-infrared-sensor/ + i = 2*(channel-1) + if mode == 'proximity': + self.irs.mode = 'IR-PROX' + return self.irs.value() + elif mode == 'beacon': + self.irs.mode = 'IR-SEEK' + # (heading, proximity, detected) + # heading in range (-25,25) + # proximity is -128 or in [0,100] + prox = self.irs.value(i+1) + return( self.irs.value(i), prox, prox != -128 ) + elif mode == 'remote': + self.irs.mode = 'IR-REMOTE' + ''' + 0 = No button (and Beacon Mode is off) + 1 = Button 1 + 2 = Button 2 + 3 = Button 3 + 4 = Button 4 + 5 = Both Button 1 and Button 3 + 6 = Both Button 1 and Button 4 + 7 = Both Button 2 and Button 3 + 8 = Both Button 2 and Button 4 + 9 = Beacon Mode is on + 10 = Both Button 1 and Button 2 + 11 = Both Button 3 and Button 4 + ''' + return self.irs.value( channel-1 ) + + + def motor_rotation_measure( self, motor, mode ): + motor = self.motor[motor] + if mode == 'reset': + motor.position = 0 + return None + if mode == 'current_power': + return (motor.speed, motor.duty_cycle) + degrees=motor.position + if mode == 'degrees': + return degrees + elif mode == 'rotations': + return degrees/360 + + def touch_sensor_measure( self ): + return self.ts.value() + + def sound( self, mode, volume=40, hz=523, path=None, + sentence=None, duration_ms=200 ): + # todo:Volume doesn't seem to work very well for tones. + # 0=just a click + # 1-49 same loud volume tone + # > 50 same volume really loud tone + sound.volume = volume + if mode == 'play_file': + # Sound.rsf files can be extracted from mindstorms by using the + # sound in a mindstorms program then going to mindstorms + # project->sounds tab and choosing "export" + + sound.play( path ) + elif mode == 'play_tone': + sound.tone( int(hz), duration_ms ) + elif mode == 'speak': + sound.speak( sentence, True ) + + diff --git a/robot/problems/introduction/printcolors/common.py b/robot/problems/introduction/printcolors/common.py new file mode 100644 index 0000000..54c3cda --- /dev/null +++ b/robot/problems/introduction/printcolors/common.py @@ -0,0 +1,80 @@ +# coding=utf-8 + +from python.util import has_token_sequence, string_almost_equal, \ + string_contains_number, get_tokens, get_numbers, get_exception_desc +from server.hints import Hint, HintSequence + +id = 211 +group = 'introduction' +number = 9 +visible = True + +solution = '''\ +import time +from ev3dev import * +from mindstorms_widgets import mindstorms_widgets + +color_table = ['none', 'black', 'blue', 'green', 'yellow', 'red', 'white', 'brown'] + +robot = mindstorms_widgets() +robot.connect_motor( 'left' ) +robot.connect_motor( 'right' ) +robot.connect_sensor( 'color' ) + +robot.move_steering( 'on') +start = time.time() +color = -1 +while time.time()-start < 2.1: + c = robot.color_sensor_measure('color') + if c!=color: + print( c, color_table[c]) + color = c +robot.move_steering( 'off' ) +''' + +hint_type = { + 'mW_init': Hint('mW_init'), + 'connectMotorLeft': Hint('connectMotorLeft'), + 'connectMotorRight': Hint('connectMotorRight'), + 'moveSteeringOn': Hint('moveSteeringOn'), + 'moveSteeringOff': Hint('moveSteeringOff'), + 'connectColorSensor': Hint('connectColorSensor'), + 'colorSensorMeasure': Hint('colorSensorMeasure'), + 'while': Hint('while'), + 'print': Hint('print') +} + +def hint( code): + tokens = get_tokens(code) + + # if code does not include mindstorms_widgets(), a student gets a hint that the robot should be somehow represented in the program + if not has_token_sequence(tokens, ['mindstorms_widgets', '(',')']): + return [{'id': 'mW_init'}] + + # if code does not include connect_motor statement, a student needs to learn about how to connect the motors + if not has_token_sequence(tokens, ['connect_motor']) and not has_token_sequence(tokens, ['left']): + return [{'id': 'connectMotorLeft'}] + + # if code does not include connect_motor statement, a student needs to learn about how to connect the motors + if not has_token_sequence(tokens, ['connect_motor']) and not has_token_sequence(tokens, ['right']): + return [{'id': 'connectMotorRight'}] + + if not (has_token_sequence(tokens, ['connect_sensor', '(' ]) and 'color' in code): + return [{'id': 'connectColorSensor'}] + + if not (has_token_sequence(tokens, ['move_steering', '(']) and 'on' in code): + return [{'id': 'moveSteeringOn'}] + + if not (has_token_sequence(tokens, ['move_steering', '(']) and 'off' in code): + return [{'id': 'moveSteeringOff'}] + + if not (has_token_sequence(tokens, ['color_sensor_measure', '(']) and 'color' in code): + return [{'id': 'colorSensorMeasure'}] + + if not has_token_sequence(tokens, ['while']): + return [{'id': 'while'}] + + if not has_token_sequence(tokens, ['print', '(']): + return [{'id': 'print'}] + + return None diff --git a/robot/problems/introduction/printcolors/common.py~ b/robot/problems/introduction/printcolors/common.py~ new file mode 100644 index 0000000..04ca0d6 --- /dev/null +++ b/robot/problems/introduction/printcolors/common.py~ @@ -0,0 +1,80 @@ +# coding=utf-8 + +from python.util import has_token_sequence, string_almost_equal, \ + string_contains_number, get_tokens, get_numbers, get_exception_desc +from server.hints import Hint, HintSequence + +id = 211 +group = 'introduction' +number = 9 +visible = True + +solution = '''\ +import time +from ev3dev import * +from mindstorms_widgets import mindstorms_widgets + +color_table = ['none', 'black', 'blue', 'green', 'yellow', 'red', 'white', 'brown'] + +robot = mindstorms_widgets() +robot.connect_motor( 'left' ) +robot.connect_motor( 'right' ) +robot.connect_sensor( 'color' ) + +robot.move_steering( 'on') +start = time.time() +color = -1 +while time.time()-start < 2.1: + c = robot.color_sensor_measure('color') + if c!=color: + print( c, color_table[c]) + color = c +robot.move_steering( 'off' ) +''' + +hint_type = { + 'mW_init': Hint('mW_init'), + 'connectMotorLeft': Hint('connectMotorLeft'), + 'connectMotorRight': Hint('connectMotorRight'), + 'moveSteeringOn': Hint('moveSteeringOn'), + 'moveSteeringOff': Hint('moveSteeringOff'), + 'connectColorSensor': Hint('connectColorSensor'), + 'colorSensorMeasure': Hint('colorSensorMeasure'), + 'while': Hint('while'), + 'print': Hint('print') +} + +def hint( code): + tokens = get_tokens(code) + + # if code does not include mindstorms_widgets(), a student gets a hint that the robot should be somehow represented in the program + if not has_token_sequence(tokens, ['mindstorms_widgets', '(',')']): + return [{'id': 'mW_init'}] + + # if code does not include connect_motor statement, a student needs to learn about how to connect the motors + if not has_token_sequence(tokens, ['connect_motor']) and not has_token_sequence(tokens, ['left']): + return [{'id': 'connectMotorLeft'}] + + # if code does not include connect_motor statement, a student needs to learn about how to connect the motors + if not has_token_sequence(tokens, ['connect_motor']) and not has_token_sequence(tokens, ['right']): + return [{'id': 'connectMotorRight'}] + + if not has_token_sequence(tokens, ['connect_sensor', '(', 'color', ')' ]): + return [{'id': 'connectColorSensor'}] + + if not has_token_sequence(tokens, ['move_steering', '(', 'on', ')']): + return [{'id': 'moveSteeringOn'}] + + if not has_token_sequence(tokens, ['move_steering', '(', 'off', ')']): + return [{'id': 'moveSteeringOff'}] + + if not has_token_sequence(tokens, ['color_sensor_measure', '(', 'color', ')']): + return [{'id': 'colorSensorMeasure'}] + + if not has_token_sequence(tokens, ['while']): + return [{'id': 'while'}] + + if not has_token_sequence(tokens, ['print', '(']): + return [{'id': 'print'}] + + return None \ No newline at end of file diff --git a/robot/problems/introduction/printcolors/en.py b/robot/problems/introduction/printcolors/en.py new file mode 100644 index 0000000..bb57c9a --- /dev/null +++ b/robot/problems/introduction/printcolors/en.py @@ -0,0 +1,15 @@ +# coding=utf-8 +import server +mod = server.problems.load_language('python', 'en') + +id = 211 +name = 'Color detection' +slug = 'Color detection' + +description = '''\ + +''' + +hint = { + +} diff --git a/robot/problems/introduction/printcolors/naloga09_printColors.py b/robot/problems/introduction/printcolors/naloga09_printColors.py new file mode 100644 index 0000000..59dfdb0 --- /dev/null +++ b/robot/problems/introduction/printcolors/naloga09_printColors.py @@ -0,0 +1,42 @@ +#!/usr/bin/python +# coding=utf-8 + +print (""" +Naloga 9: + Robot naj se pelje cez barvne crte in na zaslon izpise barvo, ki jo zazna s svetlobnim senzorjem. + Value Color + 0 none + 1 black + 2 blue + 3 green + 4 yellow + 5 red + 6 white + 7 brown +""") +import sys +sys.path.append('/home/user/codeq') +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' ) +robot.connect_sensor( 'color' ) + +robot.move_steering( 'on') +start = time.time() +color = -1 +while time.time()-start < 2.1: + c = robot.color_sensor_measure('color') + if c!=color: + print( c, color_table[c]) + color = c +robot.move_steering( 'off' ) diff --git a/robot/problems/introduction/printcolors/sl.py b/robot/problems/introduction/printcolors/sl.py new file mode 100644 index 0000000..d233b0e --- /dev/null +++ b/robot/problems/introduction/printcolors/sl.py @@ -0,0 +1,36 @@ +# coding=utf-8 + +name = 'Zaznavanje barv' +slug = 'Zaznavanje barv' + +description = '''\ +

Robot naj se pelje čez barvne črte in na zaslon izpiše barvo, ki jo zazna s svetlobnim senzorjem. + Value Color + 0 none + 1 black + 2 blue + 3 green + 4 yellow + 5 red + 6 white + 7 brown

''' + +hint = { + 'mW_init':['''

Robota v programu predstavimo z mindstorms_widgets(): robot = mindstorms_widgets().

'''], + 'connectMotorLeft':['''

Robotu priključi levi motor

''', + '''

robot.connect_motor( 'left' ).

'''], + 'connectMotorRight':['''

Robotu priključi desni motor

''', + '''

robot.connect_motor( 'right' ).

'''], + 'moveSteeringOn':['''

Sinhroniziraj motorja in ju zaženi.

''', + '''

Za sinhronizirano vožnjo je najbolj primerna metoda robot.move_steering( 'on' ).

'''], + 'moveSteeringOff':['''

Ustavi motorja.

''', + '''

robot.move_steering( 'off' ).

'''], + 'connectColorSensor':['''

Robotu moramo priključiti barvni senzor.

''', + '''

robot.connect_sensor( 'color' ).

'''], + 'colorSensorMeasure':['''

Medtem ko se robot pomika naprej, naj uporabi barvni senzor v načinu 'color', s katerim pove, katero barvo trenutno vidi.

''', + '''

robot.color_sensor_measure( 'color' ).

'''], + 'while':['''

Uporabi zanko, znotraj katere robot odčitava barve in povečuje števec.

''', + '''

Zanka je lahko časovno omejena, npr. z uporabo metode time.time().

''', + '''

while time.time()-start < 1.1:.

'''], + 'print':['''

V zanki na zaslon izpisuj barvo, ki jo zazna robot.

'''] +} diff --git a/robot/problems/introduction/printcolors/sl.py~ b/robot/problems/introduction/printcolors/sl.py~ new file mode 100644 index 0000000..9d5ec21 --- /dev/null +++ b/robot/problems/introduction/printcolors/sl.py~ @@ -0,0 +1,37 @@ +# coding=utf-8 +import server +mod = server.problems.load_language('python', 'sl') + +id = 211 +name = 'Zaznavanje barv' +slug = 'Zaznavanje barv' + +description = '''\ +

Robot naj se pelje čez barvne črte in na zaslon izpiše barvo, ki jo zazna s svetlobnim senzorjem. + Value Color + 0 none + 1 black + 2 blue + 3 green + 4 yellow + 5 red + 6 white + 7 brown

''' + +hint = { + 'mW_init':['''

Robota v programu predstavimo z mindstorms_widgets(): robot = mindstorms_widgets().

'''], + 'connectMotorLeft':['''

Robotu moramo priključiti levi motor: robot.connect_motor( 'left' ).

'''], + 'connectMotorRight':['''

Robotu moramo priključiti desni motor: robot.connect_motor( 'right' ).

'''], + 'moveSteeringOn':['''

Sinhroniziraj motorja in ju zaženi.

''', + '''

Za sinhronizirano vožnjo je najbolj primerna metoda robot.move_steering( 'on' ).

'''], + 'moveSteeringOff':['''

Ustavi motorja.

''', + '''

robot.move_steering( 'off' ).

'''], + 'connectColorSensor':['''

Robotu moramo priključiti barvni senzor.

''', + '''

robot.connect_sensor( 'color' ).

'''], + 'colorSensorMeasure':['''

Medtem ko se robot pomika naprej, naj uporabi barvni senzor v načinu 'color', s katerim pove, katero barvo trenutno vidi.

''', + '''

robot.color_sensor_measure( 'color' ).

'''], + 'while':['''

Uporabi zanko, znotraj katere robot odčitava barve in povečuje števec.

''', + '''

Zanka je lahko časovno omejena, npr. z uporabo metode time.time().

''', + '''

while time.time()-start < 1.1:.

'''], + 'print':['''

V zanki na zaslon izpisuj barvo, ki jo zazna robot.

'''] +} \ No newline at end of file diff --git a/robot/problems/introduction/rotateback/common.py b/robot/problems/introduction/rotateback/common.py new file mode 100644 index 0000000..c009d37 --- /dev/null +++ b/robot/problems/introduction/rotateback/common.py @@ -0,0 +1,111 @@ +# coding=utf-8 + +from python.util import has_token_sequence, string_almost_equal, \ + string_contains_number, get_tokens, get_numbers, get_exception_desc +from server.hints import Hint, HintSequence + +id = 212 +group = 'introduction' +number = 11 +visible = True + +solution = '''\ +from ev3dev import * +from mindstorms_widgets import mindstorms_widgets + +def sgn(x): + return -1 if x<0 else (1 if x>0 else 0) + +robot = mindstorms_widgets() +robot.connect_motor( 'left' ) +robot.connect_motor( 'right' ) +robot.connect_sensor( 'gyro' ) +robot.connect_sensor( 'touch' ) + +smer = hitrost = 0 +robot.reset_gyro() +robot.gyro_set_mode( 'angle' ) +prev_smer = -1 +while 1: + smer = robot.gyro_sensor_measure() + if smer!=prev_smer: + print ("Kot:", smer) + prev_smer = smer + + if robot.touch_sensor_measure(): + robot.reset_gyro() + print ( robot.gyro_sensor_measure() ) + + 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]) +''' + +hint_type = { + 'mW_init': Hint('mW_init'), + 'connectMotorLeft': Hint('connectMotorLeft'), + 'connectMotorRight': Hint('connectMotorRight'), + 'connectGyro': Hint('connectGyro'), + 'connectTouch': Hint('connectTouch'), + 'resetGyro': Hint('resetGyro'), + 'setGyroMode': Hint('setGyroMode'), + 'gyroMeasure': Hint('gyroMeasure'), + 'ifTouch': Hint('ifTouch'), + 'moveTank': Hint('moveTank'), + 'lrPower': Hint('lrPower'), + 'while': Hint('while') +} + +def hint( code): + tokens = get_tokens(code) + + # if code does not include mindstorms_widgets(), a student gets a hint that the robot should be somehow represented in the program + if not has_token_sequence(tokens, ['mindstorms_widgets', '(',')']): + return [{'id': 'mW_init'}] + + # if code does not include connect_motor statement, a student needs to learn about how to connect the motors + if not has_token_sequence(tokens, ['connect_motor']) and not has_token_sequence(tokens, ['left']): + return [{'id': 'connectMotorLeft'}] + + # if code does not include connect_motor statement, a student needs to learn about how to connect the motors + if not has_token_sequence(tokens, ['connect_motor']) and not has_token_sequence(tokens, ['right']): + return [{'id': 'connectMotorRight'}] + + if not (has_token_sequence(tokens, ['connect_gyro','(']) and 'gyro' in code): + return [{'id': 'connectGyro'}] + + if not (has_token_sequence(tokens, ['connect_sensor','(']) and 'touch' in code): + return [{'id': 'connectTouch'}] + + if not has_token_sequence(tokens, ['reset_gyro']): + return [{'id': 'resetGyro'}] + + if not has_token_sequence(tokens, ['gyro_set_mode']): + return [{'id': 'setGyroMode'}] + + if not has_token_sequence(tokens, ['gyro_sensor_measure']): + return [{'id': 'gyroMeasure'}] + + if not has_token_sequence(tokens, ['if','touch_sensor_measure','(']): + return [{'id': 'ifTouch'}] + + if not has_token_sequence(tokens, ['move_tank']): + return [{'id': 'moveTank'}] + + if not 'lr_power' in code: + return [{'id': 'lrPower'}] + + if not has_token_sequence(tokens, ['while']): + return [{'id': 'while'}] + + return None diff --git a/robot/problems/introduction/rotateback/common.py~ b/robot/problems/introduction/rotateback/common.py~ new file mode 100644 index 0000000..c7c199c --- /dev/null +++ b/robot/problems/introduction/rotateback/common.py~ @@ -0,0 +1,111 @@ +# coding=utf-8 + +from python.util import has_token_sequence, string_almost_equal, \ + string_contains_number, get_tokens, get_numbers, get_exception_desc +from server.hints import Hint, HintSequence + +id = 212 +group = 'introduction' +number = 11 +visible = True + +solution = '''\ +from ev3dev import * +from mindstorms_widgets import mindstorms_widgets + +def sgn(x): + return -1 if x<0 else (1 if x>0 else 0) + +robot = mindstorms_widgets() +robot.connect_motor( 'left' ) +robot.connect_motor( 'right' ) +robot.connect_sensor( 'gyro' ) +robot.connect_sensor( 'touch' ) + +smer = hitrost = 0 +robot.reset_gyro() +robot.gyro_set_mode( 'angle' ) +prev_smer = -1 +while 1: + smer = robot.gyro_sensor_measure() + if smer!=prev_smer: + print ("Kot:", smer) + prev_smer = smer + + if robot.touch_sensor_measure(): + robot.reset_gyro() + print ( robot.gyro_sensor_measure() ) + + 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]) +''' + +hint_type = { + 'mW_init': Hint('mW_init'), + 'connectMotorLeft': Hint('connectMotorLeft'), + 'connectMotorRight': Hint('connectMotorRight'), + 'connectGyro': Hint('connectGyro'), + 'connectTouch': Hint('connectTouch'), + 'resetGyro': Hint('resetGyro'), + 'setGyroMode': Hint('setGyroMode'), + 'gyroMeasure': Hint('gyroMeasure'), + 'ifTouch': Hint('ifTouch'), + 'moveTank': Hint('moveTank'), + 'lrPower': Hint('lrPower'), + 'while': Hint('while') +} + +def hint( code): + tokens = get_tokens(code) + + # if code does not include mindstorms_widgets(), a student gets a hint that the robot should be somehow represented in the program + if not has_token_sequence(tokens, ['mindstorms_widgets', '(',')']): + return [{'id': 'mW_init'}] + + # if code does not include connect_motor statement, a student needs to learn about how to connect the motors + if not has_token_sequence(tokens, ['connect_motor']) and not has_token_sequence(tokens, ['left']): + return [{'id': 'connectMotorLeft'}] + + # if code does not include connect_motor statement, a student needs to learn about how to connect the motors + if not has_token_sequence(tokens, ['connect_motor']) and not has_token_sequence(tokens, ['right']): + return [{'id': 'connectMotorRight'}] + + if not has_token_sequence(tokens, ['connect_gyro','(', 'gyro', ')']): + return [{'id': 'connectGyro'}] + + if not has_token_sequence(tokens, ['connect_sensor','(', 'touch', ')']): + return [{'id': 'connectTouch'}] + + if not has_token_sequence(tokens, ['reset_gyro()']): + return [{'id': 'resetGyro'}] + + if not has_token_sequence(tokens, ['gyro_set_mode']): + return [{'id': 'setGyroMode'}] + + if not has_token_sequence(tokens, ['gyro_sensor_measure()']): + return [{'id': 'gyroMeasure'}] + + if not has_token_sequence(tokens, ['if','touch_sensor_measure','(',')']): + return [{'id': 'ifTouch'}] + + if not has_token_sequence(tokens, ['move_tank']): + return [{'id': 'moveTank'}] + + if not has_token_sequence(tokens, ['lr_power']): + return [{'id': 'lrPower'}] + + if not has_token_sequence(tokens, ['while']): + return [{'id': 'while'}] + + return None diff --git a/robot/problems/introduction/rotateback/en.py b/robot/problems/introduction/rotateback/en.py new file mode 100644 index 0000000..5d8d059 --- /dev/null +++ b/robot/problems/introduction/rotateback/en.py @@ -0,0 +1,15 @@ +# coding=utf-8 +import server +mod = server.problems.load_language('python', 'en') + +id = 212 +name = 'Rotate back' +slug = 'Rotate back' + +description = '''\ + +''' + +hint = { + +} diff --git a/robot/problems/introduction/rotateback/naloga11_rotateBack.py b/robot/problems/introduction/rotateback/naloga11_rotateBack.py new file mode 100644 index 0000000..0bab735 --- /dev/null +++ b/robot/problems/introduction/rotateback/naloga11_rotateBack.py @@ -0,0 +1,48 @@ +#!/usr/bin/python +# coding=utf-8 + +print (""" +Naloga 11: +""") +import sys +sys.path.append('/home/user/codeq') +import time +from ev3dev import * +from mindstorms_widgets import mindstorms_widgets + +def sgn(x): + return -1 if x<0 else (1 if x>0 else 0) + +robot = mindstorms_widgets() +robot.connect_motor( 'left' ) +robot.connect_motor( 'right' ) +robot.connect_sensor( 'gyro' ) +robot.connect_sensor( 'touch' ) + +smer = hitrost = 0 +robot.reset_gyro() +robot.gyro_set_mode( 'angle' ) +prev_smer = -1 +while 1: + smer = robot.gyro_sensor_measure() + if smer!=prev_smer: + print ("Kot:", smer) + prev_smer = smer + + if robot.touch_sensor_measure(): + robot.reset_gyro() + print ( robot.gyro_sensor_measure() ) + + 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]) 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]) 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]) diff --git a/robot/problems/introduction/rotateback/sl.py b/robot/problems/introduction/rotateback/sl.py new file mode 100644 index 0000000..269ea34 --- /dev/null +++ b/robot/problems/introduction/rotateback/sl.py @@ -0,0 +1,33 @@ +# coding=utf-8 + +name = 'Drži smer' +slug = 'Drži smer' + +description = '''\ +

Robot naj drži smer - če ga obrnemo iz začetne smeri, naj se zasuka nazaj v prvotno smer. Ob pritisku na stikalo, naj se resetira (smer nastavi na 0).

''' + +hint = { + 'mW_init':['''

Robota v programu predstavimo z mindstorms_widgets(): robot = mindstorms_widgets().

'''], + 'connectMotorLeft':['''

Robotu priključi levi motor

''', + '''

robot.connect_motor( 'left' ).

'''], + 'connectMotorRight':['''

Robotu priključi desni motor

''', + '''

robot.connect_motor( 'right' ).

'''], + 'connectGyro':['''

Robotu priključi žiroskop

''', + '''

robot.connect_sensor( 'gyro' ).

'''], + 'connectTouch':['''

Robotu priključi stikalo

''', + '''

robot.connect_sensor( 'touch' ).

'''], + 'resetGyro':['''

Žiroskop na začetku in ob pritisku na stikalo resetiraj.

''', + '''

robot.reset_gyro().

'''], + 'setGyroMode':['''

Žiroskopu nastavi način delovanja na merjenje kotov.

''', + '''

robot.gyro_set_mode('angle').

'''], + 'gyroMeasure':['''

Preberi vrednost žiroskopa.

''', + '''

robot.gyro_sensor_measure().

'''], + 'ifTouch':['''

Preveri, če je stikalo pritisnjeno.

''', + '''

if robot.touch_sensor_measure():.

'''], + 'lrPower':['''

Za obrat na mestu se morata kolesi vrteti z enako močjo in v nasprotni smeri.

''', + '''

robot.move_tank( 'on_for_seconds', lr_power=[hitrost, -hitrost], ... ).

'''], + 'moveTank':['''

Robot naj se obrne na mestu.

''', + '''

Najprimernejša metoda za to je move_tank

'''], + 'while':['''

Program naj teče v neskončni zanki.

''', + '''

while 1:

'''], +} diff --git a/robot/problems/introduction/rotateback/sl.py~ b/robot/problems/introduction/rotateback/sl.py~ new file mode 100644 index 0000000..0b91379 --- /dev/null +++ b/robot/problems/introduction/rotateback/sl.py~ @@ -0,0 +1,36 @@ +# coding=utf-8 +import server +mod = server.problems.load_language('python', 'sl') + +id = 212 +name = 'Drži smer' +slug = 'Drži smer' + +description = '''\ +

Robot naj drži smer - če ga obrnemo iz začetne smeri, naj se zasuka nazaj v prvotno smer. Ob pritisku na stikalo, naj se resetira (smer nastavi na 0).

''' + +hint = { + 'mW_init':['''

Robota v programu predstavimo z mindstorms_widgets(): robot = mindstorms_widgets().

'''], + 'connectMotorLeft':['''

Robotu priključi levi motor

''', + '''

robot.connect_motor( 'left' ).

'''], + 'connectMotorRight':['''

Robotu priključi desni motor

''', + '''

robot.connect_motor( 'right' ).

'''], + 'connectGyro':['''

Robotu priključi žiroskop

''', + '''

robot.connect_sensor( 'gyro' ).

'''], + 'connectTouch':['''

Robotu priključi stikalo

''', + '''

robot.connect_sensor( 'touch' ).

'''], + 'resetGyro':['''

Žiroskop na začetku in ob pritisku na stikalo resetiraj.

''', + '''

robot.reset_gyro().

'''], + 'setGyroMode':['''

Žiroskopu nastavi način delovanja na merjenje kotov.

''', + '''

robot.gyro_set_mode('angle').

'''], + 'gyroMeasure':['''

Preberi vrednost žiroskopa.

''', + '''

robot.gyro_sensor_measure().

'''], + 'ifTouch':['''

Preveri, če je stikalo pritisnjeno.

''', + '''

if robot.touch_sensor_measure():.

'''], + 'lrPower':['''

Za obrat na mestu se morata kolesi vrteti z enako močjo in v nasprotni smeri.

''', + '''

robot.move_tank( 'on_for_seconds', lr_power=[hitrost, -hitrost], ... ).

'''], + 'moveTank':['''

Robot naj se obrne na mestu.

''', + '''

Najprimernejša metoda za to je move_tank

'''], + 'while':['''

Program naj teče v neskončni zanki.

''', + '''

while 1:

'''], +} diff --git a/robot/problems/introduction/spotturn90/common.py b/robot/problems/introduction/spotturn90/common.py new file mode 100644 index 0000000..39e9148 --- /dev/null +++ b/robot/problems/introduction/spotturn90/common.py @@ -0,0 +1,60 @@ +# coding=utf-8 + +from python.util import has_token_sequence, string_almost_equal, \ + string_contains_number, get_tokens, get_numbers, get_exception_desc +from server.hints import Hint, HintSequence + +id = 214 +group = 'introduction' +number = 3 +visible = True + +solution = '''\ +from ev3dev import * +from mindstorms_widgets import mindstorms_widgets + +robot = mindstorms_widgets() +robot.connect_motor( 'left' ) +robot.connect_motor( 'right' ) + +robot.move_tank( 'on_for_seconds', lr_power=[20,-20], seconds=.9 ) +''' + +hint_type = { + 'mW_init': Hint('mW_init'), + 'connectMotorLeft': Hint('connectMotorLeft'), + 'connectMotorRight': Hint('connectMotorRight'), + 'moveTank': Hint('moveTank'), + 'onForSeconds': Hint('onForSeconds'), + 'lrPower': Hint('lrPower'), + 'seconds': Hint('seconds'), +} + +def hint( code): + tokens = get_tokens(code) + + # if code does not include mindstorms_widgets(), a student gets a hint that the robot should be somehow represented in the program + if not has_token_sequence(tokens, ['mindstorms_widgets', '(',')']): + return [{'id': 'mW_init'}] + + # if code does not include connect_motor statement, a student needs to learn about how to connect the motors + if not has_token_sequence(tokens, ['connect_motor']) and not has_token_sequence(tokens, ['left']): + return [{'id': 'connectMotorLeft'}] + + # if code does not include connect_motor statement, a student needs to learn about how to connect the motors + if not has_token_sequence(tokens, ['connect_motor']) and not has_token_sequence(tokens, ['right']): + return [{'id': 'connectMotorRight'}] + + if not has_token_sequence(tokens, ['move_tank']): + return [{'id': 'moveTank'}] + + if not 'on_for_seconds' in code: + return [{'id': 'onForSeconds'}] + + if not 'seconds' in code: + return [{'id': 'seconds'}] + + if not 'lr_power' in code: + return [{'id': 'lrPower'}] + + return None diff --git a/robot/problems/introduction/spotturn90/common.py~ b/robot/problems/introduction/spotturn90/common.py~ new file mode 100644 index 0000000..d024bd4 --- /dev/null +++ b/robot/problems/introduction/spotturn90/common.py~ @@ -0,0 +1,61 @@ +# coding=utf-8 + +from python.util import has_token_sequence, string_almost_equal, \ + string_contains_number, get_tokens, get_numbers, get_exception_desc +from server.hints import Hint, HintSequence + +id = 214 +group = 'introduction' +number = 3 +visible = True + +solution = '''\ +import time +from ev3dev import * +from mindstorms_widgets import mindstorms_widgets + +robot = mindstorms_widgets() +robot.connect_motor( 'left' ) +robot.connect_motor( 'right' ) + +robot.move_tank( 'on_for_seconds', lr_power=[20,-20], seconds=.9 ) +''' + +hint_type = { + 'mW_init': Hint('mW_init'), + 'connectMotorLeft': Hint('connectMotorLeft'), + 'connectMotorRight': Hint('connectMotorRight'), + 'moveTank': Hint('moveTank'), + 'onForSeconds': Hint('onForSeconds'), + 'lrPower': Hint('lrPower'), + 'seconds': Hint('seconds'), +} + +def hint( code): + tokens = get_tokens(code) + + # if code does not include mindstorms_widgets(), a student gets a hint that the robot should be somehow represented in the program + if not has_token_sequence(tokens, ['mindstorms_widgets', '(',')']): + return [{'id': 'mW_init'}] + + # if code does not include connect_motor statement, a student needs to learn about how to connect the motors + if not has_token_sequence(tokens, ['connect_motor']) and not has_token_sequence(tokens, ['left']): + return [{'id': 'connectMotorLeft'}] + + # if code does not include connect_motor statement, a student needs to learn about how to connect the motors + if not has_token_sequence(tokens, ['connect_motor']) and not has_token_sequence(tokens, ['right']): + return [{'id': 'connectMotorRight'}] + + if not has_token_sequence(tokens, ['move_tank']): + return [{'id': 'moveTank'}] + + if not has_token_sequence(tokens, ['on_for_seconds']): + return [{'id': 'onForSeconds'}] + + if not has_token_sequence(tokens, ['lr_power']): + return [{'id': 'lrPower'}] + + if not has_token_sequence(tokens, ['seconds']): + return [{'id': 'seconds'}] + + return None diff --git a/robot/problems/introduction/spotturn90/en.py b/robot/problems/introduction/spotturn90/en.py new file mode 100644 index 0000000..348c517 --- /dev/null +++ b/robot/problems/introduction/spotturn90/en.py @@ -0,0 +1,14 @@ +# coding=utf-8 +import server +mod = server.problems.load_language('python', 'en') + +id = 214 +name = 'Turn on spot 90' +slug = 'Turn on spot 90' + +description = '''\ +''' + +hint = { + +} diff --git a/robot/problems/introduction/spotturn90/naloga03_turnOnSpotRight90.py b/robot/problems/introduction/spotturn90/naloga03_turnOnSpotRight90.py new file mode 100644 index 0000000..033290b --- /dev/null +++ b/robot/problems/introduction/spotturn90/naloga03_turnOnSpotRight90.py @@ -0,0 +1,23 @@ +#!/usr/bin/python + +print ("Robot naj se na mestu obrne za 90 stopinj v desno.") +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' ) + +# Solution 1: +#robot.move_tank( 'on_for_seconds', lr_power=[20,-20], seconds=.9 ) + +# Solution 2: +robot.motor['left'].position = 0 +robot.motor['right'].position = 0 +while robot.motor['left'].position <180 or robot.motor['right'].position <180: + robot.large_motor( 'left', 'on', power=10 ) + robot.large_motor( 'right', 'on', power=10 , invert=True) + #print robot.motor['left'].position, robot.motor['right'].position diff --git a/robot/problems/introduction/spotturn90/sl.py b/robot/problems/introduction/spotturn90/sl.py new file mode 100644 index 0000000..fe477aa --- /dev/null +++ b/robot/problems/introduction/spotturn90/sl.py @@ -0,0 +1,21 @@ +# coding=utf-8 + +name = 'Obrat na mestu 90' +slug = 'Obrat na mestu 90' + +description = '''\ +

Robot naj se na mestu obrne za 90 stopinj v desno.

''' + +hint = { + 'mW_init':['''

Robota v programu predstavimo z mindstorms_widgets(): robot = mindstorms_widgets().

'''], + 'connectMotorLeft':['''

Robotu moramo priključiti levi motor: robot.connect_motor( 'left' ).

'''], + 'connectMotorRight':['''

Robotu moramo priključiti desni motor: robot.connect_motor( 'right' ).

'''], + 'moveTank':['''

Robot naj se obrne na mestu.

''', + '''

Najprimernejša metoda za to je move_tank

'''], + 'onForSeconds':['''

Prvi argument metode robot.move_tank naj pove, da bo delovanje motorjev časovno omejeno.

''', + '''

robot.move_tank('on_for_seconds', ... ).

'''], + 'lrPower':['''

Za obrat na mestu se morata kolesi vrteti z enako močjo in v nasprotni smeri.

''', + '''

robot.move_tank( 'on_for_seconds', lr_power=[hitrost, -hitrost], ... ).

'''], + 'seconds':['''

Napiši časovno omejitev v sekundah.

''', + '''

robot.move_tank( 'on_for_seconds', ..., seconds=... ).

'''], +} diff --git a/robot/problems/introduction/spotturn90/sl.py~ b/robot/problems/introduction/spotturn90/sl.py~ new file mode 100644 index 0000000..bc0978c --- /dev/null +++ b/robot/problems/introduction/spotturn90/sl.py~ @@ -0,0 +1,24 @@ +# coding=utf-8 +import server +mod = server.problems.load_language('python', 'sl') + +id = 214 +name = 'Obrat na mestu 90' +slug = 'Obrat na mestu 90' + +description = '''\ +

Robot naj se na mestu obrne za 90 stopinj v desno.

''' + +hint = { + 'mW_init':['''

Robota v programu predstavimo z mindstorms_widgets(): robot = mindstorms_widgets().

'''], + 'connectMotorLeft':['''

Robotu moramo priključiti levi motor: robot.connect_motor( 'left' ).

'''], + 'connectMotorRight':['''

Robotu moramo priključiti desni motor: robot.connect_motor( 'right' ).

'''], + 'moveTank':['''

Robot naj se obrne na mestu.

''', + '''

Najprimernejša metoda za to je move_tank

'''], + 'onForSeconds':['''

Prvi argument metode robot.move_tank naj pove, da bo delovanje motorjev časovno omejeno.

''', + '''

robot.move_tank('on_for_seconds', ... ).

'''], + 'lrPower':['''

Za obrat na mestu se morata kolesi vrteti z enako močjo in v nasprotni smeri.

''', + '''

robot.move_tank( 'on_for_seconds', lr_power=[hitrost, -hitrost], ... ).

'''], + 'seconds':['''

Napiši časovno omejitev v sekundah.

''', + '''

robot.move_tank( 'on_for_seconds', ..., seconds=... ).

'''], +} \ No newline at end of file diff --git a/robot/problems/introduction/square20/common.py b/robot/problems/introduction/square20/common.py new file mode 100644 index 0000000..f868a1c --- /dev/null +++ b/robot/problems/introduction/square20/common.py @@ -0,0 +1,76 @@ +# coding=utf-8 + +from python.util import has_token_sequence, string_almost_equal, \ + string_contains_number, get_tokens, get_numbers, get_exception_desc +from server.hints import Hint, HintSequence + +id = 213 +group = 'introduction' +number = 4 +visible = True + +solution = '''\ +from ev3dev import * +from mindstorms_widgets import mindstorms_widgets + +robot = mindstorms_widgets() +robot.connect_motor( 'left' ) +robot.connect_motor( 'right' ) + +turntime = .95 +robot.move_steering( 'on_for_seconds', direction=0, power=20, seconds=2 ) +robot.move_tank( 'on_for_seconds', lr_power=[20,-20], seconds=turntime ) +robot.move_steering( 'on_for_seconds', direction=0, power=20, seconds=2 ) +robot.move_tank( 'on_for_seconds', lr_power=[20,-20], seconds=turntime ) +robot.move_steering( 'on_for_seconds', direction=0, power=20, seconds=2 ) +robot.move_tank( 'on_for_seconds', lr_power=[20,-20], seconds=turntime ) +robot.move_steering( 'on_for_seconds', direction=0, power=20, seconds=2 ) +robot.move_tank( 'on_for_seconds', lr_power=[20,-20], seconds=turntime ) +''' + +hint_type = { + 'mW_init': Hint('mW_init'), + 'connectMotorLeft': Hint('connectMotorLeft'), + 'connectMotorRight': Hint('connectMotorRight'), + 'moveSteering': Hint('moveSteering'), + 'onForSeconds': Hint('onForSeconds'), + 'direction': Hint('direction'), + 'seconds': Hint('seconds'), + 'moveTank': Hint('moveTank'), + 'lrPower': Hint('lrPower') +} + +def hint( code): + tokens = get_tokens(code) + + # if code does not include mindstorms_widgets(), a student gets a hint that the robot should be somehow represented in the program + if not has_token_sequence(tokens, ['mindstorms_widgets', '(',')']): + return [{'id': 'mW_init'}] + + # if code does not include connect_motor statement, a student needs to learn about how to connect the motors + if not has_token_sequence(tokens, ['connect_motor']) and not has_token_sequence(tokens, ['left']): + return [{'id': 'connectMotorLeft'}] + + # if code does not include connect_motor statement, a student needs to learn about how to connect the motors + if not has_token_sequence(tokens, ['connect_motor']) and not has_token_sequence(tokens, ['right']): + return [{'id': 'connectMotorRight'}] + + if not has_token_sequence(tokens, ['move_steering']): + return [{'id': 'moveSteering'}] + + if not 'on_for_seconds' in code: + return [{'id': 'onForSeconds'}] + + if not 'direction' in code: + return [{'id': 'direction'}] + + if not 'seconds' in code: + return [{'id': 'seconds'}] + + if not has_token_sequence(tokens, ['move_tank']): + return [{'id': 'moveTank'}] + + if not 'lr_power' in code: + return [{'id': 'lrPower'}] + + return None diff --git a/robot/problems/introduction/square20/common.py~ b/robot/problems/introduction/square20/common.py~ new file mode 100644 index 0000000..f868a1c --- /dev/null +++ b/robot/problems/introduction/square20/common.py~ @@ -0,0 +1,76 @@ +# coding=utf-8 + +from python.util import has_token_sequence, string_almost_equal, \ + string_contains_number, get_tokens, get_numbers, get_exception_desc +from server.hints import Hint, HintSequence + +id = 213 +group = 'introduction' +number = 4 +visible = True + +solution = '''\ +from ev3dev import * +from mindstorms_widgets import mindstorms_widgets + +robot = mindstorms_widgets() +robot.connect_motor( 'left' ) +robot.connect_motor( 'right' ) + +turntime = .95 +robot.move_steering( 'on_for_seconds', direction=0, power=20, seconds=2 ) +robot.move_tank( 'on_for_seconds', lr_power=[20,-20], seconds=turntime ) +robot.move_steering( 'on_for_seconds', direction=0, power=20, seconds=2 ) +robot.move_tank( 'on_for_seconds', lr_power=[20,-20], seconds=turntime ) +robot.move_steering( 'on_for_seconds', direction=0, power=20, seconds=2 ) +robot.move_tank( 'on_for_seconds', lr_power=[20,-20], seconds=turntime ) +robot.move_steering( 'on_for_seconds', direction=0, power=20, seconds=2 ) +robot.move_tank( 'on_for_seconds', lr_power=[20,-20], seconds=turntime ) +''' + +hint_type = { + 'mW_init': Hint('mW_init'), + 'connectMotorLeft': Hint('connectMotorLeft'), + 'connectMotorRight': Hint('connectMotorRight'), + 'moveSteering': Hint('moveSteering'), + 'onForSeconds': Hint('onForSeconds'), + 'direction': Hint('direction'), + 'seconds': Hint('seconds'), + 'moveTank': Hint('moveTank'), + 'lrPower': Hint('lrPower') +} + +def hint( code): + tokens = get_tokens(code) + + # if code does not include mindstorms_widgets(), a student gets a hint that the robot should be somehow represented in the program + if not has_token_sequence(tokens, ['mindstorms_widgets', '(',')']): + return [{'id': 'mW_init'}] + + # if code does not include connect_motor statement, a student needs to learn about how to connect the motors + if not has_token_sequence(tokens, ['connect_motor']) and not has_token_sequence(tokens, ['left']): + return [{'id': 'connectMotorLeft'}] + + # if code does not include connect_motor statement, a student needs to learn about how to connect the motors + if not has_token_sequence(tokens, ['connect_motor']) and not has_token_sequence(tokens, ['right']): + return [{'id': 'connectMotorRight'}] + + if not has_token_sequence(tokens, ['move_steering']): + return [{'id': 'moveSteering'}] + + if not 'on_for_seconds' in code: + return [{'id': 'onForSeconds'}] + + if not 'direction' in code: + return [{'id': 'direction'}] + + if not 'seconds' in code: + return [{'id': 'seconds'}] + + if not has_token_sequence(tokens, ['move_tank']): + return [{'id': 'moveTank'}] + + if not 'lr_power' in code: + return [{'id': 'lrPower'}] + + return None diff --git a/robot/problems/introduction/square20/en.py b/robot/problems/introduction/square20/en.py new file mode 100644 index 0000000..907acfe --- /dev/null +++ b/robot/problems/introduction/square20/en.py @@ -0,0 +1,14 @@ +# coding=utf-8 +import server +mod = server.problems.load_language('python', 'en') + +id = 213 +name = 'Square 20' +slug = 'Square 20' + +description = '''\ +''' + +hint = { + +} diff --git a/robot/problems/introduction/square20/naloga04_square20.py b/robot/problems/introduction/square20/naloga04_square20.py new file mode 100644 index 0000000..171c4b8 --- /dev/null +++ b/robot/problems/introduction/square20/naloga04_square20.py @@ -0,0 +1,21 @@ +#!/usr/bin/python + +print "Robot naj enkrat prevozi kvadrat s stranico 20 cm." + +import time +from ev3dev import * +from mindstorms_widgets import mindstorms_widgets + +robot = mindstorms_widgets() +robot.connect_motor( 'left' ) +robot.connect_motor( 'right' ) + +turntime = .95 +robot.move_steering( 'on_for_seconds', direction=0, power=20, seconds=2 ) +robot.move_tank( 'on_for_seconds', lr_power=[20,-20], seconds=turntime ) +robot.move_steering( 'on_for_seconds', direction=0, power=20, seconds=2 ) +robot.move_tank( 'on_for_seconds', lr_power=[20,-20], seconds=turntime ) +robot.move_steering( 'on_for_seconds', direction=0, power=20, seconds=2 ) +robot.move_tank( 'on_for_seconds', lr_power=[20,-20], seconds=turntime ) +robot.move_steering( 'on_for_seconds', direction=0, power=20, seconds=2 ) +robot.move_tank( 'on_for_seconds', lr_power=[20,-20], seconds=turntime ) \ No newline at end of file diff --git a/robot/problems/introduction/square20/sl.py b/robot/problems/introduction/square20/sl.py new file mode 100644 index 0000000..f52ddf7 --- /dev/null +++ b/robot/problems/introduction/square20/sl.py @@ -0,0 +1,29 @@ +# coding=utf-8 + +name = 'Kvadrat 20 cm' +slug = 'Kvadrat 20 cm' + +description = '''\ +

Robot naj enkrat prevozi kvadrat s stranico 20 cm.

''' + +hint = { + 'mW_init':['''

Robota v programu predstavimo z mindstorms_widgets(): robot = mindstorms_widgets().

'''], + 'connectMotorLeft':['''

Robotu priključi levi motor

''', + '''

robot.connect_motor( 'left' ).

'''], + 'connectMotorRight':['''

Robotu priključi desni motor

''', + '''

robot.connect_motor( 'right' ).

'''], + 'moveSteering':['''

Sinhroniziraj motorja in ju zaženi.

''', + '''

Za sinhronizirano vožnjo je najbolj primerna metoda robot.move_steering( ... ).

'''], + 'onForSeconds':['''

Prvi argument metode robot.move_steering naj pove, da bo delovanje motorjev časovno omejeno.

''', + '''

robot.move_steering('on_for_seconds', ... ).

'''], + 'direction':['''

Navedi smer premikanja motorjev, naravnost = 0.

''', + '''

robot.move_steering( 'on_for_seconds', direction=0, ... ).

'''], + 'seconds':['''

Napiši časovno omejitev v sekundah.

''', + '''

robot.move_steering( 'on_for_seconds', direction=0, seconds=... ).

''', + '''

robot.move_tank( 'on_for_seconds', lr_power=[20,-20], seconds=.95 ).

''',], + 'moveTank': ['''

Robot naj se obrne na mestu.

''', + '''

Najprimernejša metoda za to je move_tank

''', + '''

robot.move_tank( 'on_for_seconds', ... ).

'''], + 'lrPower': ['''

Za obrat na mestu se morata kolesi vrteti z enako močjo in v nasprotni smeri.

''', + '''

robot.move_tank( 'on_for_seconds', lr_power=[20,-20], seconds=.95 ).

'''], +} diff --git a/robot/problems/introduction/square20/sl.py~ b/robot/problems/introduction/square20/sl.py~ new file mode 100644 index 0000000..aa5137e --- /dev/null +++ b/robot/problems/introduction/square20/sl.py~ @@ -0,0 +1,27 @@ +# coding=utf-8 + +name = 'Kvadrat 20 cm' +slug = 'Kvadrat 20 cm' + +description = '''\ +

Robot naj enkrat prevozi kvadrat s stranico 20 cm.

''' + +hint = { + 'mW_init':['''

Robota v programu predstavimo z mindstorms_widgets(): robot = mindstorms_widgets().

'''], + 'connectMotorLeft':['''

Robotu moramo priključiti levi motor: robot.connect_motor( 'left' ).

'''], + 'connectMotorRight':['''

Robotu moramo priključiti desni motor: robot.connect_motor( 'right' ).

'''], + 'moveSteering':['''

Sinhroniziraj motorja in ju zaženi.

''', + '''

Za sinhronizirano vožnjo je najbolj primerna metoda robot.move_steering( ... ).

'''], + 'onForSeconds':['''

Prvi argument metode robot.move_steering naj pove, da bo delovanje motorjev časovno omejeno.

''', + '''

robot.move_steering('on_for_seconds', ... ).

'''], + 'direction':['''

Navedi smer premikanja motorjev, naravnost = 0.

''', + '''

robot.move_steering( 'on_for_seconds', direction=0, ... ).

'''], + 'seconds':['''

Napiši časovno omejitev v sekundah.

''', + '''

robot.move_steering( 'on_for_seconds', direction=0, seconds=... ).

''', + '''

robot.move_tank( 'on_for_seconds', lr_power=[20,-20], seconds=.95 ).

''',], + 'moveTank': ['''

Robot naj se obrne na mestu.

''', + '''

Najprimernejša metoda za to je move_tank

''', + '''

robot.move_tank( 'on_for_seconds', ... ).

'''], + 'lrPower': ['''

Za obrat na mestu se morata kolesi vrteti z enako močjo in v nasprotni smeri.

''', + '''

robot.move_tank( 'on_for_seconds', lr_power=[20,-20], seconds=.95 ).

'''], +} diff --git a/robot/problems/introduction/wall1m/common.py b/robot/problems/introduction/wall1m/common.py new file mode 100644 index 0000000..319cea2 --- /dev/null +++ b/robot/problems/introduction/wall1m/common.py @@ -0,0 +1,80 @@ +# coding=utf-8 + +from python.util import has_token_sequence, string_almost_equal, \ + string_contains_number, get_tokens, get_numbers, get_exception_desc +from server.hints import Hint, HintSequence + +id = 215 +group = 'introduction' +number = 6 +visible = True + +solution = '''\ +from ev3dev import * +from mindstorms_widgets import mindstorms_widgets + +robot = mindstorms_widgets() +robot.connect_motor( 'left' ) +robot.connect_motor( 'right' ) +robot.connect_sensor( 'ultrasonic' ) +robot.move_steering( 'on', power=80 ) +while robot.ultrasonic_sensor_measure( 'distance-cm' ) > 500: + pass +robot.move_steering( 'on', power=20 ) +while robot.ultrasonic_sensor_measure( 'distance-cm' ) > 200: + pass +robot.move_steering( 'off' ) +''' + +hint_type = { + 'mW_init': Hint('mW_init'), + 'connectMotorLeft': Hint('connectMotorLeft'), + 'connectMotorRight': Hint('connectMotorRight'), + 'moveSteeringOn': Hint('moveSteeringOn'), + 'moveSteeringOff': Hint('moveSteeringOff'), + 'connectUltrasonicSensor': Hint('connectUltrasonicSensor'), + 'ultrasonicSensorMeasure': Hint('ultrasonicSensorMeasure'), + 'power80': Hint('power80'), + 'power20': Hint('power20'), + 'while': Hint('while') +} + +def hint( code ): + tokens = get_tokens(code) + lines = code.split('\n') + + # if code does not include mindstorms_widgets(), a student gets a hint that the robot should be somehow represented in the program + if not has_token_sequence(tokens, ['mindstorms_widgets', '(',')']): + return [{'id': 'mW_init'}] + + # if code does not include connect_motor statement, a student needs to learn about how to connect the motors + if not has_token_sequence(tokens, ['connect_motor']) and not has_token_sequence(tokens, ['left']): + return [{'id': 'connectMotorLeft'}] + + # if code does not include connect_motor statement, a student needs to learn about how to connect the motors + if not has_token_sequence(tokens, ['connect_motor']) and not has_token_sequence(tokens, ['right']): + return [{'id': 'connectMotorRight'}] + + if not (has_token_sequence(tokens, ['connect_sensor', '(']) and 'ultrasonic' in code) : + return [{'id': 'connectUltrasonicSensor'}] + + if not (has_token_sequence(tokens, ['move_steering', '(']) and 'on' in code): + return [{'id': 'moveSteeringOn'}] + + if not (has_token_sequence(tokens, ['move_steering', '(']) and 'off' in code): + return [{'id': 'moveSteeringOff'}] + + #if not (has_token_sequence(tokens, ['ultrasonic_sensor_measure', '(']) and 'distance-cm' in code): + if not any(('ultrasonic_sensor_measure' in s and '(' in s and 'distance-cm' in s) for s in lines) + return [{'id': 'ultrasonicSensorMeasure'}] + + if not any(('power' in s and '80' in s and '=' in s) for s in lines): + return [{'id': 'power80'}] + + if not any(('power' in s and '20' in s and '=' in s) for s in lines): + return [{'id': 'power20'}] + + if not has_token_sequence(tokens, ['while']): + return [{'id': 'while'}] + + return None diff --git a/robot/problems/introduction/wall1m/common.py~ b/robot/problems/introduction/wall1m/common.py~ new file mode 100644 index 0000000..319cea2 --- /dev/null +++ b/robot/problems/introduction/wall1m/common.py~ @@ -0,0 +1,80 @@ +# coding=utf-8 + +from python.util import has_token_sequence, string_almost_equal, \ + string_contains_number, get_tokens, get_numbers, get_exception_desc +from server.hints import Hint, HintSequence + +id = 215 +group = 'introduction' +number = 6 +visible = True + +solution = '''\ +from ev3dev import * +from mindstorms_widgets import mindstorms_widgets + +robot = mindstorms_widgets() +robot.connect_motor( 'left' ) +robot.connect_motor( 'right' ) +robot.connect_sensor( 'ultrasonic' ) +robot.move_steering( 'on', power=80 ) +while robot.ultrasonic_sensor_measure( 'distance-cm' ) > 500: + pass +robot.move_steering( 'on', power=20 ) +while robot.ultrasonic_sensor_measure( 'distance-cm' ) > 200: + pass +robot.move_steering( 'off' ) +''' + +hint_type = { + 'mW_init': Hint('mW_init'), + 'connectMotorLeft': Hint('connectMotorLeft'), + 'connectMotorRight': Hint('connectMotorRight'), + 'moveSteeringOn': Hint('moveSteeringOn'), + 'moveSteeringOff': Hint('moveSteeringOff'), + 'connectUltrasonicSensor': Hint('connectUltrasonicSensor'), + 'ultrasonicSensorMeasure': Hint('ultrasonicSensorMeasure'), + 'power80': Hint('power80'), + 'power20': Hint('power20'), + 'while': Hint('while') +} + +def hint( code ): + tokens = get_tokens(code) + lines = code.split('\n') + + # if code does not include mindstorms_widgets(), a student gets a hint that the robot should be somehow represented in the program + if not has_token_sequence(tokens, ['mindstorms_widgets', '(',')']): + return [{'id': 'mW_init'}] + + # if code does not include connect_motor statement, a student needs to learn about how to connect the motors + if not has_token_sequence(tokens, ['connect_motor']) and not has_token_sequence(tokens, ['left']): + return [{'id': 'connectMotorLeft'}] + + # if code does not include connect_motor statement, a student needs to learn about how to connect the motors + if not has_token_sequence(tokens, ['connect_motor']) and not has_token_sequence(tokens, ['right']): + return [{'id': 'connectMotorRight'}] + + if not (has_token_sequence(tokens, ['connect_sensor', '(']) and 'ultrasonic' in code) : + return [{'id': 'connectUltrasonicSensor'}] + + if not (has_token_sequence(tokens, ['move_steering', '(']) and 'on' in code): + return [{'id': 'moveSteeringOn'}] + + if not (has_token_sequence(tokens, ['move_steering', '(']) and 'off' in code): + return [{'id': 'moveSteeringOff'}] + + #if not (has_token_sequence(tokens, ['ultrasonic_sensor_measure', '(']) and 'distance-cm' in code): + if not any(('ultrasonic_sensor_measure' in s and '(' in s and 'distance-cm' in s) for s in lines) + return [{'id': 'ultrasonicSensorMeasure'}] + + if not any(('power' in s and '80' in s and '=' in s) for s in lines): + return [{'id': 'power80'}] + + if not any(('power' in s and '20' in s and '=' in s) for s in lines): + return [{'id': 'power20'}] + + if not has_token_sequence(tokens, ['while']): + return [{'id': 'while'}] + + return None diff --git a/robot/problems/introduction/wall1m/en.py b/robot/problems/introduction/wall1m/en.py new file mode 100644 index 0000000..ec91c7b --- /dev/null +++ b/robot/problems/introduction/wall1m/en.py @@ -0,0 +1,14 @@ +# coding=utf-8 +import server +mod = server.problems.load_language('python', 'en') + +id = 215 +name = 'To the wall' +slug = 'To the wall' + +description = '''\ +''' + +hint = { + +} diff --git a/robot/problems/introduction/wall1m/naloga06_wall1m.py b/robot/problems/introduction/wall1m/naloga06_wall1m.py new file mode 100644 index 0000000..e3be37c --- /dev/null +++ b/robot/problems/introduction/wall1m/naloga06_wall1m.py @@ -0,0 +1,27 @@ +#!/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' ) +robot.connect_sensor( 'ultrasonic' ) +robot.move_steering( 'on', power=80 ) +while robot.ultrasonic_sensor_measure( 'distance-cm' ) > 500: + pass +robot.move_steering( 'on', power=20 ) +while robot.ultrasonic_sensor_measure( 'distance-cm' ) > 200: + pass +robot.move_steering( 'off' ) + diff --git a/robot/problems/introduction/wall1m/naloga06_wall1m.py~ b/robot/problems/introduction/wall1m/naloga06_wall1m.py~ new file mode 100644 index 0000000..f7e6bad --- /dev/null +++ b/robot/problems/introduction/wall1m/naloga06_wall1m.py~ @@ -0,0 +1,31 @@ +#!/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 time +from ev3dev import * +from mindstorms_widgets import mindstorms_widgets + +us = ultrasonic_sensor(); assert us.connected +us.mode = 'US-DIST-CM' # Continuous measurement of distance (0-2550 mm) + +# for m in us.modes: +# print "\t",m +#exit() +robot = mindstorms_widgets() +robot.connect_motor( 'left' ) +robot.connect_motor( 'right' ) + +robot.move_steering( 'on', power=80 ) +while us.value()>500: + pass +robot.move_steering( 'on', power=20 ) +while us.value()>200: + pass +robot.move_steering( 'off' ) 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' ) diff --git a/robot/problems/introduction/wall1m/sl.py b/robot/problems/introduction/wall1m/sl.py new file mode 100644 index 0000000..18518d5 --- /dev/null +++ b/robot/problems/introduction/wall1m/sl.py @@ -0,0 +1,31 @@ +# coding=utf-8 + +name = 'Pelji do zida' +slug = 'Pelji do zida' + +description = '''\ +

Robota postavi pred zid, tako da bo od njega oddaljen vsaj 1 m; vmes naj ne bo ovir. + Napiši program, s katerim bo robot vozil naravnost proti zidu z 80% močjo. + Na razdalji 50 cm od zida naj robot zmanjša hitrost na 20%, na razdalji 20 cm od zida pa naj se ustavi.

''' + +hint = { + 'mW_init':['''

Robota v programu predstavimo z mindstorms_widgets(): robot = mindstorms_widgets().

'''], + 'connectMotorLeft':['''

Robotu priključi levi motor

''', + '''

robot.connect_motor( 'left' ).

'''], + 'connectMotorRight':['''

Robotu priključi desni motor

''', + '''

robot.connect_motor( 'right' ).

'''], + 'moveSteeringOn':['''

Sinhroniziraj motorja in ju zaženi.

''', + '''

Za sinhronizirano vožnjo je najbolj primerna metoda robot.move_steering( 'on' ).

'''], + 'moveSteeringOff':['''

Ustavi motorja.

''', + '''

robot.move_steering( 'off' ).

'''], + 'power80': ['''

Nastavi moč motorjev na 80%.

''', + '''

robot.move_steering( 'on', power=80 ).

'''], + 'power20': ['''

Nastavi moč motorjev na 20%.

''', + '''

robot.move_steering( 'on', power=20 ).

'''], + 'connectUltrasonicSensor':['''

Robotu moramo priključiti ultrazvočni senzor.

''', + '''

robot.connect_sensor( 'ultrasonic' ).

'''], + 'ultrasonicSensorMeasure':['''

Medtem ko se robot pomika naprej, naj uporabi ultrazvočni senzor v načinu 'distance-cm', s katerim meri razdaljo v cm.

''', + '''

robot.ultrasonic_sensor_measure( 'distance-cm' ).

'''], + 'while':['''

Uporabi zanko: robot naj se pelje naprej, dokler ne pride do razdalje 50 cm od zida.

''', + '''

Uporabi še eno zanko: robot naj se pelje naprej z 20% močjo, dokler ne pride do razdalje 20 cm od zida.

'''], +} diff --git a/robot/problems/introduction/wall1m/sl.py~ b/robot/problems/introduction/wall1m/sl.py~ new file mode 100644 index 0000000..8455bab --- /dev/null +++ b/robot/problems/introduction/wall1m/sl.py~ @@ -0,0 +1,31 @@ +# coding=utf-8 + +name = 'Pelji do zida' +slug = 'Pelji do zida' + +description = '''\ +

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.

''' + +hint = { + 'mW_init':['''

Robota v programu predstavimo z mindstorms_widgets(): robot = mindstorms_widgets().

'''], + 'connectMotorLeft':['''

Robotu priključi levi motor

''', + '''

robot.connect_motor( 'left' ).

'''], + 'connectMotorRight':['''

Robotu priključi desni motor

''', + '''

robot.connect_motor( 'right' ).

'''], + 'moveSteeringOn':['''

Sinhroniziraj motorja in ju zaženi.

''', + '''

Za sinhronizirano vožnjo je najbolj primerna metoda robot.move_steering( 'on' ).

'''], + 'moveSteeringOff':['''

Ustavi motorja.

''', + '''

robot.move_steering( 'off' ).

'''], + 'power80': ['''

Nastavi moč motorjev na 80%.

''', + '''

robot.move_steering( 'on', power=80 ).

'''], + 'power20': ['''

Nastavi moč motorjev na 20%.

''', + '''

robot.move_steering( 'on', power=20 ).

'''], + 'connectUltrasonicSensor':['''

Robotu moramo priključiti ultrazvočni senzor.

''', + '''

robot.connect_sensor( 'ultrasonic' ).

'''], + 'ultrasonicSensorMeasure':['''

Medtem ko se robot pomika naprej, naj uporabi ultrazvočni senzor v načinu 'distance-cm', s katerim meri razdaljo v cm.

''', + '''

robot.ultrasonic_sensor_measure( 'distance-cm' ).

'''], + 'while':['''

Uporabi zanko: robot naj se pelje naprej, dokler ne pride do razdalje 50 cm od zida.

''', + '''

Uporabi še eno zanko: robot naj se pelje naprej z 20% močjo, dokler ne pride do razdalje 20 cm od zida.

'''], +} -- cgit v1.2.1 From a86a6ca92d315dedf3ce4d5035a4c38178f8b531 Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Tue, 13 Oct 2015 13:00:05 +0200 Subject: Remove backup files and add *~ to .gitignore --- robot/problems/introduction/circle20/common.py~ | 63 ------------ robot/problems/introduction/circle20/sl.py~ | 24 ----- robot/problems/introduction/countlines/common.py~ | 79 --------------- robot/problems/introduction/countlines/sl.py~ | 29 ------ robot/problems/introduction/followline/common.py~ | 85 ---------------- robot/problems/introduction/followline/sl.py~ | 35 ------- robot/problems/introduction/forward/common.py~ | 60 ----------- robot/problems/introduction/forward/en.py~ | 20 ---- robot/problems/introduction/forward/sl.py~ | 23 ----- robot/problems/introduction/forward1m/common.py~ | 61 ----------- robot/problems/introduction/forward1m/sl.py~ | 24 ----- robot/problems/introduction/gyro90/common.py~ | 80 --------------- .../introduction/gyro90/naloga07_gyro90.py~ | 34 ------- robot/problems/introduction/gyro90/sl.py~ | 32 ------ robot/problems/introduction/gyrosquare/common.py~ | 103 ------------------- robot/problems/introduction/gyrosquare/sl.py~ | 40 -------- robot/problems/introduction/printcolors/common.py~ | 80 --------------- robot/problems/introduction/printcolors/sl.py~ | 37 ------- robot/problems/introduction/rotateback/common.py~ | 111 --------------------- robot/problems/introduction/rotateback/sl.py~ | 36 ------- robot/problems/introduction/spotturn90/common.py~ | 61 ----------- robot/problems/introduction/spotturn90/sl.py~ | 24 ----- robot/problems/introduction/square20/common.py~ | 76 -------------- robot/problems/introduction/square20/sl.py~ | 27 ----- robot/problems/introduction/wall1m/common.py~ | 80 --------------- .../introduction/wall1m/naloga06_wall1m.py~ | 31 ------ robot/problems/introduction/wall1m/sl.py~ | 31 ------ 27 files changed, 1386 deletions(-) delete mode 100644 robot/problems/introduction/circle20/common.py~ delete mode 100644 robot/problems/introduction/circle20/sl.py~ delete mode 100644 robot/problems/introduction/countlines/common.py~ delete mode 100644 robot/problems/introduction/countlines/sl.py~ delete mode 100644 robot/problems/introduction/followline/common.py~ delete mode 100644 robot/problems/introduction/followline/sl.py~ delete mode 100644 robot/problems/introduction/forward/common.py~ delete mode 100644 robot/problems/introduction/forward/en.py~ delete mode 100644 robot/problems/introduction/forward/sl.py~ delete mode 100644 robot/problems/introduction/forward1m/common.py~ delete mode 100644 robot/problems/introduction/forward1m/sl.py~ delete mode 100644 robot/problems/introduction/gyro90/common.py~ delete mode 100644 robot/problems/introduction/gyro90/naloga07_gyro90.py~ delete mode 100644 robot/problems/introduction/gyro90/sl.py~ delete mode 100644 robot/problems/introduction/gyrosquare/common.py~ delete mode 100644 robot/problems/introduction/gyrosquare/sl.py~ delete mode 100644 robot/problems/introduction/printcolors/common.py~ delete mode 100644 robot/problems/introduction/printcolors/sl.py~ delete mode 100644 robot/problems/introduction/rotateback/common.py~ delete mode 100644 robot/problems/introduction/rotateback/sl.py~ delete mode 100644 robot/problems/introduction/spotturn90/common.py~ delete mode 100644 robot/problems/introduction/spotturn90/sl.py~ delete mode 100644 robot/problems/introduction/square20/common.py~ delete mode 100644 robot/problems/introduction/square20/sl.py~ delete mode 100644 robot/problems/introduction/wall1m/common.py~ delete mode 100644 robot/problems/introduction/wall1m/naloga06_wall1m.py~ delete mode 100644 robot/problems/introduction/wall1m/sl.py~ (limited to 'robot/problems') diff --git a/robot/problems/introduction/circle20/common.py~ b/robot/problems/introduction/circle20/common.py~ deleted file mode 100644 index eb171ae..0000000 --- a/robot/problems/introduction/circle20/common.py~ +++ /dev/null @@ -1,63 +0,0 @@ -# coding=utf-8 - -from python.util import has_token_sequence, string_almost_equal, \ - string_contains_number, get_tokens, get_numbers, get_exception_desc -from server.hints import Hint, HintSequence - -id = 205 -group = 'introduction' -number = 5 -visible = True - -solution = '''\ -import time -from ev3dev import * -from mindstorms_widgets import mindstorms_widgets - -robot = mindstorms_widgets() -robot.connect_motor( 'left' ) -robot.connect_motor( 'right' ) - -fct = 9 # full circle time -rad = 20 # Direction to make a good radius for the circle -robot.move_steering( 'on_for_seconds', direction=rad, power=40, seconds=fct ) -''' - -hint_type = { - 'mW_init': Hint('mW_init'), - 'connectMotorLeft': Hint('connectMotorLeft'), - 'connectMotorRight': Hint('connectMotorRight'), - 'moveSteering': Hint('moveSteering'), - 'onForSeconds': Hint('onForSeconds'), - 'direction': Hint('direction'), - 'seconds': Hint('seconds'), -} - -def hint( code): - tokens = get_tokens(code) - - # if code does not include mindstorms_widgets(), a student gets a hint that the robot should be somehow represented in the program - if not has_token_sequence(tokens, ['mindstorms_widgets', '(',')']): - return [{'id': 'mW_init'}] - - # if code does not include connect_motor statement, a student needs to learn about how to connect the motors - if not has_token_sequence(tokens, ['connect_motor']) and not has_token_sequence(tokens, ['left']): - return [{'id': 'connectMotorLeft'}] - - # if code does not include connect_motor statement, a student needs to learn about how to connect the motors - if not has_token_sequence(tokens, ['connect_motor']) and not has_token_sequence(tokens, ['right']): - return [{'id': 'connectMotorRight'}] - - if not has_token_sequence(tokens, ['move_steering']): - return [{'id': 'moveSteering'}] - - if not has_token_sequence(tokens, ['on_for_seconds']): - return [{'id': 'onForSeconds'}] - - if not has_token_sequence(tokens, ['direction']): - return [{'id': 'direction'}] - - if not has_token_sequence(tokens, ['seconds']): - return [{'id': 'seconds'}] - - return None diff --git a/robot/problems/introduction/circle20/sl.py~ b/robot/problems/introduction/circle20/sl.py~ deleted file mode 100644 index 656253d..0000000 --- a/robot/problems/introduction/circle20/sl.py~ +++ /dev/null @@ -1,24 +0,0 @@ -# coding=utf-8 - -id = 205 -name = 'Krog 20 cm' -slug = 'Krog 20 cm' - -description = '''\ -

Napiši program, s katerim bo robot enkrat prevozil krog s polmerom 20 cm in se nato ustavil.

''' - -hint = { - 'mW_init':['''

Robota v programu predstavimo z mindstorms_widgets(): robot = mindstorms_widgets().

'''], - 'connectMotorLeft':['''

Robotu moramo priključiti levi motor: robot.connect_motor( 'left' ).

'''], - 'connectMotorRight':['''

Robotu moramo priključiti desni motor: robot.connect_motor( 'right' ).

'''], - 'moveSteering':['''

Sinhroniziraj motorja in ju zaženi za 3 sekunde.

''', - '''

Za sinhronizirano vožnjo je najbolj primerna metoda robot.move_steering( ... ).

'''], - 'onForSeconds':['''

Prvi argument metode robot.move_steering naj pove, da bo delovanje motorjev časovno omejeno.

''', - '''

robot.move_steering('on_for_seconds', ... ).

'''], - 'direction':['''

Navedi smer premikanja motorjev; pozitivne vrednosti pomenijo zavoj v desno.

''', - '''

Določi vrednost parametra direction tako, da bo robot krožil po krogu s polmerom 20cm. Vrednost je odvisna od konstrukcije robota in podlage.

''', - '''

robot.move_steering( 'on_for_seconds', direction=20, ... ).

'''], - 'seconds':['''

Napiši časovno omejitev v sekundah.

''', - '''

Za dani polmer izmeri čas, ki ga robot potrebuje za en obhod.

''', - '''

robot.move_steering( 'on_for_seconds', direction=0, seconds=3 ).

'''], -} diff --git a/robot/problems/introduction/countlines/common.py~ b/robot/problems/introduction/countlines/common.py~ deleted file mode 100644 index 6e5d135..0000000 --- a/robot/problems/introduction/countlines/common.py~ +++ /dev/null @@ -1,79 +0,0 @@ -# coding=utf-8 - -from python.util import has_token_sequence, string_almost_equal, \ - string_contains_number, get_tokens, get_numbers, get_exception_desc -from server.hints import Hint, HintSequence - -id = 206 -group = 'introduction' -number = 10 -visible = True - -solution = '''\ -import time -from ev3dev import * -from mindstorms_widgets import mindstorms_widgets - -color_table = ['none', 'black', 'blue', 'green', 'yellow', 'red', 'white', 'brown'] - -robot = mindstorms_widgets() -robot.connect_motor( 'left' ) -robot.connect_motor( 'right' ) -robot.connect_sensor( 'color' ) - -robot.move_steering( 'on' ) -start = time.time() -stevec = 0 -color = -1 -while time.time()-start < 2.1: - c = robot.color_sensor_measure( 'color' ) # values: 0-7 see the scale above - if c!=color: - if c!=6 and c!=0: - stevec += 1 - color = c -robot.move_steering( 'off' ) -print( "Stevilo crt:", stevec ) -''' - -hint_type = { - 'mW_init': Hint('mW_init'), - 'connectMotorLeft': Hint('connectMotorLeft'), - 'connectMotorRight': Hint('connectMotorRight'), - 'moveSteeringOn': Hint('moveSteeringOn'), - 'moveSteeringOff': Hint('moveSteeringOff'), - 'connectColorSensor': Hint('connectColorSensor'), - 'colorSensorMeasure': Hint('colorSensorMeasure'), - 'while': Hint('while') -} - -def hint( code): - tokens = get_tokens(code) - - # if code does not include mindstorms_widgets(), a student gets a hint that the robot should be somehow represented in the program - if not has_token_sequence(tokens, ['mindstorms_widgets', '(',')']): - return [{'id': 'mW_init'}] - - # if code does not include connect_motor statement, a student needs to learn about how to connect the motors - if not has_token_sequence(tokens, ['connect_motor']) and not has_token_sequence(tokens, ['left']): - return [{'id': 'connectMotorLeft'}] - - # if code does not include connect_motor statement, a student needs to learn about how to connect the motors - if not has_token_sequence(tokens, ['connect_motor']) and not has_token_sequence(tokens, ['right']): - return [{'id': 'connectMotorRight'}] - - if not (has_token_sequence(tokens, ['connect_sensor', '(' ]) and 'color' in code): - return [{'id': 'connectColorSensor'}] - - if not has_token_sequence(tokens, ['move_steering', '(', 'on', ')']): - return [{'id': 'moveSteeringOn'}] - - if not has_token_sequence(tokens, ['move_steering', '(', 'off', ')']): - return [{'id': 'moveSteeringOff'}] - - if not (has_token_sequence(tokens, ['color_sensor_measure', '(']) and 'color' in code): - return [{'id': 'colorSensorMeasure'}] - - if not has_token_sequence(tokens, ['while']): - return [{'id': 'while'}] - - return None diff --git a/robot/problems/introduction/countlines/sl.py~ b/robot/problems/introduction/countlines/sl.py~ deleted file mode 100644 index 6b759ad..0000000 --- a/robot/problems/introduction/countlines/sl.py~ +++ /dev/null @@ -1,29 +0,0 @@ -# coding=utf-8 -import server -mod = server.problems.load_language('python', 'sl') - -id = 206 -name = 'Preštej črte' -slug = 'Preštej črte' - -description = '''\ -

Robot naj pelje naravnost, pravokotno na črte in naj jih prešteje.

''' - -hint = { - 'mW_init':['''

Robota v programu predstavimo z mindstorms_widgets(): robot = mindstorms_widgets().

'''], - 'connectMotorLeft':['''

Robotu priključi levi motor

''', - '''

robot.connect_motor( 'left' ).

'''], - 'connectMotorRight':['''

Robotu priključi desni motor

''', - '''

robot.connect_motor( 'right' ).

'''], - 'moveSteeringOn':['''

Sinhroniziraj motorja in ju zaženi.

''', - '''

Za sinhronizirano vožnjo je najbolj primerna metoda robot.move_steering( 'on' ).

'''], - 'moveSteeringOff':['''

Ustavi motorja.

''', - '''

robot.move_steering( 'off' ).

'''], - 'connectColorSensor':['''

Robotu moramo priključiti barvni senzor.

''', - '''

robot.connect_sensor( 'color' ).

'''], - 'colorSensorMeasure':['''

Medtem ko se robot pomika naprej, naj uporabi barvni senzor v načinu 'color', s katerim pove, katero barvo trenutno vidi.

''', - '''

robot.color_sensor_measure( 'color' ).

'''], - 'while':['''

Uporabi zanko, znotraj katere robot odčitava barve in povečuje števec.

''', - '''

Zanka je lahko časovno omejena, npr. z uporabo metode time.time().

''', - '''

while time.time()-start < 1.1:.

'''], -} diff --git a/robot/problems/introduction/followline/common.py~ b/robot/problems/introduction/followline/common.py~ deleted file mode 100644 index 5a3db5b..0000000 --- a/robot/problems/introduction/followline/common.py~ +++ /dev/null @@ -1,85 +0,0 @@ -# coding=utf-8 - -from python.util import has_token_sequence, string_almost_equal, \ - string_contains_number, get_tokens, get_numbers, get_exception_desc -from server.hints import Hint, HintSequence - -id = 207 -group = 'introduction' -number = 12 -visible = True - -solution = '''\ -import time -from ev3dev import * -from mindstorms_widgets import mindstorms_widgets - -robot = mindstorms_widgets() -robot.connect_motor( 'left' ) -robot.connect_motor( 'right' ) -robot.connect_sensor( 'color' ) - -start = time.time() -while time.time()-start < 10: - if robot.color_sensor_measure('reflected_light_intensity') < 30: - L, R = 0, 20 - else: - L, R = 20, 0 - robot.move_tank( 'on', lr_power=[L,R]) -robot.move_tank( 'off' ) -''' - -hint_type = { - 'mW_init': Hint('mW_init'), - 'connectMotorLeft': Hint('connectMotorLeft'), - 'connectMotorRight': Hint('connectMotorRight'), - 'moveTankOn': Hint('moveTankOn'), - 'lrPower': Hint('lr_power'), - 'moveTankOff': Hint('moveTankOff'), - 'connectColorSensor': Hint('connectColorSensor'), - 'colorSensorMeasureRLI': Hint('colorSensorMeasureRLI'), - 'while': Hint('while'), - 'time': Hint('time'), - 'if': Hint('if') -} - -def hint( code): - tokens = get_tokens(code) - - # if code does not include mindstorms_widgets(), a student gets a hint that the robot should be somehow represented in the program - if not has_token_sequence(tokens, ['mindstorms_widgets', '(',')']): - return [{'id': 'mW_init'}] - - # if code does not include connect_motor statement, a student needs to learn about how to connect the motors - if not has_token_sequence(tokens, ['connect_motor']) and not has_token_sequence(tokens, ['left']): - return [{'id': 'connectMotorLeft'}] - - # if code does not include connect_motor statement, a student needs to learn about how to connect the motors - if not has_token_sequence(tokens, ['connect_motor']) and not has_token_sequence(tokens, ['right']): - return [{'id': 'connectMotorRight'}] - - if not has_token_sequence(tokens, ['connect_sensor', '(', 'color', ')' ]): - return [{'id': 'connectColorSensor'}] - - if not has_token_sequence(tokens, ['move_tank', '(', 'on', ')']): - return [{'id': 'moveTankOn'}] - - if not has_token_sequence(tokens, ['lr_power']): - return [{'id': 'lrPower'}] - - if not has_token_sequence(tokens, ['move_tank', '(', 'off', ')']): - return [{'id': 'moveTankOff'}] - - if not has_token_sequence(tokens, ['color_sensor_measure', '(', 'reflected_light_intensity', ')']): - return [{'id': 'colorSensorMeasureRLI'}] - - if not has_token_sequence(tokens, ['while']): - return [{'id': 'while'}] - - if not has_token_sequence(tokens, ['time']): - return [{'id': 'time'}] - - if not has_token_sequence(tokens, ['if']): - return [{'id': 'if'}] - - return None diff --git a/robot/problems/introduction/followline/sl.py~ b/robot/problems/introduction/followline/sl.py~ deleted file mode 100644 index 5d201fe..0000000 --- a/robot/problems/introduction/followline/sl.py~ +++ /dev/null @@ -1,35 +0,0 @@ -# coding=utf-8 -import server -mod = server.problems.load_language('python', 'sl') - -id = 207 -name = 'Sledenje črti' -slug = 'Sledenje črti' - -description = '''\ -

Robot naj 10 sekund sledi črni črti na beli podlagi; pri tem naj si pomaga z barvnim senzorjem.

''' - -hint = { - 'mW_init':['''

Robota v programu predstavimo z mindstorms_widgets(): robot = mindstorms_widgets().

'''], - 'connectMotorLeft':['''

Robotu moramo priključiti levi motor: robot.connect_motor( 'left' ).

'''], - 'connectMotorRight':['''

Robotu moramo priključiti desni motor: robot.connect_motor( 'right' ).

'''], - - 'moveTankOn':['''

Uporabi metodo za ločen nadzor motorjev, s katero vsakemu od motorjev nastavljaš drugačno moč.

''', - '''

Za to je najbolj primerna metoda robot.move_tank( ... ).

''', - '''

robot.move_tank( 'on', ...)

'''], - 'lrPower': ['''

Nastavi parameter s katerim nastaviš moči levega in desnega motorja.

''', - '''

robot.move_tank( 'on', lr_power=[ ... ])

'''], - 'moveTankOff': ['''Ustavi robota.''', - '''

robot.move_tank( 'off' )

'''], - 'connectColorSensor':['''

Robotu moramo priključiti barvni senzor.

''', - '''

robot.connect_sensor( 'color' ).

'''], - 'colorSensorMeasureRLI':['''

Medtem ko se robot pomika naprej, naj uporabi barvni senzor v načinu 'reflected_light_intensity', za zaznavanje jakosti odbite svetlobe.

''', - '''

robot.color_sensor_measure( 'reflected_light_intensity' ).

'''], - 'while':['''

Uporabi zanko, znotraj katere robot sledi črti.

''', - '''

Zanka naj bo časovno omejena, npr. z uporabo metode time.time().

''', - '''

start = time.time()\nwhile time.time()-start < 10:.

'''], - 'time': ['''Uporabi metodo time() za merjenje časa.''', - '''

start = time.time()\nwhile time.time()-start < 10:

'''], - 'if': ['''

V zanki uporabi pogojni stavek...

''', - '''

Če robot vidi črto, naj zavije z nje; če vidi podlago, naj zavije proti črti.

'''] -} \ No newline at end of file diff --git a/robot/problems/introduction/forward/common.py~ b/robot/problems/introduction/forward/common.py~ deleted file mode 100644 index f6330fd..0000000 --- a/robot/problems/introduction/forward/common.py~ +++ /dev/null @@ -1,60 +0,0 @@ -# coding=utf-8 - -from python.util import has_token_sequence, string_almost_equal, \ - string_contains_number, get_tokens, get_numbers, get_exception_desc -from server.hints import Hint, HintSequence - -id = 202 -number = 1 -visible = True - -solution = '''\ -import time -from ev3dev import * -from mindstorms_widgets import mindstorms_widgets - -robot = mindstorms_widgets() -robot.connect_motor( 'left' ) -robot.connect_motor( 'right' ) - -robot.move_steering( 'on_for_seconds', direction=0, seconds=3 ) -''' - -hint_type = { - 'mW_init': Hint('mW_init'), - 'connectMotorLeft': Hint('connectMotorLeft'), - 'connectMotorRight': Hint('connectMotorRight'), - 'moveSteering': Hint('moveSteering'), - 'onForSeconds': Hint('onForSeconds'), - 'direction': Hint('direction'), - 'seconds': Hint('seconds'), -} - -def hint( code): - tokens = get_tokens(code) - - # if code does not include mindstorms_widgets(), a student gets a hint that the robot should be somehow represented in the program - if not has_token_sequence(tokens, ['mindstorms_widgets', '(',')']): - return [{'id': 'mW_init'}] - - # if code does not include connect_motor statement, a student needs to learn about how to connect the motors - if not has_token_sequence(tokens, ['connect_motor']) and not has_token_sequence(tokens, ['left']): - return [{'id': 'connectMotorLeft'}] - - # if code does not include connect_motor statement, a student needs to learn about how to connect the motors - if not has_token_sequence(tokens, ['connect_motor']) and not has_token_sequence(tokens, ['right']): - return [{'id': 'connectMotorRight'}] - - if not has_token_sequence(tokens, ['move_steering']): - return [{'id': 'moveSteering'}] - - if not has_token_sequence(tokens, ['on_for_seconds']): - return [{'id': 'onForSeconds'}] - - if not has_token_sequence(tokens, ['direction']): - return [{'id': 'direction'}] - - if not has_token_sequence(tokens, ['seconds']): - return [{'id': 'seconds'}] - - return None diff --git a/robot/problems/introduction/forward/en.py~ b/robot/problems/introduction/forward/en.py~ deleted file mode 100644 index 4337ac5..0000000 --- a/robot/problems/introduction/forward/en.py~ +++ /dev/null @@ -1,20 +0,0 @@ -# coding=utf-8 -import server -mod = server.problems.load_language('python', 'en') - -<<<<<<< HEAD -id = 202 -name = 'Forward 3s' -slug = 'Forward 3s' -======= -name = 'Forward' -slug = 'Forward' ->>>>>>> 5a01c2bb184152c6ccc3c536e9b857d247bc55ad - -description = '''\ -

Write a program that would make the robot drive straight forward for 3 seconds and stop

-''' - -hint = { - -} diff --git a/robot/problems/introduction/forward/sl.py~ b/robot/problems/introduction/forward/sl.py~ deleted file mode 100644 index a6f7e86..0000000 --- a/robot/problems/introduction/forward/sl.py~ +++ /dev/null @@ -1,23 +0,0 @@ -# coding=utf-8 - -name = 'Naprej 3s' -slug = 'Naprej 3s' - -description = '''\ -

Napiši program, da bo robot peljal naravnost naprej 3 sekunde in se nato ustavil.

''' - -hint = { - 'mW_init':['''

Robota v programu predstavimo z mindstorms_widgets(): robot = mindstorms_widgets().

'''], - 'connectMotorLeft':['''

Robotu priključi levi motor

''', - '''

robot.connect_motor( 'left' ).

'''], - 'connectMotorRight':['''

Robotu priključi desni motor

''', - '''

robot.connect_motor( 'right' ).

'''], - 'moveSteering':['''

Sinhroniziraj motorja in ju zaženi za 3 sekunde.

''', - '''

Za sinhronizirano vožnjo je najbolj primerna metoda robot.move_steering( ... ).

'''], - 'onForSeconds':['''

Prvi argument metode robot.move_steering naj pove, da bo delovanje motorjev časovno omejeno.

''', - '''

robot.move_steering('on_for_seconds', ... ).

'''], - 'direction':['''

Navedi smer premikanja motorjev, naravnost = 0.

''', - '''

robot.move_steering( 'on_for_seconds', direction=0, ... ).

'''], - 'seconds':['''

Napiši časovno omejitev v sekundah.

''', - '''

robot.move_steering( 'on_for_seconds', direction=0, seconds=3 ).

'''], -} diff --git a/robot/problems/introduction/forward1m/common.py~ b/robot/problems/introduction/forward1m/common.py~ deleted file mode 100644 index 809fe9d..0000000 --- a/robot/problems/introduction/forward1m/common.py~ +++ /dev/null @@ -1,61 +0,0 @@ -# coding=utf-8 - -from python.util import has_token_sequence, string_almost_equal, \ - string_contains_number, get_tokens, get_numbers, get_exception_desc -from server.hints import Hint, HintSequence - -id = 208 -group = 'introduction' -number = 2 -visible = True - -solution = '''\ -import time -from ev3dev import * -from mindstorms_widgets import mindstorms_widgets - -robot = mindstorms_widgets() -robot.connect_motor( 'left' ) -robot.connect_motor( 'right' ) - -robot.move_steering( 'on_for_rotations', direction=0, rotations=5.71 ) -''' - -hint_type = { - 'mW_init': Hint('mW_init'), - 'connectMotorLeft': Hint('connectMotorLeft'), - 'connectMotorRight': Hint('connectMotorRight'), - 'moveSteering': Hint('moveSteering'), - 'onForRotations': Hint('onForRotations'), - 'direction': Hint('direction'), - 'rotations': Hint('rotations'), -} - -def hint(code): - tokens = get_tokens(code) - - # if code does not include mindstorms_widgets(), a student gets a hint that the robot should be somehow represented in the program - if not has_token_sequence(tokens, ['mindstorms_widgets', '(',')']): - return [{'id': 'mW_init'}] - - # if code does not include connect_motor statement, a student needs to learn about how to connect the motors - if not has_token_sequence(tokens, ['connect_motor']) and not has_token_sequence(tokens, ['left']): - return [{'id': 'connectMotorLeft'}] - - # if code does not include connect_motor statement, a student needs to learn about how to connect the motors - if not has_token_sequence(tokens, ['connect_motor']) and not has_token_sequence(tokens, ['right']): - return [{'id': 'connectMotorRight'}] - - if not has_token_sequence(tokens, ['move_steering']): - return [{'id': 'moveSteering'}] - - if not has_token_sequence(tokens, ['on_for_rotations']): - return [{'id': 'onForRotations'}] - - if not has_token_sequence(tokens, ['direction']): - return [{'id': 'direction'}] - - if not has_token_sequence(tokens, ['rotations']): - return [{'id': 'rotations'}] - - return None diff --git a/robot/problems/introduction/forward1m/sl.py~ b/robot/problems/introduction/forward1m/sl.py~ deleted file mode 100644 index e8071ee..0000000 --- a/robot/problems/introduction/forward1m/sl.py~ +++ /dev/null @@ -1,24 +0,0 @@ -# coding=utf-8 -import server -mod = server.problems.load_language('python', 'sl') - -id = 208 -name = 'Naprej 1m' -slug = 'Naprej 1m' - -description = '''\ -

Napiši program, da bo robot peljal naravnost naprej 3 sekunde in se nato ustavil.

''' - -hint = { - 'mW_init':['''

Robota v programu predstavimo z mindstorms_widgets(): robot = mindstorms_widgets().

'''], - 'connectMotorLeft':['''

Robotu moramo priključiti levi motor: robot.connect_motor( 'left' ).

'''], - 'connectMotorRight':['''

Robotu moramo priključiti desni motor: robot.connect_motor( 'right' ).

'''], - 'moveSteering':['''

Sinhroniziraj motorja in ju zaženi za 3 sekunde.

''', - '''

Za sinhronizirano vožnjo je najbolj primerna metoda robot.move_steering( ... ).

'''], - 'onForRotations':['''

Prvi argument metode robot.move_steering naj pove, da bo delovanje motorjev določeno s številom obratov.

''', - '''

robot.move_steering('on_for_rotations', ... ).

'''], - 'direction':['''

Navedi smer premikanja motorjev, naravnost = 0.

''', - '''

robot.move_steering( 'on_for_rotations', direction=0, ... ).

'''], - 'rotations':['''

Določi število obratov; za koliko obratov naj se zavrtita motorja? Izmeri dolžino 1m, izpisuj obrate print(robot.motor['left'].count_per_rot, robot.motor['right'].count_per_rot) in tako določi ustrezno število obratov.

''', - '''

robot.move_steering( 'on_for_rotations', direction=0, rotations=5 ).

'''], -} diff --git a/robot/problems/introduction/gyro90/common.py~ b/robot/problems/introduction/gyro90/common.py~ deleted file mode 100644 index c02a2c4..0000000 --- a/robot/problems/introduction/gyro90/common.py~ +++ /dev/null @@ -1,80 +0,0 @@ -# coding=utf-8 - -from python.util import has_token_sequence, string_almost_equal, \ - string_contains_number, get_tokens, get_numbers, get_exception_desc -from server.hints import Hint, HintSequence - -id = 209 -group = 'introduction' -number = 7 -visible = True - -solution = '''\ -from ev3dev import * -from mindstorms_widgets import mindstorms_widgets - -robot = mindstorms_widgets() -robot.connect_motor( 'left' ) -robot.connect_motor( 'right' ) -robot.connect_sensor( 'gyro' ) - -robot.gyro_set_mode( 'angle' ) -robot.reset_gyro() - -power = 15 -robot.move_tank( 'on', lr_power=[power,-power] ) -while robot.gyro_sensor_measure() < 90: - pass -robot.move_tank( 'off' ) -''' - -hint_type = { - 'mW_init': Hint('mW_init'), - 'connectMotorLeft': Hint('connectMotorLeft'), - 'connectMotorRight': Hint('connectMotorRight'), - 'connectGyro': Hint('connectGyro'), - 'resetGyro': Hint('resetGyro'), - 'setGyroMode': Hint('setGyroMode'), - 'gyroMeasure': Hint('gyroMeasure'), - 'moveTank': Hint('moveTank'), - 'lrPower': Hint('lrPower'), - 'while': Hint('while') -} - -def hint( code): - tokens = get_tokens(code) - - # if code does not include mindstorms_widgets(), a student gets a hint that the robot should be somehow represented in the program - if not has_token_sequence(tokens, ['mindstorms_widgets', '(',')']): - return [{'id': 'mW_init'}] - - # if code does not include connect_motor statement, a student needs to learn about how to connect the motors - if not has_token_sequence(tokens, ['connect_motor']) and not has_token_sequence(tokens, ['left']): - return [{'id': 'connectMotorLeft'}] - - # if code does not include connect_motor statement, a student needs to learn about how to connect the motors - if not has_token_sequence(tokens, ['connect_motor']) and not has_token_sequence(tokens, ['right']): - return [{'id': 'connectMotorRight'}] - - if not has_token_sequence(tokens, ['connect_gyro','(', 'gyro', ')']): - return [{'id': 'connectGyro'}] - - if not has_token_sequence(tokens, ['reset_gyro()']): - return [{'id': 'resetGyro'}] - - if not has_token_sequence(tokens, ['gyro_set_mode']): - return [{'id': 'setGyroMode'}] - - if not has_token_sequence(tokens, ['gyro_sensor_measure()']): - return [{'id': 'gyroMeasure'}] - - if not has_token_sequence(tokens, ['move_tank']): - return [{'id': 'moveTank'}] - - if not has_token_sequence(tokens, ['lr_power']): - return [{'id': 'lrPower'}] - - if not has_token_sequence(tokens, ['while']): - return [{'id': 'while'}] - - return None diff --git a/robot/problems/introduction/gyro90/naloga07_gyro90.py~ b/robot/problems/introduction/gyro90/naloga07_gyro90.py~ deleted file mode 100644 index 97e42ee..0000000 --- a/robot/problems/introduction/gyro90/naloga07_gyro90.py~ +++ /dev/null @@ -1,34 +0,0 @@ -#!/usr/bin/python -# coding=utf-8 - -print """ -Naloga 7: - Robot naj se na mestu obrne za 90 stopinj v desno; pri tem naj si pomaga z ziroskopom. -""" - -import time -from ev3dev import * -from mindstorms_widgets import mindstorms_widgets - -gs = gyro_sensor(); -assert gs.connected -gs.mode = 'GYRO-ANG' # Angle (degrees), value: (-32768 to 32767) - -# for m in us.modes: -# print "\t",m -#exit() -robot = mindstorms_widgets() -robot.connect_motor( 'left' ) -robot.connect_motor( 'right' ) - -power = 15 -robot.move_tank( 'on', lr_power=[power,-power] ) -while gs.value()<90: - pass -robot.move_tank( 'off', brake_at_end=True ) -# print gs.value() -# gs = gyro_sensor(); -# assert gs.connected -# gs.mode = 'GYRO-ANG' -# -# print "--->",gs.value() \ No newline at end of file diff --git a/robot/problems/introduction/gyro90/sl.py~ b/robot/problems/introduction/gyro90/sl.py~ deleted file mode 100644 index 76939f7..0000000 --- a/robot/problems/introduction/gyro90/sl.py~ +++ /dev/null @@ -1,32 +0,0 @@ -# coding=utf-8 -import server -mod = server.problems.load_language('python', 'sl') - -id = 209 -name = 'Žiroskop 90' -slug = 'Žiroskop 90' - -description = '''\ -

Robot naj se na mestu obrne za 90 stopinj v desno; pri tem naj si pomaga z žiroskopom.

''' - -hint = { - 'mW_init':['''

Robota v programu predstavimo z mindstorms_widgets(): robot = mindstorms_widgets().

'''], - 'connectMotorLeft':['''

Robotu priključi levi motor.

''', - '''

robot.connect_motor( 'left' ).

'''], - 'connectMotorRight':['''

Robotu priključi desni motor.

''', - '''

robot.connect_motor( 'right' ).

'''], - 'connectGyro':['''

Robotu priključi žiroskop.

''', - '''

robot.connect_sensor( 'gyro' ).

'''], - 'resetGyro':['''

Žiroskop na začetku resetiraj.

''', - '''

robot.reset_gyro().

'''], - 'setGyroMode':['''

Žiroskopu nastavi način delovanja na merjenje kotov.

''', - '''

robot.gyro_set_mode('angle').

'''], - 'gyroMeasure':['''

Preberi vrednost žiroskopa.

''', - '''

robot.gyro_sensor_measure().

'''], - 'lrPower':['''

Za obrat na mestu se morata kolesi vrteti z enako močjo in v nasprotni smeri.

''', - '''

robot.move_tank( 'on', lr_power=[hitrost, -hitrost], ... ).

'''], - 'moveTank':['''

Robot naj se obrne na mestu.

''', - '''

Najprimernejša metoda za to je move_tank

'''], - 'while':['''

Program naj teče dokler je kot zasuka manjši od 90 stopinj.

''', - '''

robot.gyro_sensor_measure() < 90:

'''], -} \ No newline at end of file diff --git a/robot/problems/introduction/gyrosquare/common.py~ b/robot/problems/introduction/gyrosquare/common.py~ deleted file mode 100644 index 1c31f92..0000000 --- a/robot/problems/introduction/gyrosquare/common.py~ +++ /dev/null @@ -1,103 +0,0 @@ -# coding=utf-8 - -from python.util import has_token_sequence, string_almost_equal, \ - string_contains_number, get_tokens, get_numbers, get_exception_desc -from server.hints import Hint, HintSequence - -id = 210 -group = 'introduction' -number = 8 -visible = True - -solution = '''\ -from ev3dev import * -from mindstorms_widgets import mindstorms_widgets - -robot = mindstorms_widgets() -robot.connect_motor( 'left' ) -robot.connect_motor( 'right' ) -robot.connect_sensor( 'gyro' ) - -robot.gyro_set_mode( 'angle' ) -robot.reset_gyro() - -power = 20 -def forward_and_turnRight(power, angle): - robot.move_steering( 'on_for_seconds', direction=0, power=power, seconds=2 ) - robot.move_tank( 'on', lr_power=[power,-power] ) - while robot.gyro_sensor_measure( 'angle' ) < angle: - pass - robot.move_tank( 'off' ) - -forward_and_turnRight(power, 89) -forward_and_turnRight(power, 179) -forward_and_turnRight(power, 269) -forward_and_turnRight(power, 359) -''' - -hint_type = { - 'mW_init': Hint('mW_init'), - 'connectMotorLeft': Hint('connectMotorLeft'), - 'connectMotorRight': Hint('connectMotorRight'), - 'moveSteering': Hint('moveSteering'), - 'onForSeconds': Hint('onForSeconds'), - 'direction': Hint('direction'), - 'seconds': Hint('seconds'), - 'connectGyro': Hint('connectGyro'), - 'resetGyro': Hint('resetGyro'), - 'setGyroMode': Hint('setGyroMode'), - 'gyroMeasure': Hint('gyroMeasure'), - 'moveTank': Hint('moveTank'), - 'lrPower': Hint('lrPower'), - 'while': Hint('while') -} - -def hint( code): - tokens = get_tokens(code) - - # if code does not include mindstorms_widgets(), a student gets a hint that the robot should be somehow represented in the program - if not has_token_sequence(tokens, ['mindstorms_widgets', '(',')']): - return [{'id': 'mW_init'}] - - # if code does not include connect_motor statement, a student needs to learn about how to connect the motors - if not has_token_sequence(tokens, ['connect_motor']) and not has_token_sequence(tokens, ['left']): - return [{'id': 'connectMotorLeft'}] - - # if code does not include connect_motor statement, a student needs to learn about how to connect the motors - if not has_token_sequence(tokens, ['connect_motor']) and not has_token_sequence(tokens, ['right']): - return [{'id': 'connectMotorRight'}] - - if not has_token_sequence(tokens, ['connect_gyro','(', 'gyro', ')']): - return [{'id': 'connectGyro'}] - - if not has_token_sequence(tokens, ['reset_gyro()']): - return [{'id': 'resetGyro'}] - - if not has_token_sequence(tokens, ['gyro_set_mode']): - return [{'id': 'setGyroMode'}] - - if not has_token_sequence(tokens, ['gyro_sensor_measure()']): - return [{'id': 'gyroMeasure'}] - - if not has_token_sequence(tokens, ['move_tank']): - return [{'id': 'moveTank'}] - - if not has_token_sequence(tokens, ['move_steering']): - return [{'id': 'moveSteering'}] - - if not 'on_for_seconds' in code: - return [{'id': 'onForSeconds'}] - - if not 'direction' in code: - return [{'id': 'direction'}] - - if not 'seconds' in code: - return [{'id': 'seconds'}] - - if not 'lr_power' in code: - return [{'id': 'lrPower'}] - - if not has_token_sequence(tokens, ['while']): - return [{'id': 'while'}] - - return None diff --git a/robot/problems/introduction/gyrosquare/sl.py~ b/robot/problems/introduction/gyrosquare/sl.py~ deleted file mode 100644 index 00171e8..0000000 --- a/robot/problems/introduction/gyrosquare/sl.py~ +++ /dev/null @@ -1,40 +0,0 @@ -# coding=utf-8 -import server -mod = server.problems.load_language('python', 'sl') - -id = 210 -name = 'Kvadrat z žiroskopom' -slug = 'Kvadrat z žiroskopom' - -description = '''\ -

Robot naj prevozi kvadrat s stranico 20 cm; pri tem naj si pomaga z žiroskopom.

''' - -hint = { - 'mW_init':['''

Robota v programu predstavimo z mindstorms_widgets(): robot = mindstorms_widgets().

'''], - 'connectMotorLeft':['''

Robotu moramo priključiti levi motor: robot.connect_motor( 'left' ).

'''], - 'connectMotorRight':['''

Robotu moramo priključiti desni motor: robot.connect_motor( 'right' ).

'''], - - 'connectGyro':['''

Robotu priključi žiroskop.

''', - '''

robot.connect_sensor( 'gyro' ).

'''], - 'resetGyro':['''

Žiroskop na začetku resetiraj.

''', - '''

robot.reset_gyro().

'''], - 'setGyroMode':['''

Žiroskopu nastavi način delovanja na merjenje kotov.

''', - '''

robot.gyro_set_mode('angle').

'''], - 'gyroMeasure':['''

Preberi vrednost žiroskopa.

''', - '''

robot.gyro_sensor_measure().

'''], - 'lrPower':['''

Za obrat na mestu se morata kolesi vrteti z enako močjo in v nasprotni smeri.

''', - '''

robot.move_tank( 'on', lr_power=[hitrost, -hitrost], ... ).

'''], - 'moveTank':['''

Robot naj se obrne na mestu.

''', - '''

Najprimernejša metoda za to je move_tank

'''], - 'while':['''

Program naj čaka dokler je kot zasuka manjši od 90 stopinj.

''', - '''

robot.gyro_sensor_measure() < 90:

'''], - - 'moveSteering':['''

Sinhroniziraj motorja in ju zaženi.

''', - '''

Za sinhronizirano vožnjo je najbolj primerna metoda robot.move_steering( ... ).

'''], - 'onForSeconds':['''

Prvi argument metode robot.move_steering naj pove, da bo delovanje motorjev časovno omejeno.

''', - '''

robot.move_steering('on_for_seconds', ... ).

'''], - 'direction':['''

Navedi smer premikanja motorjev, naravnost = 0.

''', - '''

robot.move_steering( 'on_for_seconds', direction=0, ... ).

'''], - 'seconds':['''

Napiši časovno omejitev v sekundah.

''', - '''

robot.move_steering( 'on_for_seconds', direction=0, seconds=3 ).

'''], -} diff --git a/robot/problems/introduction/printcolors/common.py~ b/robot/problems/introduction/printcolors/common.py~ deleted file mode 100644 index 04ca0d6..0000000 --- a/robot/problems/introduction/printcolors/common.py~ +++ /dev/null @@ -1,80 +0,0 @@ -# coding=utf-8 - -from python.util import has_token_sequence, string_almost_equal, \ - string_contains_number, get_tokens, get_numbers, get_exception_desc -from server.hints import Hint, HintSequence - -id = 211 -group = 'introduction' -number = 9 -visible = True - -solution = '''\ -import time -from ev3dev import * -from mindstorms_widgets import mindstorms_widgets - -color_table = ['none', 'black', 'blue', 'green', 'yellow', 'red', 'white', 'brown'] - -robot = mindstorms_widgets() -robot.connect_motor( 'left' ) -robot.connect_motor( 'right' ) -robot.connect_sensor( 'color' ) - -robot.move_steering( 'on') -start = time.time() -color = -1 -while time.time()-start < 2.1: - c = robot.color_sensor_measure('color') - if c!=color: - print( c, color_table[c]) - color = c -robot.move_steering( 'off' ) -''' - -hint_type = { - 'mW_init': Hint('mW_init'), - 'connectMotorLeft': Hint('connectMotorLeft'), - 'connectMotorRight': Hint('connectMotorRight'), - 'moveSteeringOn': Hint('moveSteeringOn'), - 'moveSteeringOff': Hint('moveSteeringOff'), - 'connectColorSensor': Hint('connectColorSensor'), - 'colorSensorMeasure': Hint('colorSensorMeasure'), - 'while': Hint('while'), - 'print': Hint('print') -} - -def hint( code): - tokens = get_tokens(code) - - # if code does not include mindstorms_widgets(), a student gets a hint that the robot should be somehow represented in the program - if not has_token_sequence(tokens, ['mindstorms_widgets', '(',')']): - return [{'id': 'mW_init'}] - - # if code does not include connect_motor statement, a student needs to learn about how to connect the motors - if not has_token_sequence(tokens, ['connect_motor']) and not has_token_sequence(tokens, ['left']): - return [{'id': 'connectMotorLeft'}] - - # if code does not include connect_motor statement, a student needs to learn about how to connect the motors - if not has_token_sequence(tokens, ['connect_motor']) and not has_token_sequence(tokens, ['right']): - return [{'id': 'connectMotorRight'}] - - if not has_token_sequence(tokens, ['connect_sensor', '(', 'color', ')' ]): - return [{'id': 'connectColorSensor'}] - - if not has_token_sequence(tokens, ['move_steering', '(', 'on', ')']): - return [{'id': 'moveSteeringOn'}] - - if not has_token_sequence(tokens, ['move_steering', '(', 'off', ')']): - return [{'id': 'moveSteeringOff'}] - - if not has_token_sequence(tokens, ['color_sensor_measure', '(', 'color', ')']): - return [{'id': 'colorSensorMeasure'}] - - if not has_token_sequence(tokens, ['while']): - return [{'id': 'while'}] - - if not has_token_sequence(tokens, ['print', '(']): - return [{'id': 'print'}] - - return None \ No newline at end of file diff --git a/robot/problems/introduction/printcolors/sl.py~ b/robot/problems/introduction/printcolors/sl.py~ deleted file mode 100644 index 9d5ec21..0000000 --- a/robot/problems/introduction/printcolors/sl.py~ +++ /dev/null @@ -1,37 +0,0 @@ -# coding=utf-8 -import server -mod = server.problems.load_language('python', 'sl') - -id = 211 -name = 'Zaznavanje barv' -slug = 'Zaznavanje barv' - -description = '''\ -

Robot naj se pelje čez barvne črte in na zaslon izpiše barvo, ki jo zazna s svetlobnim senzorjem. - Value Color - 0 none - 1 black - 2 blue - 3 green - 4 yellow - 5 red - 6 white - 7 brown

''' - -hint = { - 'mW_init':['''

Robota v programu predstavimo z mindstorms_widgets(): robot = mindstorms_widgets().

'''], - 'connectMotorLeft':['''

Robotu moramo priključiti levi motor: robot.connect_motor( 'left' ).

'''], - 'connectMotorRight':['''

Robotu moramo priključiti desni motor: robot.connect_motor( 'right' ).

'''], - 'moveSteeringOn':['''

Sinhroniziraj motorja in ju zaženi.

''', - '''

Za sinhronizirano vožnjo je najbolj primerna metoda robot.move_steering( 'on' ).

'''], - 'moveSteeringOff':['''

Ustavi motorja.

''', - '''

robot.move_steering( 'off' ).

'''], - 'connectColorSensor':['''

Robotu moramo priključiti barvni senzor.

''', - '''

robot.connect_sensor( 'color' ).

'''], - 'colorSensorMeasure':['''

Medtem ko se robot pomika naprej, naj uporabi barvni senzor v načinu 'color', s katerim pove, katero barvo trenutno vidi.

''', - '''

robot.color_sensor_measure( 'color' ).

'''], - 'while':['''

Uporabi zanko, znotraj katere robot odčitava barve in povečuje števec.

''', - '''

Zanka je lahko časovno omejena, npr. z uporabo metode time.time().

''', - '''

while time.time()-start < 1.1:.

'''], - 'print':['''

V zanki na zaslon izpisuj barvo, ki jo zazna robot.

'''] -} \ No newline at end of file diff --git a/robot/problems/introduction/rotateback/common.py~ b/robot/problems/introduction/rotateback/common.py~ deleted file mode 100644 index c7c199c..0000000 --- a/robot/problems/introduction/rotateback/common.py~ +++ /dev/null @@ -1,111 +0,0 @@ -# coding=utf-8 - -from python.util import has_token_sequence, string_almost_equal, \ - string_contains_number, get_tokens, get_numbers, get_exception_desc -from server.hints import Hint, HintSequence - -id = 212 -group = 'introduction' -number = 11 -visible = True - -solution = '''\ -from ev3dev import * -from mindstorms_widgets import mindstorms_widgets - -def sgn(x): - return -1 if x<0 else (1 if x>0 else 0) - -robot = mindstorms_widgets() -robot.connect_motor( 'left' ) -robot.connect_motor( 'right' ) -robot.connect_sensor( 'gyro' ) -robot.connect_sensor( 'touch' ) - -smer = hitrost = 0 -robot.reset_gyro() -robot.gyro_set_mode( 'angle' ) -prev_smer = -1 -while 1: - smer = robot.gyro_sensor_measure() - if smer!=prev_smer: - print ("Kot:", smer) - prev_smer = smer - - if robot.touch_sensor_measure(): - robot.reset_gyro() - print ( robot.gyro_sensor_measure() ) - - 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]) -''' - -hint_type = { - 'mW_init': Hint('mW_init'), - 'connectMotorLeft': Hint('connectMotorLeft'), - 'connectMotorRight': Hint('connectMotorRight'), - 'connectGyro': Hint('connectGyro'), - 'connectTouch': Hint('connectTouch'), - 'resetGyro': Hint('resetGyro'), - 'setGyroMode': Hint('setGyroMode'), - 'gyroMeasure': Hint('gyroMeasure'), - 'ifTouch': Hint('ifTouch'), - 'moveTank': Hint('moveTank'), - 'lrPower': Hint('lrPower'), - 'while': Hint('while') -} - -def hint( code): - tokens = get_tokens(code) - - # if code does not include mindstorms_widgets(), a student gets a hint that the robot should be somehow represented in the program - if not has_token_sequence(tokens, ['mindstorms_widgets', '(',')']): - return [{'id': 'mW_init'}] - - # if code does not include connect_motor statement, a student needs to learn about how to connect the motors - if not has_token_sequence(tokens, ['connect_motor']) and not has_token_sequence(tokens, ['left']): - return [{'id': 'connectMotorLeft'}] - - # if code does not include connect_motor statement, a student needs to learn about how to connect the motors - if not has_token_sequence(tokens, ['connect_motor']) and not has_token_sequence(tokens, ['right']): - return [{'id': 'connectMotorRight'}] - - if not has_token_sequence(tokens, ['connect_gyro','(', 'gyro', ')']): - return [{'id': 'connectGyro'}] - - if not has_token_sequence(tokens, ['connect_sensor','(', 'touch', ')']): - return [{'id': 'connectTouch'}] - - if not has_token_sequence(tokens, ['reset_gyro()']): - return [{'id': 'resetGyro'}] - - if not has_token_sequence(tokens, ['gyro_set_mode']): - return [{'id': 'setGyroMode'}] - - if not has_token_sequence(tokens, ['gyro_sensor_measure()']): - return [{'id': 'gyroMeasure'}] - - if not has_token_sequence(tokens, ['if','touch_sensor_measure','(',')']): - return [{'id': 'ifTouch'}] - - if not has_token_sequence(tokens, ['move_tank']): - return [{'id': 'moveTank'}] - - if not has_token_sequence(tokens, ['lr_power']): - return [{'id': 'lrPower'}] - - if not has_token_sequence(tokens, ['while']): - return [{'id': 'while'}] - - return None diff --git a/robot/problems/introduction/rotateback/sl.py~ b/robot/problems/introduction/rotateback/sl.py~ deleted file mode 100644 index 0b91379..0000000 --- a/robot/problems/introduction/rotateback/sl.py~ +++ /dev/null @@ -1,36 +0,0 @@ -# coding=utf-8 -import server -mod = server.problems.load_language('python', 'sl') - -id = 212 -name = 'Drži smer' -slug = 'Drži smer' - -description = '''\ -

Robot naj drži smer - če ga obrnemo iz začetne smeri, naj se zasuka nazaj v prvotno smer. Ob pritisku na stikalo, naj se resetira (smer nastavi na 0).

''' - -hint = { - 'mW_init':['''

Robota v programu predstavimo z mindstorms_widgets(): robot = mindstorms_widgets().

'''], - 'connectMotorLeft':['''

Robotu priključi levi motor

''', - '''

robot.connect_motor( 'left' ).

'''], - 'connectMotorRight':['''

Robotu priključi desni motor

''', - '''

robot.connect_motor( 'right' ).

'''], - 'connectGyro':['''

Robotu priključi žiroskop

''', - '''

robot.connect_sensor( 'gyro' ).

'''], - 'connectTouch':['''

Robotu priključi stikalo

''', - '''

robot.connect_sensor( 'touch' ).

'''], - 'resetGyro':['''

Žiroskop na začetku in ob pritisku na stikalo resetiraj.

''', - '''

robot.reset_gyro().

'''], - 'setGyroMode':['''

Žiroskopu nastavi način delovanja na merjenje kotov.

''', - '''

robot.gyro_set_mode('angle').

'''], - 'gyroMeasure':['''

Preberi vrednost žiroskopa.

''', - '''

robot.gyro_sensor_measure().

'''], - 'ifTouch':['''

Preveri, če je stikalo pritisnjeno.

''', - '''

if robot.touch_sensor_measure():.

'''], - 'lrPower':['''

Za obrat na mestu se morata kolesi vrteti z enako močjo in v nasprotni smeri.

''', - '''

robot.move_tank( 'on_for_seconds', lr_power=[hitrost, -hitrost], ... ).

'''], - 'moveTank':['''

Robot naj se obrne na mestu.

''', - '''

Najprimernejša metoda za to je move_tank

'''], - 'while':['''

Program naj teče v neskončni zanki.

''', - '''

while 1:

'''], -} diff --git a/robot/problems/introduction/spotturn90/common.py~ b/robot/problems/introduction/spotturn90/common.py~ deleted file mode 100644 index d024bd4..0000000 --- a/robot/problems/introduction/spotturn90/common.py~ +++ /dev/null @@ -1,61 +0,0 @@ -# coding=utf-8 - -from python.util import has_token_sequence, string_almost_equal, \ - string_contains_number, get_tokens, get_numbers, get_exception_desc -from server.hints import Hint, HintSequence - -id = 214 -group = 'introduction' -number = 3 -visible = True - -solution = '''\ -import time -from ev3dev import * -from mindstorms_widgets import mindstorms_widgets - -robot = mindstorms_widgets() -robot.connect_motor( 'left' ) -robot.connect_motor( 'right' ) - -robot.move_tank( 'on_for_seconds', lr_power=[20,-20], seconds=.9 ) -''' - -hint_type = { - 'mW_init': Hint('mW_init'), - 'connectMotorLeft': Hint('connectMotorLeft'), - 'connectMotorRight': Hint('connectMotorRight'), - 'moveTank': Hint('moveTank'), - 'onForSeconds': Hint('onForSeconds'), - 'lrPower': Hint('lrPower'), - 'seconds': Hint('seconds'), -} - -def hint( code): - tokens = get_tokens(code) - - # if code does not include mindstorms_widgets(), a student gets a hint that the robot should be somehow represented in the program - if not has_token_sequence(tokens, ['mindstorms_widgets', '(',')']): - return [{'id': 'mW_init'}] - - # if code does not include connect_motor statement, a student needs to learn about how to connect the motors - if not has_token_sequence(tokens, ['connect_motor']) and not has_token_sequence(tokens, ['left']): - return [{'id': 'connectMotorLeft'}] - - # if code does not include connect_motor statement, a student needs to learn about how to connect the motors - if not has_token_sequence(tokens, ['connect_motor']) and not has_token_sequence(tokens, ['right']): - return [{'id': 'connectMotorRight'}] - - if not has_token_sequence(tokens, ['move_tank']): - return [{'id': 'moveTank'}] - - if not has_token_sequence(tokens, ['on_for_seconds']): - return [{'id': 'onForSeconds'}] - - if not has_token_sequence(tokens, ['lr_power']): - return [{'id': 'lrPower'}] - - if not has_token_sequence(tokens, ['seconds']): - return [{'id': 'seconds'}] - - return None diff --git a/robot/problems/introduction/spotturn90/sl.py~ b/robot/problems/introduction/spotturn90/sl.py~ deleted file mode 100644 index bc0978c..0000000 --- a/robot/problems/introduction/spotturn90/sl.py~ +++ /dev/null @@ -1,24 +0,0 @@ -# coding=utf-8 -import server -mod = server.problems.load_language('python', 'sl') - -id = 214 -name = 'Obrat na mestu 90' -slug = 'Obrat na mestu 90' - -description = '''\ -

Robot naj se na mestu obrne za 90 stopinj v desno.

''' - -hint = { - 'mW_init':['''

Robota v programu predstavimo z mindstorms_widgets(): robot = mindstorms_widgets().

'''], - 'connectMotorLeft':['''

Robotu moramo priključiti levi motor: robot.connect_motor( 'left' ).

'''], - 'connectMotorRight':['''

Robotu moramo priključiti desni motor: robot.connect_motor( 'right' ).

'''], - 'moveTank':['''

Robot naj se obrne na mestu.

''', - '''

Najprimernejša metoda za to je move_tank

'''], - 'onForSeconds':['''

Prvi argument metode robot.move_tank naj pove, da bo delovanje motorjev časovno omejeno.

''', - '''

robot.move_tank('on_for_seconds', ... ).

'''], - 'lrPower':['''

Za obrat na mestu se morata kolesi vrteti z enako močjo in v nasprotni smeri.

''', - '''

robot.move_tank( 'on_for_seconds', lr_power=[hitrost, -hitrost], ... ).

'''], - 'seconds':['''

Napiši časovno omejitev v sekundah.

''', - '''

robot.move_tank( 'on_for_seconds', ..., seconds=... ).

'''], -} \ No newline at end of file diff --git a/robot/problems/introduction/square20/common.py~ b/robot/problems/introduction/square20/common.py~ deleted file mode 100644 index f868a1c..0000000 --- a/robot/problems/introduction/square20/common.py~ +++ /dev/null @@ -1,76 +0,0 @@ -# coding=utf-8 - -from python.util import has_token_sequence, string_almost_equal, \ - string_contains_number, get_tokens, get_numbers, get_exception_desc -from server.hints import Hint, HintSequence - -id = 213 -group = 'introduction' -number = 4 -visible = True - -solution = '''\ -from ev3dev import * -from mindstorms_widgets import mindstorms_widgets - -robot = mindstorms_widgets() -robot.connect_motor( 'left' ) -robot.connect_motor( 'right' ) - -turntime = .95 -robot.move_steering( 'on_for_seconds', direction=0, power=20, seconds=2 ) -robot.move_tank( 'on_for_seconds', lr_power=[20,-20], seconds=turntime ) -robot.move_steering( 'on_for_seconds', direction=0, power=20, seconds=2 ) -robot.move_tank( 'on_for_seconds', lr_power=[20,-20], seconds=turntime ) -robot.move_steering( 'on_for_seconds', direction=0, power=20, seconds=2 ) -robot.move_tank( 'on_for_seconds', lr_power=[20,-20], seconds=turntime ) -robot.move_steering( 'on_for_seconds', direction=0, power=20, seconds=2 ) -robot.move_tank( 'on_for_seconds', lr_power=[20,-20], seconds=turntime ) -''' - -hint_type = { - 'mW_init': Hint('mW_init'), - 'connectMotorLeft': Hint('connectMotorLeft'), - 'connectMotorRight': Hint('connectMotorRight'), - 'moveSteering': Hint('moveSteering'), - 'onForSeconds': Hint('onForSeconds'), - 'direction': Hint('direction'), - 'seconds': Hint('seconds'), - 'moveTank': Hint('moveTank'), - 'lrPower': Hint('lrPower') -} - -def hint( code): - tokens = get_tokens(code) - - # if code does not include mindstorms_widgets(), a student gets a hint that the robot should be somehow represented in the program - if not has_token_sequence(tokens, ['mindstorms_widgets', '(',')']): - return [{'id': 'mW_init'}] - - # if code does not include connect_motor statement, a student needs to learn about how to connect the motors - if not has_token_sequence(tokens, ['connect_motor']) and not has_token_sequence(tokens, ['left']): - return [{'id': 'connectMotorLeft'}] - - # if code does not include connect_motor statement, a student needs to learn about how to connect the motors - if not has_token_sequence(tokens, ['connect_motor']) and not has_token_sequence(tokens, ['right']): - return [{'id': 'connectMotorRight'}] - - if not has_token_sequence(tokens, ['move_steering']): - return [{'id': 'moveSteering'}] - - if not 'on_for_seconds' in code: - return [{'id': 'onForSeconds'}] - - if not 'direction' in code: - return [{'id': 'direction'}] - - if not 'seconds' in code: - return [{'id': 'seconds'}] - - if not has_token_sequence(tokens, ['move_tank']): - return [{'id': 'moveTank'}] - - if not 'lr_power' in code: - return [{'id': 'lrPower'}] - - return None diff --git a/robot/problems/introduction/square20/sl.py~ b/robot/problems/introduction/square20/sl.py~ deleted file mode 100644 index aa5137e..0000000 --- a/robot/problems/introduction/square20/sl.py~ +++ /dev/null @@ -1,27 +0,0 @@ -# coding=utf-8 - -name = 'Kvadrat 20 cm' -slug = 'Kvadrat 20 cm' - -description = '''\ -

Robot naj enkrat prevozi kvadrat s stranico 20 cm.

''' - -hint = { - 'mW_init':['''

Robota v programu predstavimo z mindstorms_widgets(): robot = mindstorms_widgets().

'''], - 'connectMotorLeft':['''

Robotu moramo priključiti levi motor: robot.connect_motor( 'left' ).

'''], - 'connectMotorRight':['''

Robotu moramo priključiti desni motor: robot.connect_motor( 'right' ).

'''], - 'moveSteering':['''

Sinhroniziraj motorja in ju zaženi.

''', - '''

Za sinhronizirano vožnjo je najbolj primerna metoda robot.move_steering( ... ).

'''], - 'onForSeconds':['''

Prvi argument metode robot.move_steering naj pove, da bo delovanje motorjev časovno omejeno.

''', - '''

robot.move_steering('on_for_seconds', ... ).

'''], - 'direction':['''

Navedi smer premikanja motorjev, naravnost = 0.

''', - '''

robot.move_steering( 'on_for_seconds', direction=0, ... ).

'''], - 'seconds':['''

Napiši časovno omejitev v sekundah.

''', - '''

robot.move_steering( 'on_for_seconds', direction=0, seconds=... ).

''', - '''

robot.move_tank( 'on_for_seconds', lr_power=[20,-20], seconds=.95 ).

''',], - 'moveTank': ['''

Robot naj se obrne na mestu.

''', - '''

Najprimernejša metoda za to je move_tank

''', - '''

robot.move_tank( 'on_for_seconds', ... ).

'''], - 'lrPower': ['''

Za obrat na mestu se morata kolesi vrteti z enako močjo in v nasprotni smeri.

''', - '''

robot.move_tank( 'on_for_seconds', lr_power=[20,-20], seconds=.95 ).

'''], -} diff --git a/robot/problems/introduction/wall1m/common.py~ b/robot/problems/introduction/wall1m/common.py~ deleted file mode 100644 index 319cea2..0000000 --- a/robot/problems/introduction/wall1m/common.py~ +++ /dev/null @@ -1,80 +0,0 @@ -# coding=utf-8 - -from python.util import has_token_sequence, string_almost_equal, \ - string_contains_number, get_tokens, get_numbers, get_exception_desc -from server.hints import Hint, HintSequence - -id = 215 -group = 'introduction' -number = 6 -visible = True - -solution = '''\ -from ev3dev import * -from mindstorms_widgets import mindstorms_widgets - -robot = mindstorms_widgets() -robot.connect_motor( 'left' ) -robot.connect_motor( 'right' ) -robot.connect_sensor( 'ultrasonic' ) -robot.move_steering( 'on', power=80 ) -while robot.ultrasonic_sensor_measure( 'distance-cm' ) > 500: - pass -robot.move_steering( 'on', power=20 ) -while robot.ultrasonic_sensor_measure( 'distance-cm' ) > 200: - pass -robot.move_steering( 'off' ) -''' - -hint_type = { - 'mW_init': Hint('mW_init'), - 'connectMotorLeft': Hint('connectMotorLeft'), - 'connectMotorRight': Hint('connectMotorRight'), - 'moveSteeringOn': Hint('moveSteeringOn'), - 'moveSteeringOff': Hint('moveSteeringOff'), - 'connectUltrasonicSensor': Hint('connectUltrasonicSensor'), - 'ultrasonicSensorMeasure': Hint('ultrasonicSensorMeasure'), - 'power80': Hint('power80'), - 'power20': Hint('power20'), - 'while': Hint('while') -} - -def hint( code ): - tokens = get_tokens(code) - lines = code.split('\n') - - # if code does not include mindstorms_widgets(), a student gets a hint that the robot should be somehow represented in the program - if not has_token_sequence(tokens, ['mindstorms_widgets', '(',')']): - return [{'id': 'mW_init'}] - - # if code does not include connect_motor statement, a student needs to learn about how to connect the motors - if not has_token_sequence(tokens, ['connect_motor']) and not has_token_sequence(tokens, ['left']): - return [{'id': 'connectMotorLeft'}] - - # if code does not include connect_motor statement, a student needs to learn about how to connect the motors - if not has_token_sequence(tokens, ['connect_motor']) and not has_token_sequence(tokens, ['right']): - return [{'id': 'connectMotorRight'}] - - if not (has_token_sequence(tokens, ['connect_sensor', '(']) and 'ultrasonic' in code) : - return [{'id': 'connectUltrasonicSensor'}] - - if not (has_token_sequence(tokens, ['move_steering', '(']) and 'on' in code): - return [{'id': 'moveSteeringOn'}] - - if not (has_token_sequence(tokens, ['move_steering', '(']) and 'off' in code): - return [{'id': 'moveSteeringOff'}] - - #if not (has_token_sequence(tokens, ['ultrasonic_sensor_measure', '(']) and 'distance-cm' in code): - if not any(('ultrasonic_sensor_measure' in s and '(' in s and 'distance-cm' in s) for s in lines) - return [{'id': 'ultrasonicSensorMeasure'}] - - if not any(('power' in s and '80' in s and '=' in s) for s in lines): - return [{'id': 'power80'}] - - if not any(('power' in s and '20' in s and '=' in s) for s in lines): - return [{'id': 'power20'}] - - if not has_token_sequence(tokens, ['while']): - return [{'id': 'while'}] - - return None diff --git a/robot/problems/introduction/wall1m/naloga06_wall1m.py~ b/robot/problems/introduction/wall1m/naloga06_wall1m.py~ deleted file mode 100644 index f7e6bad..0000000 --- a/robot/problems/introduction/wall1m/naloga06_wall1m.py~ +++ /dev/null @@ -1,31 +0,0 @@ -#!/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 time -from ev3dev import * -from mindstorms_widgets import mindstorms_widgets - -us = ultrasonic_sensor(); assert us.connected -us.mode = 'US-DIST-CM' # Continuous measurement of distance (0-2550 mm) - -# for m in us.modes: -# print "\t",m -#exit() -robot = mindstorms_widgets() -robot.connect_motor( 'left' ) -robot.connect_motor( 'right' ) - -robot.move_steering( 'on', power=80 ) -while us.value()>500: - pass -robot.move_steering( 'on', power=20 ) -while us.value()>200: - pass -robot.move_steering( 'off' ) diff --git a/robot/problems/introduction/wall1m/sl.py~ b/robot/problems/introduction/wall1m/sl.py~ deleted file mode 100644 index 8455bab..0000000 --- a/robot/problems/introduction/wall1m/sl.py~ +++ /dev/null @@ -1,31 +0,0 @@ -# coding=utf-8 - -name = 'Pelji do zida' -slug = 'Pelji do zida' - -description = '''\ -

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.

''' - -hint = { - 'mW_init':['''

Robota v programu predstavimo z mindstorms_widgets(): robot = mindstorms_widgets().

'''], - 'connectMotorLeft':['''

Robotu priključi levi motor

''', - '''

robot.connect_motor( 'left' ).

'''], - 'connectMotorRight':['''

Robotu priključi desni motor

''', - '''

robot.connect_motor( 'right' ).

'''], - 'moveSteeringOn':['''

Sinhroniziraj motorja in ju zaženi.

''', - '''

Za sinhronizirano vožnjo je najbolj primerna metoda robot.move_steering( 'on' ).

'''], - 'moveSteeringOff':['''

Ustavi motorja.

''', - '''

robot.move_steering( 'off' ).

'''], - 'power80': ['''

Nastavi moč motorjev na 80%.

''', - '''

robot.move_steering( 'on', power=80 ).

'''], - 'power20': ['''

Nastavi moč motorjev na 20%.

''', - '''

robot.move_steering( 'on', power=20 ).

'''], - 'connectUltrasonicSensor':['''

Robotu moramo priključiti ultrazvočni senzor.

''', - '''

robot.connect_sensor( 'ultrasonic' ).

'''], - 'ultrasonicSensorMeasure':['''

Medtem ko se robot pomika naprej, naj uporabi ultrazvočni senzor v načinu 'distance-cm', s katerim meri razdaljo v cm.

''', - '''

robot.ultrasonic_sensor_measure( 'distance-cm' ).

'''], - 'while':['''

Uporabi zanko: robot naj se pelje naprej, dokler ne pride do razdalje 50 cm od zida.

''', - '''

Uporabi še eno zanko: robot naj se pelje naprej z 20% močjo, dokler ne pride do razdalje 20 cm od zida.

'''], -} -- cgit v1.2.1 From 3bcdcda1631abe6fed0eb0fa0ea608a7170274bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=BDabkar?= Date: Wed, 14 Oct 2015 15:38:37 +0200 Subject: fixed: TabError: inconsistent use of tabs and spaces in indentation --- robot/problems/introduction/followline/common.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'robot/problems') diff --git a/robot/problems/introduction/followline/common.py b/robot/problems/introduction/followline/common.py index 0fc6704..d61d4c1 100644 --- a/robot/problems/introduction/followline/common.py +++ b/robot/problems/introduction/followline/common.py @@ -69,8 +69,8 @@ def hint( code): if not (has_token_sequence(tokens, ['move_steering', '(']) and 'off' in code): return [{'id': 'moveTankOff'}] - - if not (has_token_sequence(tokens, ['color_sensor_measure', '(']) and 'reflected_light_intensity' in code): + + if not (has_token_sequence(tokens, ['color_sensor_measure', '(']) and 'reflected_light_intensity' in code): return [{'id': 'colorSensorMeasureRLI'}] if not has_token_sequence(tokens, ['while']): -- cgit v1.2.1 From f0978716a04628543161bd77f6e3ca3af3130f2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=BDabkar?= Date: Wed, 14 Oct 2015 15:41:51 +0200 Subject: fixed: TabError: inconsistent use of tabs and spaces in indentation --- robot/problems/introduction/wall1m/common.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'robot/problems') diff --git a/robot/problems/introduction/wall1m/common.py b/robot/problems/introduction/wall1m/common.py index 319cea2..2a93573 100644 --- a/robot/problems/introduction/wall1m/common.py +++ b/robot/problems/introduction/wall1m/common.py @@ -41,7 +41,7 @@ hint_type = { def hint( code ): tokens = get_tokens(code) - lines = code.split('\n') + lines = code.split('\n') # if code does not include mindstorms_widgets(), a student gets a hint that the robot should be somehow represented in the program if not has_token_sequence(tokens, ['mindstorms_widgets', '(',')']): @@ -65,7 +65,7 @@ def hint( code ): return [{'id': 'moveSteeringOff'}] #if not (has_token_sequence(tokens, ['ultrasonic_sensor_measure', '(']) and 'distance-cm' in code): - if not any(('ultrasonic_sensor_measure' in s and '(' in s and 'distance-cm' in s) for s in lines) + if not any(('ultrasonic_sensor_measure' in s and '(' in s and 'distance-cm' in s) for s in lines): return [{'id': 'ultrasonicSensorMeasure'}] if not any(('power' in s and '80' in s and '=' in s) for s in lines): -- cgit v1.2.1