| 1 | -- A simple line following program. |
|---|
| 2 | -- It works with the standard NXT bot. |
|---|
| 3 | -- Place the bot on the test pad, with the wheels |
|---|
| 4 | -- on the start line facing forward. |
|---|
| 5 | -- Then start the program. |
|---|
| 6 | |
|---|
| 7 | -- author: Jan-Klaas Kollhof |
|---|
| 8 | -- last changed by: $LastChangedBy$ |
|---|
| 9 | -- last changed date: $Date$ |
|---|
| 10 | -- revision: $Revision$ |
|---|
| 11 | |
|---|
| 12 | LightThreshold=500 |
|---|
| 13 | Fast=75 |
|---|
| 14 | Slow=20 |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | function follow_simple() |
|---|
| 19 | |
|---|
| 20 | nxt.InputSetType(3, 1) |
|---|
| 21 | nxt.InputSetDir(3, 1, 1) |
|---|
| 22 | nxt.InputSetState(3, 1, 0) |
|---|
| 23 | |
|---|
| 24 | -- no speed regulation, this seems important |
|---|
| 25 | -- for some reason |
|---|
| 26 | nxt.OutputSetRegulation(2, 0, 1 ) |
|---|
| 27 | nxt.OutputSetRegulation(3, 0, 1 ) |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | -- lets turn 90 deg left |
|---|
| 31 | |
|---|
| 32 | -- now follow the line |
|---|
| 33 | nxt.OutputSetSpeed(2, 32, Fast) |
|---|
| 34 | nxt.OutputSetSpeed(3, 32, Fast) |
|---|
| 35 | |
|---|
| 36 | repeat |
|---|
| 37 | if(nxt.InputGetStatus( 3 ) > LightThreshold) then |
|---|
| 38 | nxt.OutputSetSpeed(2, 32, Slow) |
|---|
| 39 | else |
|---|
| 40 | nxt.OutputSetSpeed(2, 32, Fast) |
|---|
| 41 | end |
|---|
| 42 | |
|---|
| 43 | until(nxt.ButtonRead() == 8) |
|---|
| 44 | |
|---|
| 45 | nxt.OutputSetSpeed(2, 0, 0) |
|---|
| 46 | nxt.OutputSetSpeed(3, 0, 0) |
|---|
| 47 | |
|---|
| 48 | end |
|---|
| 49 | |
|---|
| 50 | follow_simple() |
|---|