📜 ⬆️ ⬇️

Lego Mindstorms NXT 2.0 - Brief Introduction


Years 10-11, after a long and carefree years of playing with Lego developers, I learned about the existence of a magnificent set of Mindstorms, which allowed us to create the most real robots without specialized knowledge of electronics, electrical engineering and even programming. I immediately became interested in this series, but then my dreams of having Mindstorms for various (mostly financial) reasons did not come true.
Now I am 20 and in honor of the anniversary friends (thanks to them!) Decided to dip me back to my childhood and still give the opportunity to feed my own robots. True, this time everything will be more serious than in my childhood thoughts - we will really program Mindstorms under Debian GNU / Linux.


What is this?



Mindstorms NXT 2.0 is the third product in the Mindstorms line - a special series of Lego designers, designed to create programmable robots. The designer comes with a set of standard Lego Technic series parts, as well as special sensors (distance, lightness, touch), several tachometer motors and a special NXT unit. You can learn more about Mindstorms from this article here .
Speaking of NXT, there are two microcontrollers hidden in this small box - 32-bit ARM7 and 8-bit AVR, 512 MB of RAM, more than 256 KB of flash memory, a monochrome LCD display, a speaker, a USB port, and 7 ports to connect sensors. And, yes - another compartment for 6 batteries or a battery, which is sold separately on shop.lego.com . Actually, NXT is the “heart” of any created robot.
After reading the brief guide included in the kit, you can quite create a robot that performs some simple actions without any programming at all. For example, in just 40 minutes with the assembly, you can make a robot that will travel around the room and carefully avoid obstacles. This is done directly on the device itself, without being connected to a computer, on the built-in monochrome display.


')
Not bad, huh?
Actually, this robot will be our main test model. But we will try to improve his skills a little. And for this we will write a small piece of code.


But as?


