# coding=utf-8 import server mod = server.problems.load_language('robot', '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']+['''

Use move_steering method with 'on' as the first parameter robot.move_steering( 'on',... ).

'''], 'moveSteeringOff':mod.hint['moveSteeringOff'], 'connectColorSensor':mod.hint['connectColorSensor'], 'colorSensorMeasureRLI':mod.hint['colorSensorMeasureRLI'], 'while':['''

Use the loop, inside which the robot would follow the line.

''', '''

The loop should be time constrained, e.g. time.time().

''', '''

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

'''], 'moveTankOn':mod.hint['moveTankOn'], 'lrPower': mod.hint['lrPower'], 'moveTankOff': mod.hint['moveTankOff'], 'time': ['''Use time() to measure time.''', '''

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

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

Use conditional statement inside the loop...

''', '''

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.

'''] } plan = ['''\

The program should do the following:

  1. create a mindstorms_widgets() object, which represents the robot in your code.
  2. connect the driving motors.
  3. connect the color sensor.
  4. in a loop, the robot should read the color sensor to check whether it is on or off line.
  5. if it sees black, it should turn right/left; if it sees white, it should turn left/right.
  6. break the loop after specified time, 10 seconds.
  7. stop the motors.

Note: you may need to calibrate the color sensor before running the program on the robot.

''' ]