summaryrefslogtreecommitdiff
path: root/robot/problems/introduction/followline/en.py
blob: 1551d1beae4b4c8fb6a1644edfa18f633dee7174 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# coding=utf-8
import server
mod = server.problems.load_language('python', 'en')

id = 207
name = 'Line following'
slug = 'Line following'

description = '''\
              Write the program for line following. The robot should use the color sensor to follow the black line on white background.
'''

hint = {
    'mW_init':mod.hint['init'],
    'connectMotorLeft':mod.hint['connectMotorLeft'],
    'connectMotorRight':mod.hint['connectMotorRight'],
    'moveSteeringOn':mod.hint['moveSteering']+['''<p>Use move_steering method with 'on' as the first parameter <code>robot.move_steering( 'on',... )</code>.</p>'''],
    'moveSteeringOff':mod.hint['moveSteeringOff'],
    'connectColorSensor':mod.hint['connectColorSensor'],
    'colorSensorMeasureRLI':mod.hint['colorSensorMeasureRLI'],
    'while':['''<p>Use the loop, inside which the robot would follow the line.</p>''',
             '''<p>The loop should be time constrained, e.g. <code>time.time()</code>.</p>''',
             '''<p><code>start = time.time()\nwhile time.time()-start < 10:</code>.</p>'''],
    'moveTankOn':mod.hint['moveTankOn'],
    'lrPower': mod.hint['lrPower'],
    'moveTankOff': mod.hint['moveTankOff'],    
    'time': ['''Use time() to measure time.''',
             '''<p><code>start = time.time()\nwhile time.time()-start < 10:</code></p>'''],
    'if': ['''<p>Use conditional statement inside the loop...</p>''',
           '''<p>If the robot sees the line, it should turn slightly to go off the line; if the robot sees the background, it should turn towards the line.</p>''']
}

plan = ['''\
<p>The program should do the following:</p>
<ol>
  <li>create a mindstorms_widgets() object, which represents the robot in your code.</li>
  <li>connect the driving motors.</li>
  <li>connect the color sensor.</li>
  <li>in a loop, the robot should read the color sensor to check whether it is on or off line.</li>
  <li>if it sees black, it should turn right/left; if it sees white, it should turn left/right.</li>
  <li>break the loop after specified time, 10 seconds.</li>
  <li>stop the motors.</li>
</ol>
<p>Note: you may need to calibrate the color sensor before running the program on the robot.</p>
'''
]