Really. The bundled software only works on Windows and Mac OS. And here we have, suddenly, Debian Squeeze. Fortunately, Mindstorms has a huge community of fans who have come up with a solution to this problem - the use of alternative software for programming robots, in particular Bricxcc ( here is the complete manual for setting up everything and everyone).
And now a bit of theory - in programming Mindstorms, as a rule, besides the visual ROBOLAB environment for Windows and Mac OS, RCX is used, but among the fans one of the most popular languages ​​is fairly simple NXC (Not eXactly C). A simple NXC program looks like this:
task music() { int lastTone=5000; while ( true ) { int tone= Random (5000)+500; int duration= Random (500); PlayTone(tone,duration); Wait(duration); } } task main() { start music; while ( true ) { /* Determine Next Action */ unsigned int duration= Random (5000); unsigned int motorSpeed= Random (100); unsigned int syncMode= Random (3); /* Display Next Action */ ClearScreen(); NumOut(0,LCD_LINE1,duration); NumOut(0,LCD_LINE2,motorSpeed); NumOut(0,LCD_LINE3,syncMode); /* Perform Next Action */ switch (syncMode) { case 0: OnFwdReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 1: OnRevReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 2: OnFwdSync(OUT_AC,motorSpeed,-100); break ; case 3: OnRevSync(OUT_AC,motorSpeed,-100); break ; } Wait(duration); } } * This source code was highlighted with Source Code Highlighter .
  1. task music() { int lastTone=5000; while ( true ) { int tone= Random (5000)+500; int duration= Random (500); PlayTone(tone,duration); Wait(duration); } } task main() { start music; while ( true ) { /* Determine Next Action */ unsigned int duration= Random (5000); unsigned int motorSpeed= Random (100); unsigned int syncMode= Random (3); /* Display Next Action */ ClearScreen(); NumOut(0,LCD_LINE1,duration); NumOut(0,LCD_LINE2,motorSpeed); NumOut(0,LCD_LINE3,syncMode); /* Perform Next Action */ switch (syncMode) { case 0: OnFwdReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 1: OnRevReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 2: OnFwdSync(OUT_AC,motorSpeed,-100); break ; case 3: OnRevSync(OUT_AC,motorSpeed,-100); break ; } Wait(duration); } } * This source code was highlighted with Source Code Highlighter .
  2. task music() { int lastTone=5000; while ( true ) { int tone= Random (5000)+500; int duration= Random (500); PlayTone(tone,duration); Wait(duration); } } task main() { start music; while ( true ) { /* Determine Next Action */ unsigned int duration= Random (5000); unsigned int motorSpeed= Random (100); unsigned int syncMode= Random (3); /* Display Next Action */ ClearScreen(); NumOut(0,LCD_LINE1,duration); NumOut(0,LCD_LINE2,motorSpeed); NumOut(0,LCD_LINE3,syncMode); /* Perform Next Action */ switch (syncMode) { case 0: OnFwdReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 1: OnRevReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 2: OnFwdSync(OUT_AC,motorSpeed,-100); break ; case 3: OnRevSync(OUT_AC,motorSpeed,-100); break ; } Wait(duration); } } * This source code was highlighted with Source Code Highlighter .
  3. task music() { int lastTone=5000; while ( true ) { int tone= Random (5000)+500; int duration= Random (500); PlayTone(tone,duration); Wait(duration); } } task main() { start music; while ( true ) { /* Determine Next Action */ unsigned int duration= Random (5000); unsigned int motorSpeed= Random (100); unsigned int syncMode= Random (3); /* Display Next Action */ ClearScreen(); NumOut(0,LCD_LINE1,duration); NumOut(0,LCD_LINE2,motorSpeed); NumOut(0,LCD_LINE3,syncMode); /* Perform Next Action */ switch (syncMode) { case 0: OnFwdReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 1: OnRevReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 2: OnFwdSync(OUT_AC,motorSpeed,-100); break ; case 3: OnRevSync(OUT_AC,motorSpeed,-100); break ; } Wait(duration); } } * This source code was highlighted with Source Code Highlighter .
  4. task music() { int lastTone=5000; while ( true ) { int tone= Random (5000)+500; int duration= Random (500); PlayTone(tone,duration); Wait(duration); } } task main() { start music; while ( true ) { /* Determine Next Action */ unsigned int duration= Random (5000); unsigned int motorSpeed= Random (100); unsigned int syncMode= Random (3); /* Display Next Action */ ClearScreen(); NumOut(0,LCD_LINE1,duration); NumOut(0,LCD_LINE2,motorSpeed); NumOut(0,LCD_LINE3,syncMode); /* Perform Next Action */ switch (syncMode) { case 0: OnFwdReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 1: OnRevReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 2: OnFwdSync(OUT_AC,motorSpeed,-100); break ; case 3: OnRevSync(OUT_AC,motorSpeed,-100); break ; } Wait(duration); } } * This source code was highlighted with Source Code Highlighter .
  5. task music() { int lastTone=5000; while ( true ) { int tone= Random (5000)+500; int duration= Random (500); PlayTone(tone,duration); Wait(duration); } } task main() { start music; while ( true ) { /* Determine Next Action */ unsigned int duration= Random (5000); unsigned int motorSpeed= Random (100); unsigned int syncMode= Random (3); /* Display Next Action */ ClearScreen(); NumOut(0,LCD_LINE1,duration); NumOut(0,LCD_LINE2,motorSpeed); NumOut(0,LCD_LINE3,syncMode); /* Perform Next Action */ switch (syncMode) { case 0: OnFwdReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 1: OnRevReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 2: OnFwdSync(OUT_AC,motorSpeed,-100); break ; case 3: OnRevSync(OUT_AC,motorSpeed,-100); break ; } Wait(duration); } } * This source code was highlighted with Source Code Highlighter .
  6. task music() { int lastTone=5000; while ( true ) { int tone= Random (5000)+500; int duration= Random (500); PlayTone(tone,duration); Wait(duration); } } task main() { start music; while ( true ) { /* Determine Next Action */ unsigned int duration= Random (5000); unsigned int motorSpeed= Random (100); unsigned int syncMode= Random (3); /* Display Next Action */ ClearScreen(); NumOut(0,LCD_LINE1,duration); NumOut(0,LCD_LINE2,motorSpeed); NumOut(0,LCD_LINE3,syncMode); /* Perform Next Action */ switch (syncMode) { case 0: OnFwdReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 1: OnRevReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 2: OnFwdSync(OUT_AC,motorSpeed,-100); break ; case 3: OnRevSync(OUT_AC,motorSpeed,-100); break ; } Wait(duration); } } * This source code was highlighted with Source Code Highlighter .
  7. task music() { int lastTone=5000; while ( true ) { int tone= Random (5000)+500; int duration= Random (500); PlayTone(tone,duration); Wait(duration); } } task main() { start music; while ( true ) { /* Determine Next Action */ unsigned int duration= Random (5000); unsigned int motorSpeed= Random (100); unsigned int syncMode= Random (3); /* Display Next Action */ ClearScreen(); NumOut(0,LCD_LINE1,duration); NumOut(0,LCD_LINE2,motorSpeed); NumOut(0,LCD_LINE3,syncMode); /* Perform Next Action */ switch (syncMode) { case 0: OnFwdReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 1: OnRevReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 2: OnFwdSync(OUT_AC,motorSpeed,-100); break ; case 3: OnRevSync(OUT_AC,motorSpeed,-100); break ; } Wait(duration); } } * This source code was highlighted with Source Code Highlighter .
  8. task music() { int lastTone=5000; while ( true ) { int tone= Random (5000)+500; int duration= Random (500); PlayTone(tone,duration); Wait(duration); } } task main() { start music; while ( true ) { /* Determine Next Action */ unsigned int duration= Random (5000); unsigned int motorSpeed= Random (100); unsigned int syncMode= Random (3); /* Display Next Action */ ClearScreen(); NumOut(0,LCD_LINE1,duration); NumOut(0,LCD_LINE2,motorSpeed); NumOut(0,LCD_LINE3,syncMode); /* Perform Next Action */ switch (syncMode) { case 0: OnFwdReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 1: OnRevReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 2: OnFwdSync(OUT_AC,motorSpeed,-100); break ; case 3: OnRevSync(OUT_AC,motorSpeed,-100); break ; } Wait(duration); } } * This source code was highlighted with Source Code Highlighter .
  9. task music() { int lastTone=5000; while ( true ) { int tone= Random (5000)+500; int duration= Random (500); PlayTone(tone,duration); Wait(duration); } } task main() { start music; while ( true ) { /* Determine Next Action */ unsigned int duration= Random (5000); unsigned int motorSpeed= Random (100); unsigned int syncMode= Random (3); /* Display Next Action */ ClearScreen(); NumOut(0,LCD_LINE1,duration); NumOut(0,LCD_LINE2,motorSpeed); NumOut(0,LCD_LINE3,syncMode); /* Perform Next Action */ switch (syncMode) { case 0: OnFwdReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 1: OnRevReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 2: OnFwdSync(OUT_AC,motorSpeed,-100); break ; case 3: OnRevSync(OUT_AC,motorSpeed,-100); break ; } Wait(duration); } } * This source code was highlighted with Source Code Highlighter .
  10. task music() { int lastTone=5000; while ( true ) { int tone= Random (5000)+500; int duration= Random (500); PlayTone(tone,duration); Wait(duration); } } task main() { start music; while ( true ) { /* Determine Next Action */ unsigned int duration= Random (5000); unsigned int motorSpeed= Random (100); unsigned int syncMode= Random (3); /* Display Next Action */ ClearScreen(); NumOut(0,LCD_LINE1,duration); NumOut(0,LCD_LINE2,motorSpeed); NumOut(0,LCD_LINE3,syncMode); /* Perform Next Action */ switch (syncMode) { case 0: OnFwdReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 1: OnRevReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 2: OnFwdSync(OUT_AC,motorSpeed,-100); break ; case 3: OnRevSync(OUT_AC,motorSpeed,-100); break ; } Wait(duration); } } * This source code was highlighted with Source Code Highlighter .
  11. task music() { int lastTone=5000; while ( true ) { int tone= Random (5000)+500; int duration= Random (500); PlayTone(tone,duration); Wait(duration); } } task main() { start music; while ( true ) { /* Determine Next Action */ unsigned int duration= Random (5000); unsigned int motorSpeed= Random (100); unsigned int syncMode= Random (3); /* Display Next Action */ ClearScreen(); NumOut(0,LCD_LINE1,duration); NumOut(0,LCD_LINE2,motorSpeed); NumOut(0,LCD_LINE3,syncMode); /* Perform Next Action */ switch (syncMode) { case 0: OnFwdReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 1: OnRevReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 2: OnFwdSync(OUT_AC,motorSpeed,-100); break ; case 3: OnRevSync(OUT_AC,motorSpeed,-100); break ; } Wait(duration); } } * This source code was highlighted with Source Code Highlighter .
  12. task music() { int lastTone=5000; while ( true ) { int tone= Random (5000)+500; int duration= Random (500); PlayTone(tone,duration); Wait(duration); } } task main() { start music; while ( true ) { /* Determine Next Action */ unsigned int duration= Random (5000); unsigned int motorSpeed= Random (100); unsigned int syncMode= Random (3); /* Display Next Action */ ClearScreen(); NumOut(0,LCD_LINE1,duration); NumOut(0,LCD_LINE2,motorSpeed); NumOut(0,LCD_LINE3,syncMode); /* Perform Next Action */ switch (syncMode) { case 0: OnFwdReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 1: OnRevReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 2: OnFwdSync(OUT_AC,motorSpeed,-100); break ; case 3: OnRevSync(OUT_AC,motorSpeed,-100); break ; } Wait(duration); } } * This source code was highlighted with Source Code Highlighter .
  13. task music() { int lastTone=5000; while ( true ) { int tone= Random (5000)+500; int duration= Random (500); PlayTone(tone,duration); Wait(duration); } } task main() { start music; while ( true ) { /* Determine Next Action */ unsigned int duration= Random (5000); unsigned int motorSpeed= Random (100); unsigned int syncMode= Random (3); /* Display Next Action */ ClearScreen(); NumOut(0,LCD_LINE1,duration); NumOut(0,LCD_LINE2,motorSpeed); NumOut(0,LCD_LINE3,syncMode); /* Perform Next Action */ switch (syncMode) { case 0: OnFwdReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 1: OnRevReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 2: OnFwdSync(OUT_AC,motorSpeed,-100); break ; case 3: OnRevSync(OUT_AC,motorSpeed,-100); break ; } Wait(duration); } } * This source code was highlighted with Source Code Highlighter .
  14. task music() { int lastTone=5000; while ( true ) { int tone= Random (5000)+500; int duration= Random (500); PlayTone(tone,duration); Wait(duration); } } task main() { start music; while ( true ) { /* Determine Next Action */ unsigned int duration= Random (5000); unsigned int motorSpeed= Random (100); unsigned int syncMode= Random (3); /* Display Next Action */ ClearScreen(); NumOut(0,LCD_LINE1,duration); NumOut(0,LCD_LINE2,motorSpeed); NumOut(0,LCD_LINE3,syncMode); /* Perform Next Action */ switch (syncMode) { case 0: OnFwdReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 1: OnRevReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 2: OnFwdSync(OUT_AC,motorSpeed,-100); break ; case 3: OnRevSync(OUT_AC,motorSpeed,-100); break ; } Wait(duration); } } * This source code was highlighted with Source Code Highlighter .
  15. task music() { int lastTone=5000; while ( true ) { int tone= Random (5000)+500; int duration= Random (500); PlayTone(tone,duration); Wait(duration); } } task main() { start music; while ( true ) { /* Determine Next Action */ unsigned int duration= Random (5000); unsigned int motorSpeed= Random (100); unsigned int syncMode= Random (3); /* Display Next Action */ ClearScreen(); NumOut(0,LCD_LINE1,duration); NumOut(0,LCD_LINE2,motorSpeed); NumOut(0,LCD_LINE3,syncMode); /* Perform Next Action */ switch (syncMode) { case 0: OnFwdReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 1: OnRevReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 2: OnFwdSync(OUT_AC,motorSpeed,-100); break ; case 3: OnRevSync(OUT_AC,motorSpeed,-100); break ; } Wait(duration); } } * This source code was highlighted with Source Code Highlighter .
  16. task music() { int lastTone=5000; while ( true ) { int tone= Random (5000)+500; int duration= Random (500); PlayTone(tone,duration); Wait(duration); } } task main() { start music; while ( true ) { /* Determine Next Action */ unsigned int duration= Random (5000); unsigned int motorSpeed= Random (100); unsigned int syncMode= Random (3); /* Display Next Action */ ClearScreen(); NumOut(0,LCD_LINE1,duration); NumOut(0,LCD_LINE2,motorSpeed); NumOut(0,LCD_LINE3,syncMode); /* Perform Next Action */ switch (syncMode) { case 0: OnFwdReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 1: OnRevReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 2: OnFwdSync(OUT_AC,motorSpeed,-100); break ; case 3: OnRevSync(OUT_AC,motorSpeed,-100); break ; } Wait(duration); } } * This source code was highlighted with Source Code Highlighter .
  17. task music() { int lastTone=5000; while ( true ) { int tone= Random (5000)+500; int duration= Random (500); PlayTone(tone,duration); Wait(duration); } } task main() { start music; while ( true ) { /* Determine Next Action */ unsigned int duration= Random (5000); unsigned int motorSpeed= Random (100); unsigned int syncMode= Random (3); /* Display Next Action */ ClearScreen(); NumOut(0,LCD_LINE1,duration); NumOut(0,LCD_LINE2,motorSpeed); NumOut(0,LCD_LINE3,syncMode); /* Perform Next Action */ switch (syncMode) { case 0: OnFwdReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 1: OnRevReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 2: OnFwdSync(OUT_AC,motorSpeed,-100); break ; case 3: OnRevSync(OUT_AC,motorSpeed,-100); break ; } Wait(duration); } } * This source code was highlighted with Source Code Highlighter .
  18. task music() { int lastTone=5000; while ( true ) { int tone= Random (5000)+500; int duration= Random (500); PlayTone(tone,duration); Wait(duration); } } task main() { start music; while ( true ) { /* Determine Next Action */ unsigned int duration= Random (5000); unsigned int motorSpeed= Random (100); unsigned int syncMode= Random (3); /* Display Next Action */ ClearScreen(); NumOut(0,LCD_LINE1,duration); NumOut(0,LCD_LINE2,motorSpeed); NumOut(0,LCD_LINE3,syncMode); /* Perform Next Action */ switch (syncMode) { case 0: OnFwdReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 1: OnRevReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 2: OnFwdSync(OUT_AC,motorSpeed,-100); break ; case 3: OnRevSync(OUT_AC,motorSpeed,-100); break ; } Wait(duration); } } * This source code was highlighted with Source Code Highlighter .
  19. task music() { int lastTone=5000; while ( true ) { int tone= Random (5000)+500; int duration= Random (500); PlayTone(tone,duration); Wait(duration); } } task main() { start music; while ( true ) { /* Determine Next Action */ unsigned int duration= Random (5000); unsigned int motorSpeed= Random (100); unsigned int syncMode= Random (3); /* Display Next Action */ ClearScreen(); NumOut(0,LCD_LINE1,duration); NumOut(0,LCD_LINE2,motorSpeed); NumOut(0,LCD_LINE3,syncMode); /* Perform Next Action */ switch (syncMode) { case 0: OnFwdReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 1: OnRevReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 2: OnFwdSync(OUT_AC,motorSpeed,-100); break ; case 3: OnRevSync(OUT_AC,motorSpeed,-100); break ; } Wait(duration); } } * This source code was highlighted with Source Code Highlighter .
  20. task music() { int lastTone=5000; while ( true ) { int tone= Random (5000)+500; int duration= Random (500); PlayTone(tone,duration); Wait(duration); } } task main() { start music; while ( true ) { /* Determine Next Action */ unsigned int duration= Random (5000); unsigned int motorSpeed= Random (100); unsigned int syncMode= Random (3); /* Display Next Action */ ClearScreen(); NumOut(0,LCD_LINE1,duration); NumOut(0,LCD_LINE2,motorSpeed); NumOut(0,LCD_LINE3,syncMode); /* Perform Next Action */ switch (syncMode) { case 0: OnFwdReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 1: OnRevReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 2: OnFwdSync(OUT_AC,motorSpeed,-100); break ; case 3: OnRevSync(OUT_AC,motorSpeed,-100); break ; } Wait(duration); } } * This source code was highlighted with Source Code Highlighter .
  21. task music() { int lastTone=5000; while ( true ) { int tone= Random (5000)+500; int duration= Random (500); PlayTone(tone,duration); Wait(duration); } } task main() { start music; while ( true ) { /* Determine Next Action */ unsigned int duration= Random (5000); unsigned int motorSpeed= Random (100); unsigned int syncMode= Random (3); /* Display Next Action */ ClearScreen(); NumOut(0,LCD_LINE1,duration); NumOut(0,LCD_LINE2,motorSpeed); NumOut(0,LCD_LINE3,syncMode); /* Perform Next Action */ switch (syncMode) { case 0: OnFwdReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 1: OnRevReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 2: OnFwdSync(OUT_AC,motorSpeed,-100); break ; case 3: OnRevSync(OUT_AC,motorSpeed,-100); break ; } Wait(duration); } } * This source code was highlighted with Source Code Highlighter .
  22. task music() { int lastTone=5000; while ( true ) { int tone= Random (5000)+500; int duration= Random (500); PlayTone(tone,duration); Wait(duration); } } task main() { start music; while ( true ) { /* Determine Next Action */ unsigned int duration= Random (5000); unsigned int motorSpeed= Random (100); unsigned int syncMode= Random (3); /* Display Next Action */ ClearScreen(); NumOut(0,LCD_LINE1,duration); NumOut(0,LCD_LINE2,motorSpeed); NumOut(0,LCD_LINE3,syncMode); /* Perform Next Action */ switch (syncMode) { case 0: OnFwdReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 1: OnRevReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 2: OnFwdSync(OUT_AC,motorSpeed,-100); break ; case 3: OnRevSync(OUT_AC,motorSpeed,-100); break ; } Wait(duration); } } * This source code was highlighted with Source Code Highlighter .
  23. task music() { int lastTone=5000; while ( true ) { int tone= Random (5000)+500; int duration= Random (500); PlayTone(tone,duration); Wait(duration); } } task main() { start music; while ( true ) { /* Determine Next Action */ unsigned int duration= Random (5000); unsigned int motorSpeed= Random (100); unsigned int syncMode= Random (3); /* Display Next Action */ ClearScreen(); NumOut(0,LCD_LINE1,duration); NumOut(0,LCD_LINE2,motorSpeed); NumOut(0,LCD_LINE3,syncMode); /* Perform Next Action */ switch (syncMode) { case 0: OnFwdReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 1: OnRevReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 2: OnFwdSync(OUT_AC,motorSpeed,-100); break ; case 3: OnRevSync(OUT_AC,motorSpeed,-100); break ; } Wait(duration); } } * This source code was highlighted with Source Code Highlighter .
  24. task music() { int lastTone=5000; while ( true ) { int tone= Random (5000)+500; int duration= Random (500); PlayTone(tone,duration); Wait(duration); } } task main() { start music; while ( true ) { /* Determine Next Action */ unsigned int duration= Random (5000); unsigned int motorSpeed= Random (100); unsigned int syncMode= Random (3); /* Display Next Action */ ClearScreen(); NumOut(0,LCD_LINE1,duration); NumOut(0,LCD_LINE2,motorSpeed); NumOut(0,LCD_LINE3,syncMode); /* Perform Next Action */ switch (syncMode) { case 0: OnFwdReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 1: OnRevReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 2: OnFwdSync(OUT_AC,motorSpeed,-100); break ; case 3: OnRevSync(OUT_AC,motorSpeed,-100); break ; } Wait(duration); } } * This source code was highlighted with Source Code Highlighter .
  25. task music() { int lastTone=5000; while ( true ) { int tone= Random (5000)+500; int duration= Random (500); PlayTone(tone,duration); Wait(duration); } } task main() { start music; while ( true ) { /* Determine Next Action */ unsigned int duration= Random (5000); unsigned int motorSpeed= Random (100); unsigned int syncMode= Random (3); /* Display Next Action */ ClearScreen(); NumOut(0,LCD_LINE1,duration); NumOut(0,LCD_LINE2,motorSpeed); NumOut(0,LCD_LINE3,syncMode); /* Perform Next Action */ switch (syncMode) { case 0: OnFwdReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 1: OnRevReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 2: OnFwdSync(OUT_AC,motorSpeed,-100); break ; case 3: OnRevSync(OUT_AC,motorSpeed,-100); break ; } Wait(duration); } } * This source code was highlighted with Source Code Highlighter .
  26. task music() { int lastTone=5000; while ( true ) { int tone= Random (5000)+500; int duration= Random (500); PlayTone(tone,duration); Wait(duration); } } task main() { start music; while ( true ) { /* Determine Next Action */ unsigned int duration= Random (5000); unsigned int motorSpeed= Random (100); unsigned int syncMode= Random (3); /* Display Next Action */ ClearScreen(); NumOut(0,LCD_LINE1,duration); NumOut(0,LCD_LINE2,motorSpeed); NumOut(0,LCD_LINE3,syncMode); /* Perform Next Action */ switch (syncMode) { case 0: OnFwdReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 1: OnRevReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 2: OnFwdSync(OUT_AC,motorSpeed,-100); break ; case 3: OnRevSync(OUT_AC,motorSpeed,-100); break ; } Wait(duration); } } * This source code was highlighted with Source Code Highlighter .
  27. task music() { int lastTone=5000; while ( true ) { int tone= Random (5000)+500; int duration= Random (500); PlayTone(tone,duration); Wait(duration); } } task main() { start music; while ( true ) { /* Determine Next Action */ unsigned int duration= Random (5000); unsigned int motorSpeed= Random (100); unsigned int syncMode= Random (3); /* Display Next Action */ ClearScreen(); NumOut(0,LCD_LINE1,duration); NumOut(0,LCD_LINE2,motorSpeed); NumOut(0,LCD_LINE3,syncMode); /* Perform Next Action */ switch (syncMode) { case 0: OnFwdReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 1: OnRevReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 2: OnFwdSync(OUT_AC,motorSpeed,-100); break ; case 3: OnRevSync(OUT_AC,motorSpeed,-100); break ; } Wait(duration); } } * This source code was highlighted with Source Code Highlighter .
  28. task music() { int lastTone=5000; while ( true ) { int tone= Random (5000)+500; int duration= Random (500); PlayTone(tone,duration); Wait(duration); } } task main() { start music; while ( true ) { /* Determine Next Action */ unsigned int duration= Random (5000); unsigned int motorSpeed= Random (100); unsigned int syncMode= Random (3); /* Display Next Action */ ClearScreen(); NumOut(0,LCD_LINE1,duration); NumOut(0,LCD_LINE2,motorSpeed); NumOut(0,LCD_LINE3,syncMode); /* Perform Next Action */ switch (syncMode) { case 0: OnFwdReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 1: OnRevReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 2: OnFwdSync(OUT_AC,motorSpeed,-100); break ; case 3: OnRevSync(OUT_AC,motorSpeed,-100); break ; } Wait(duration); } } * This source code was highlighted with Source Code Highlighter .
  29. task music() { int lastTone=5000; while ( true ) { int tone= Random (5000)+500; int duration= Random (500); PlayTone(tone,duration); Wait(duration); } } task main() { start music; while ( true ) { /* Determine Next Action */ unsigned int duration= Random (5000); unsigned int motorSpeed= Random (100); unsigned int syncMode= Random (3); /* Display Next Action */ ClearScreen(); NumOut(0,LCD_LINE1,duration); NumOut(0,LCD_LINE2,motorSpeed); NumOut(0,LCD_LINE3,syncMode); /* Perform Next Action */ switch (syncMode) { case 0: OnFwdReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 1: OnRevReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 2: OnFwdSync(OUT_AC,motorSpeed,-100); break ; case 3: OnRevSync(OUT_AC,motorSpeed,-100); break ; } Wait(duration); } } * This source code was highlighted with Source Code Highlighter .
  30. task music() { int lastTone=5000; while ( true ) { int tone= Random (5000)+500; int duration= Random (500); PlayTone(tone,duration); Wait(duration); } } task main() { start music; while ( true ) { /* Determine Next Action */ unsigned int duration= Random (5000); unsigned int motorSpeed= Random (100); unsigned int syncMode= Random (3); /* Display Next Action */ ClearScreen(); NumOut(0,LCD_LINE1,duration); NumOut(0,LCD_LINE2,motorSpeed); NumOut(0,LCD_LINE3,syncMode); /* Perform Next Action */ switch (syncMode) { case 0: OnFwdReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 1: OnRevReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 2: OnFwdSync(OUT_AC,motorSpeed,-100); break ; case 3: OnRevSync(OUT_AC,motorSpeed,-100); break ; } Wait(duration); } } * This source code was highlighted with Source Code Highlighter .
  31. task music() { int lastTone=5000; while ( true ) { int tone= Random (5000)+500; int duration= Random (500); PlayTone(tone,duration); Wait(duration); } } task main() { start music; while ( true ) { /* Determine Next Action */ unsigned int duration= Random (5000); unsigned int motorSpeed= Random (100); unsigned int syncMode= Random (3); /* Display Next Action */ ClearScreen(); NumOut(0,LCD_LINE1,duration); NumOut(0,LCD_LINE2,motorSpeed); NumOut(0,LCD_LINE3,syncMode); /* Perform Next Action */ switch (syncMode) { case 0: OnFwdReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 1: OnRevReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 2: OnFwdSync(OUT_AC,motorSpeed,-100); break ; case 3: OnRevSync(OUT_AC,motorSpeed,-100); break ; } Wait(duration); } } * This source code was highlighted with Source Code Highlighter .
  32. task music() { int lastTone=5000; while ( true ) { int tone= Random (5000)+500; int duration= Random (500); PlayTone(tone,duration); Wait(duration); } } task main() { start music; while ( true ) { /* Determine Next Action */ unsigned int duration= Random (5000); unsigned int motorSpeed= Random (100); unsigned int syncMode= Random (3); /* Display Next Action */ ClearScreen(); NumOut(0,LCD_LINE1,duration); NumOut(0,LCD_LINE2,motorSpeed); NumOut(0,LCD_LINE3,syncMode); /* Perform Next Action */ switch (syncMode) { case 0: OnFwdReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 1: OnRevReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 2: OnFwdSync(OUT_AC,motorSpeed,-100); break ; case 3: OnRevSync(OUT_AC,motorSpeed,-100); break ; } Wait(duration); } } * This source code was highlighted with Source Code Highlighter .
  33. task music() { int lastTone=5000; while ( true ) { int tone= Random (5000)+500; int duration= Random (500); PlayTone(tone,duration); Wait(duration); } } task main() { start music; while ( true ) { /* Determine Next Action */ unsigned int duration= Random (5000); unsigned int motorSpeed= Random (100); unsigned int syncMode= Random (3); /* Display Next Action */ ClearScreen(); NumOut(0,LCD_LINE1,duration); NumOut(0,LCD_LINE2,motorSpeed); NumOut(0,LCD_LINE3,syncMode); /* Perform Next Action */ switch (syncMode) { case 0: OnFwdReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 1: OnRevReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 2: OnFwdSync(OUT_AC,motorSpeed,-100); break ; case 3: OnRevSync(OUT_AC,motorSpeed,-100); break ; } Wait(duration); } } * This source code was highlighted with Source Code Highlighter .
  34. task music() { int lastTone=5000; while ( true ) { int tone= Random (5000)+500; int duration= Random (500); PlayTone(tone,duration); Wait(duration); } } task main() { start music; while ( true ) { /* Determine Next Action */ unsigned int duration= Random (5000); unsigned int motorSpeed= Random (100); unsigned int syncMode= Random (3); /* Display Next Action */ ClearScreen(); NumOut(0,LCD_LINE1,duration); NumOut(0,LCD_LINE2,motorSpeed); NumOut(0,LCD_LINE3,syncMode); /* Perform Next Action */ switch (syncMode) { case 0: OnFwdReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 1: OnRevReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 2: OnFwdSync(OUT_AC,motorSpeed,-100); break ; case 3: OnRevSync(OUT_AC,motorSpeed,-100); break ; } Wait(duration); } } * This source code was highlighted with Source Code Highlighter .
  35. task music() { int lastTone=5000; while ( true ) { int tone= Random (5000)+500; int duration= Random (500); PlayTone(tone,duration); Wait(duration); } } task main() { start music; while ( true ) { /* Determine Next Action */ unsigned int duration= Random (5000); unsigned int motorSpeed= Random (100); unsigned int syncMode= Random (3); /* Display Next Action */ ClearScreen(); NumOut(0,LCD_LINE1,duration); NumOut(0,LCD_LINE2,motorSpeed); NumOut(0,LCD_LINE3,syncMode); /* Perform Next Action */ switch (syncMode) { case 0: OnFwdReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 1: OnRevReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 2: OnFwdSync(OUT_AC,motorSpeed,-100); break ; case 3: OnRevSync(OUT_AC,motorSpeed,-100); break ; } Wait(duration); } } * This source code was highlighted with Source Code Highlighter .
  36. task music() { int lastTone=5000; while ( true ) { int tone= Random (5000)+500; int duration= Random (500); PlayTone(tone,duration); Wait(duration); } } task main() { start music; while ( true ) { /* Determine Next Action */ unsigned int duration= Random (5000); unsigned int motorSpeed= Random (100); unsigned int syncMode= Random (3); /* Display Next Action */ ClearScreen(); NumOut(0,LCD_LINE1,duration); NumOut(0,LCD_LINE2,motorSpeed); NumOut(0,LCD_LINE3,syncMode); /* Perform Next Action */ switch (syncMode) { case 0: OnFwdReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 1: OnRevReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 2: OnFwdSync(OUT_AC,motorSpeed,-100); break ; case 3: OnRevSync(OUT_AC,motorSpeed,-100); break ; } Wait(duration); } } * This source code was highlighted with Source Code Highlighter .
  37. task music() { int lastTone=5000; while ( true ) { int tone= Random (5000)+500; int duration= Random (500); PlayTone(tone,duration); Wait(duration); } } task main() { start music; while ( true ) { /* Determine Next Action */ unsigned int duration= Random (5000); unsigned int motorSpeed= Random (100); unsigned int syncMode= Random (3); /* Display Next Action */ ClearScreen(); NumOut(0,LCD_LINE1,duration); NumOut(0,LCD_LINE2,motorSpeed); NumOut(0,LCD_LINE3,syncMode); /* Perform Next Action */ switch (syncMode) { case 0: OnFwdReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 1: OnRevReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 2: OnFwdSync(OUT_AC,motorSpeed,-100); break ; case 3: OnRevSync(OUT_AC,motorSpeed,-100); break ; } Wait(duration); } } * This source code was highlighted with Source Code Highlighter .
  38. task music() { int lastTone=5000; while ( true ) { int tone= Random (5000)+500; int duration= Random (500); PlayTone(tone,duration); Wait(duration); } } task main() { start music; while ( true ) { /* Determine Next Action */ unsigned int duration= Random (5000); unsigned int motorSpeed= Random (100); unsigned int syncMode= Random (3); /* Display Next Action */ ClearScreen(); NumOut(0,LCD_LINE1,duration); NumOut(0,LCD_LINE2,motorSpeed); NumOut(0,LCD_LINE3,syncMode); /* Perform Next Action */ switch (syncMode) { case 0: OnFwdReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 1: OnRevReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 2: OnFwdSync(OUT_AC,motorSpeed,-100); break ; case 3: OnRevSync(OUT_AC,motorSpeed,-100); break ; } Wait(duration); } } * This source code was highlighted with Source Code Highlighter .
  39. task music() { int lastTone=5000; while ( true ) { int tone= Random (5000)+500; int duration= Random (500); PlayTone(tone,duration); Wait(duration); } } task main() { start music; while ( true ) { /* Determine Next Action */ unsigned int duration= Random (5000); unsigned int motorSpeed= Random (100); unsigned int syncMode= Random (3); /* Display Next Action */ ClearScreen(); NumOut(0,LCD_LINE1,duration); NumOut(0,LCD_LINE2,motorSpeed); NumOut(0,LCD_LINE3,syncMode); /* Perform Next Action */ switch (syncMode) { case 0: OnFwdReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 1: OnRevReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 2: OnFwdSync(OUT_AC,motorSpeed,-100); break ; case 3: OnRevSync(OUT_AC,motorSpeed,-100); break ; } Wait(duration); } } * This source code was highlighted with Source Code Highlighter .
  40. task music() { int lastTone=5000; while ( true ) { int tone= Random (5000)+500; int duration= Random (500); PlayTone(tone,duration); Wait(duration); } } task main() { start music; while ( true ) { /* Determine Next Action */ unsigned int duration= Random (5000); unsigned int motorSpeed= Random (100); unsigned int syncMode= Random (3); /* Display Next Action */ ClearScreen(); NumOut(0,LCD_LINE1,duration); NumOut(0,LCD_LINE2,motorSpeed); NumOut(0,LCD_LINE3,syncMode); /* Perform Next Action */ switch (syncMode) { case 0: OnFwdReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 1: OnRevReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 2: OnFwdSync(OUT_AC,motorSpeed,-100); break ; case 3: OnRevSync(OUT_AC,motorSpeed,-100); break ; } Wait(duration); } } * This source code was highlighted with Source Code Highlighter .
  41. task music() { int lastTone=5000; while ( true ) { int tone= Random (5000)+500; int duration= Random (500); PlayTone(tone,duration); Wait(duration); } } task main() { start music; while ( true ) { /* Determine Next Action */ unsigned int duration= Random (5000); unsigned int motorSpeed= Random (100); unsigned int syncMode= Random (3); /* Display Next Action */ ClearScreen(); NumOut(0,LCD_LINE1,duration); NumOut(0,LCD_LINE2,motorSpeed); NumOut(0,LCD_LINE3,syncMode); /* Perform Next Action */ switch (syncMode) { case 0: OnFwdReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 1: OnRevReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 2: OnFwdSync(OUT_AC,motorSpeed,-100); break ; case 3: OnRevSync(OUT_AC,motorSpeed,-100); break ; } Wait(duration); } } * This source code was highlighted with Source Code Highlighter .
  42. task music() { int lastTone=5000; while ( true ) { int tone= Random (5000)+500; int duration= Random (500); PlayTone(tone,duration); Wait(duration); } } task main() { start music; while ( true ) { /* Determine Next Action */ unsigned int duration= Random (5000); unsigned int motorSpeed= Random (100); unsigned int syncMode= Random (3); /* Display Next Action */ ClearScreen(); NumOut(0,LCD_LINE1,duration); NumOut(0,LCD_LINE2,motorSpeed); NumOut(0,LCD_LINE3,syncMode); /* Perform Next Action */ switch (syncMode) { case 0: OnFwdReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 1: OnRevReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 2: OnFwdSync(OUT_AC,motorSpeed,-100); break ; case 3: OnRevSync(OUT_AC,motorSpeed,-100); break ; } Wait(duration); } } * This source code was highlighted with Source Code Highlighter .
  43. task music() { int lastTone=5000; while ( true ) { int tone= Random (5000)+500; int duration= Random (500); PlayTone(tone,duration); Wait(duration); } } task main() { start music; while ( true ) { /* Determine Next Action */ unsigned int duration= Random (5000); unsigned int motorSpeed= Random (100); unsigned int syncMode= Random (3); /* Display Next Action */ ClearScreen(); NumOut(0,LCD_LINE1,duration); NumOut(0,LCD_LINE2,motorSpeed); NumOut(0,LCD_LINE3,syncMode); /* Perform Next Action */ switch (syncMode) { case 0: OnFwdReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 1: OnRevReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 2: OnFwdSync(OUT_AC,motorSpeed,-100); break ; case 3: OnRevSync(OUT_AC,motorSpeed,-100); break ; } Wait(duration); } } * This source code was highlighted with Source Code Highlighter .
  44. task music() { int lastTone=5000; while ( true ) { int tone= Random (5000)+500; int duration= Random (500); PlayTone(tone,duration); Wait(duration); } } task main() { start music; while ( true ) { /* Determine Next Action */ unsigned int duration= Random (5000); unsigned int motorSpeed= Random (100); unsigned int syncMode= Random (3); /* Display Next Action */ ClearScreen(); NumOut(0,LCD_LINE1,duration); NumOut(0,LCD_LINE2,motorSpeed); NumOut(0,LCD_LINE3,syncMode); /* Perform Next Action */ switch (syncMode) { case 0: OnFwdReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 1: OnRevReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 2: OnFwdSync(OUT_AC,motorSpeed,-100); break ; case 3: OnRevSync(OUT_AC,motorSpeed,-100); break ; } Wait(duration); } } * This source code was highlighted with Source Code Highlighter .
