Перевод статьи "Программирование LEGO NXT роботов на языке NXC" — различия между версиями

Материал из roboforum.ru Wiki
Перейти к: навигация, поиск
Строка 6: Строка 6:
 
<p align=center><b>Автор: Daniele Benedettelli</b><br><br><i>Перевод: © Ботов Антон aka =DeaD=, 2009<br><br>Эксклюзивно для www.roboforum.ru<br> копирование на другие ресурсы и публикация перевода<br>без разрешения его автора запрещены</i></p>
 
<p align=center><b>Автор: Daniele Benedettelli</b><br><br><i>Перевод: © Ботов Антон aka =DeaD=, 2009<br><br>Эксклюзивно для www.roboforum.ru<br> копирование на другие ресурсы и публикация перевода<br>без разрешения его автора запрещены</i></p>
  
==Preface==
+
Содержание:
As happened for good old Mindstorms RIS, CyberMaster, and Spybotics, to unleash the full power of
+
* [[Введение]]Preface ___________________________________________________________________ 2
Mindstorms NXT brick, you need a programming environment that is more handy than NXT-G, the National
+
** Acknowledgements____________________________________________________________________ 2
Instruments Labview-like graphical language that comes with NXT retail set.
+
* Writing your first program __________________________________________________ 5
 
+
**Building a robot ______________________________________________________________________ 5
NXC is a programming language, invented by John Hansen, which was especially designed for the Lego robots.
+
**Starting Bricx Command Center __________________________________________________________ 5
If you have never written a program before, don't worry. NXC is really easy to use and this tutorial will lead you
+
**Writing the program ___________________________________________________________________ 6
on your first steps towards it.
+
**Running the program __________________________________________________________________ 7
 
+
**Errors in your program _________________________________________________________________ 8
To make writing programs even easier, there is the Bricx Command Center (BricxCC). This utility helps you to
+
**Changing the speed ____________________________________________________________________ 8
write your programs, to download them to the robot, to start and stop them, browse NXT flash memory, convert
+
**Summary____________________________________________________________________________ 9
sound files for use with the brick, and much more. BricxCC works almost like a text processor, but with some
+
*A more interesting program _______________________________________________ 10
extras. This tutorial will use BricxCC (version 3.3.7.16 or higher) as integrated development environment (IDE).
+
**Making turns ________________________________________________________________________ 10
 