task music() { int lastTone=5000; while ( true ) { int tone= Random (5000)+500; int duration= Random (500); PlayTone(tone,duration); Wait(duration); } } task main() { start music; while ( true ) { /* Determine Next Action */ unsigned int duration= Random (5000); unsigned int motorSpeed= Random (100); unsigned int syncMode= Random (3); /* Display Next Action */ ClearScreen(); NumOut(0,LCD_LINE1,duration); NumOut(0,LCD_LINE2,motorSpeed); NumOut(0,LCD_LINE3,syncMode); /* Perform Next Action */ switch (syncMode) { case 0: OnFwdReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 1: OnRevReg(OUT_AC,motorSpeed,OUT_REGMODE_SYNC); break ; case 2: OnFwdSync(OUT_AC,motorSpeed,-100); break ; case 3: OnRevSync(OUT_AC,motorSpeed,-100); break ; } Wait(duration); } } * This source code was highlighted with Source Code Highlighter .

For reference, this program causes our robot to “dance” to something resembling music.

I will not argue, the program is not difficult to understand, but rather cumbersome. And it can be simplified noticeably, using instead of writing code on the NXC a special converter PyNXC . In other words, we will write code in Python, and PyNXC will convert it to NXC code and download it to the device, saving us from having to write bulky code like C.


We write the program!


Well, now, in fact, we will write on Python a program for traveling our robot among transparent cups, but using a more competent reversal algorithm:
  1. # in cm
  2. DEFINE NEAR = 7
  3. def main ():
  4. DefineSensors (None, None, None, EYES)
  5. while true:
  6. OnFwd (OUT_BC, 50)
  7. while SensorVal (4)> NEAR:
  8. pass
  9. Off (OUT_BC)
  10. while SensorVal (4) <NEAR:
  11. OnFwd (OUT_B, 50)
  12. Wait (100)
* This source code was highlighted with Source Code Highlighter .

Now our robot has learned to turn on the spot and, as soon as the interfering object disappears from his field of vision, continue moving forward.

As you have probably noticed, programming Mindstorms is very simple. It should also be said that in addition to NXC and Python using PyNXC, you can write code in Java, Lua, Ruby, Assembler, and also, which is logical, use assembly inserts in other languages.
Thanks to all this, Mindstorms from a children's toy turns into a very powerful piece that allows you to create complex and “smart” mechanisms, like this guitar for example:



Or this sorter of colored balls:



And the best part about all of this is that most of the necessary parts are already included in the Mindstorms NXT 2.0 package. The only thing that can really be needed is additional sensors that can be bought, for example, in the official Lego store.

Source: https://habr.com/ru/post/116408/


All Articles