+
**Repeating commands _________________________________________________________________ 10
You can download it for free from the web at the address
+
**Adding comments ____________________________________________________________________ 11
* [[http://bricxcc.sourceforge.net/ http://bricxcc.sourceforge.net/]]
+
**Summary___________________________________________________________________________ 12
 
+
* Using variables_________________________________________________________ 13
BricxCC runs on Windows PCs (95, 98, ME, NT, 2K, XP, Vista). The NXC language can also be used on other
+
**Moving in a spiral ____________________________________________________________________ 13
platforms. You can download it from the web page
+
**Random numbers ____________________________________________________________________ 14
* [[http://bricxcc.sourceforge.net/nxc/ http://bricxcc.sourceforge.net/nxc/]]
+
**Summary___________________________________________________________________________ 15
 
+
*Control structures_______________________________________________________ 16
Most of this tutorial should also apply to other platforms, except that you loose some of the tools included in
+
**The if statement______________________________________________________________________ 16
BricxCC and the color-coding.
+
**The do statement _____________________________________________________________________ 17
 
+
**Summary___________________________________________________________________________ 17
The tutorial has been updated to work with beta 30 of NXC and higher versions. Some of the sample programs
+
*Sensors ________________________________________________________________ 18
will not compile with versions older than beta 30.
+
**Waiting for a sensor __________________________________________________________________ 18
 
+
**Acting on a touch sensor _______________________________________________________________ 19
As side note, my webpage is full of Lego Mindstorms RCX and NXT related content, including a PC tool to
+
**Light sensor_________________________________________________________________________ 19
communicate with NXT:
+
**Sound sensor ________________________________________________________________________ 20
* [[http://daniele.benedettelli.com http://daniele.benedettelli.com]]
+
**Ultrasonic sensor_____________________________________________________________________ 21
 
+
**Summary___________________________________________________________________________ 22
===Acknowledgements===
+
*Tasks and subroutines ___________________________________________________ 23
Many thanks go to John Hansen, whose work is priceless!
+
**Tasks ______________________________________________________________________________ 23
 +
**Subroutines _________________________________________________________________________ 24
 +
**Defining macros _____________________________________________________________________ 25
 +
**Summary___________________________________________________________________________ 26
 +
*Making music _________________________________________________________ 28
 +
**Playing sound files ___________________________________________________________________ 28
 +
**Playing music _______________________________________________________________________ 28
 +
**Summary___________________________________________________________________________ 30
 +
*More about motors ____________________________________________________ 31
 +
**Stopping gently ______________________________________________________________________ 31
 +
**Advanced commands _________________________________________________________________ 31
 +
**PID control _________________________________________________________________________ 33
 +
**Summary___________________________________________________________________________ 34
 +
*More about sensors _____________________________________________________ 35
 +
**Sensor mode and type _________________________________________________________________ 35
 +
**The rotation sensor ___________________________________________________________________ 36
 +
**Putting multiple sensors on one input _____________________________________________________ 37
 +
**Summary___________________________________________________________________________ 38
 +
*Parallel tasks ___________________________________________________________ 39
 +
**A wrong program ____________________________________________________________________ 39
 +
**Critical sections and mutex variables _____________________________________________________ 39
 +
**Using semaphores ____________________________________________________________________ 40
 +
**Summary___________________________________________________________________________ 41
 +
*Communication between robots ___________________________________________ 42
 +
**Master – Slave messaging______________________________________________________________ 42
 +
**Sending numbers with acknowledgement__________________________________________________ 43
 +
**Direct commands ____________________________________________________________________ 45
 +
**Summary___________________________________________________________________________ 45
 +
*More commands _______________________________________________________ 46
 +
**Timers _____________________________________________________________________________ 46
 +
**Dot matrix display____________________________________________________________________ 46
 +
**File system _________________________________________________________________________ 47
 +
**Summary___________________________________________________________________________ 50
 +
*Final remarks ________________________________________________________ 51

Версия 13:13, 16 мая 2009

(перевод статьи "Programming LEGO NXT Robots using NXC")


Исходная статья: [http://bricxcc.sourceforge.net/nbc/nxcdoc/NXC_tutorial.pdf]

Автор: Daniele Benedettelli

Перевод: © Ботов Антон aka =DeaD=, 2009

Эксклюзивно для www.roboforum.ru
копирование на другие ресурсы и публикация перевода
без разрешения его автора запрещены

Содержание:

  • ВведениеPreface ___________________________________________________________________ 2
    • Acknowledgements____________________________________________________________________ 2
  • Writing your first program __________________________________________________ 5
    • Building a robot ______________________________________________________________________ 5
    • Starting Bricx Command Center __________________________________________________________ 5
    • Writing the program ___________________________________________________________________ 6
    • Running the program __________________________________________________________________ 7
    • Errors in your program _________________________________________________________________ 8
    • Changing the speed ____________________________________________________________________ 8
    • Summary____________________________________________________________________________ 9
  • A more interesting program _______________________________________________ 10
    • Making turns ________________________________________________________________________ 10
    • Repeating commands _________________________________________________________________ 10
    • Adding comments ____________________________________________________________________ 11
    • Summary___________________________________________________________________________ 12
  • Using variables_________________________________________________________ 13
    • Moving in a spiral ____________________________________________________________________ 13
    • Random numbers ____________________________________________________________________ 14
    • Summary___________________________________________________________________________ 15
  • Control structures_______________________________________________________ 16
    • The if statement______________________________________________________________________ 16
    • The do statement _____________________________________________________________________ 17
    • Summary___________________________________________________________________________ 17
  • Sensors ________________________________________________________________ 18
    • Waiting for a sensor __________________________________________________________________ 18
    • Acting on a touch sensor _______________________________________________________________ 19
    • Light sensor_________________________________________________________________________ 19
    • Sound sensor ________________________________________________________________________ 20
    • Ultrasonic sensor_____________________________________________________________________ 21
    • Summary___________________________________________________________________________ 22
  • Tasks and subroutines ___________________________________________________ 23
    • Tasks ______________________________________________________________________________ 23
    • Subroutines _________________________________________________________________________ 24
    • Defining macros _____________________________________________________________________ 25
    • Summary___________________________________________________________________________ 26
  • Making music _________________________________________________________ 28
    • Playing sound files ___________________________________________________________________ 28
    • Playing music _______________________________________________________________________ 28
    • Summary___________________________________________________________________________ 30
  • More about motors ____________________________________________________ 31
    • Stopping gently ______________________________________________________________________ 31
    • Advanced commands _________________________________________________________________ 31
    • PID control _________________________________________________________________________ 33
    • Summary___________________________________________________________________________ 34
  • More about sensors _____________________________________________________ 35
    • Sensor mode and type _________________________________________________________________ 35
    • The rotation sensor ___________________________________________________________________ 36
    • Putting multiple sensors on one input _____________________________________________________ 37
    • Summary___________________________________________________________________________ 38
  • Parallel tasks ___________________________________________________________ 39
    • A wrong program ____________________________________________________________________ 39
    • Critical sections and mutex variables _____________________________________________________ 39
    • Using semaphores ____________________________________________________________________ 40
    • Summary___________________________________________________________________________ 41
  • Communication between robots ___________________________________________ 42
    • Master – Slave messaging______________________________________________________________ 42
    • Sending numbers with acknowledgement__________________________________________________ 43
    • Direct commands ____________________________________________________________________ 45
    • Summary___________________________________________________________________________ 45
  • More commands _______________________________________________________ 46
    • Timers _____________________________________________________________________________ 46
    • Dot matrix display____________________________________________________________________ 46
    • File system _________________________________________________________________________ 47
    • Summary___________________________________________________________________________ 50
  • Final remarks ________________________________________________________ 51