📜 ⬆️ ⬇️

Programming microcomputer LEGO NXT Mindstorms 2.0. Introduction

Hello. In my articles, I want to introduce you to the basics of programming a LEGO NXT Mindstorms 2.0 microcomputer. I will use Microsoft Robotics Developer Studio 4 (MRDS 4) and National Instruments LabVIEW (NI LabVIEW) platforms for application development. The tasks of automatic and automated control of mobile robots will be considered and implemented. We will move from simple to complex.




Anticipating some questions and comments from readers.


Why NXT Mindstorms 2.0? Because for my projects this set seemed to me the most suitable, because The NXT microcomputer is fully compatible with the MRDS 4 and NI LabVIEW platforms, as well as this kit is very flexible in terms of assembling various configurations of robots - it takes a minimum of time to assemble the robot.
')
Why MRDS 4 and NI LabVIEW platforms? It happened historically. While studying at university, there was a task in developing training courses using these platforms. In addition, the platforms have sufficient ease of use and functionality, with their use, you can write a program directly to control the robot, develop a user interface and test in a virtual environment (in the case of MRDS 4).

Who needs these lessons from you, on the net, and so a lot of projects on robotics! With the use of this bundle (NXT + MRDS 4 / NI LabVIEW), there are practically no training articles, mainly the native programming environment is used, and everything in it is trivial. Anyone who is interested in robotics, programming and who has a set of NXT (and there are not enough of them), any age audience.

Graphic programming languages ​​are evil, and those who program heretics on them! Graphic programming languages ​​that are MRDS 4 and NI LabVIEW undoubtedly have their drawbacks, for example, focusing on narrow tasks, but still in functionality they are not much inferior to text languages, especially since NI LabVIEW was originally developed as an easy-to-learn language for solving scientific and engineering problems , for this, it contains many necessary libraries and tools. Therefore, these graphical languages ​​are the most suitable for solving our problems. And do not burn us for it at the stake to despise.

All this looks childish and not serious at all! When the task is to implement the algorithms, to teach the basics and principles of programming, robotics, real-time systems without deepening the circuitry and protocols, then this is a very suitable tool, though not cheap (regarding the NXT set). Although for the same purpose, Arduino-based kits will work well, but this controller has almost no compatibility with MRDS 4 and NI LabVIEW, and these platforms have their charms.

The technologies that are used are the product of decaying capitalist countries, and the author is an enemy of the people and an accomplice of Western conspirators! Unfortunately, the majority of technologies in the field of electronics and computing equipment come from the west, I will be very happy if they point out to me similar technologies of native domestic production. In the meantime, we will use what we have. And you do not need to tell me for it to the special services to keep evil.

Overview of the MRDS 4 and NI LabVIEW platforms.


I will bring some clarity to the terminology. Under the platform, in this case, there is a set of different tools, such as the VPL language in the MRDS, as well as the application execution environment, i.e. There is no direct compilation of applications into executable (* .exe) files.

In 2006, Microsoft announced the creation of the Microsoft Robotics Developer Studio platform (for more information on the Wikipedia article ). MRDS is a Windows-based application development environment for robotics and simulation. Currently relevant is the version of Microsoft Robotics Developer Studio 4. Among the features: graphical programming language VPL, Web - and Windows - oriented interfaces, VSE simulation environment, simplified access to sensors, microcontroller and robot actuators, support for C # programming language, libraries for multi-threaded programming and distributed execution of CCR and DSS applications, support for many robotic platforms (Eddie, Boe-Bot, CoroBot, iRobot, LEGO NXT, etc.).

LabVIEW (Laboratory Virtual Instrumentation Engineering Workbench) is a development environment and platform for executing programs created in the National Instruments graphical programming language G (more details in the Wikipedia article ). LabVIEW is used in data acquisition and processing systems, as well as for managing technical objects and technological processes. Ideologically, LabVIEW is very close to SCADA systems, but unlike them, it is more focused on solving problems not so much in the field of automated process control systems (automated process control systems), as in the field of automated technical data sources (automated research systems). The graphical programming language “G” used in LabVIEW is based on the data flow architecture. The sequence of operators in such languages ​​is not determined by their order (as in imperative programming languages), but by the availability of data at the inputs of these operators. Operators not related to data are executed in parallel in random order. The LabVIEW program is called and is a virtual instrument (English Virtual Instrument) and consists of two parts:

LEGO NXT Mindstorms 2.0 kit overview.


The NXT kit consists of a control unit, four sensors and three servos. The control unit contains:

Sensors (different sets of sensors in different configurations):



Figure 1 - NXT microcomputer with connected sensors and actuators

And of course, the set contains various LEGO parts in the LEGO Technic form factor from which the actuators and the supporting structure will be assembled.


Figure 2 - Details in the form factor LEGO Technic

We write the first application.


Write the first application. Let, classically, this application displays the text “Hello, World!”. The implementation will take place alternately in MRDS 4 and NI LabVIEW, in the process we will consider the specifics of each platform.

Pre-install the MRDS 4 and NI LabVIEW platforms, in the case of the MRDS 4, the installation must be done in a folder that does not consist of Cyrillic (Russian letters), the user account must also consist of only Latin letters .

1. MRDS platform 4.

Run the VPL environment (Start Menu - All Programs - Microsoft Robotics Developer Studio 4 - Visual Programming Language). This environment allows you to develop applications in the VPL language, to conduct testing in a virtual environment VSE. A program in a VPL is a diagram consisting of interconnected blocks. In the window that opens, in addition to the standard command bar and menu, there are 5 main windows:

  1. Basic Activities - contains basic blocks that implement such operators as a constant, variable, condition, etc .;
  2. Services - contains blocks that provide access to the functionality of the MRDS platform, for example, blocks for interacting with any hardware component of the robot, or blocks for calling a dialog box;
  3. Project - combines diagrams included in the project, as well as various configuration files;
  4. Properties - contains the properties of the selected block;
  5. Diagrams window - contains, directly, a diagram (source code) of the application.




Figure 3 - VPL programming environment

Perform the following sequence of actions:

  1. add the Data blocks (from the Basic Activities window) and the Simple Dialog service block (from the Services window),
  2. in the Data block, enter “Hello, World!” (without quotes) and select the String data type,
  3. connect the Data block with the Simple Dialog block, a dialog box appears,
  4. further, we perform everything as in the pictures



  5. Figure 4 - Connections Window



  6. Figure 5 - Data Connections window



  7. Figure 6 - The finished form of the diagram

  8. Run the program for execution.



    Figure 7 - The result of the program


2. NI LabVIEW Platform.

On this platform, everything is implemented, almost identical. Run the LabVIEW environment. Two windows appear before us, the first is the Front Panel, designed to implement the user interface (the appearance of the virtual instrument), the second is the Block Diagram, to implement the program logic.


Figure 8 - LabVIEW environment windows

We will use the Block Diagram window. Perform the following steps:

  1. in the Block Diagram window, open the context menu by right-clicking,
  2. in the window that appears, go through the tabs, as in the picture and select String Constant,



    Figure 9 - Context Menu

  3. place this block and enter “Hello, World!”,
  4. Similarly, select the One Button Dialog box,



    Figure 10 - One Button Dialog Block

  5. connect the blocks as shown in the picture,



    Figure 11 - Finished Chart

  6. run the program by clicking the button in the form of a horizontal arrow on the taskbar,



    Figure 12 - The result of the program


Summary



In the following articles we will deal directly with programming the NXT. There are a lot of training materials on the LabVIEW environment on the network, much less on the VPL. I highly recommend to study the reference manual of both platforms (knowledge of English is necessary), in these manuals there are a lot of examples that can be implemented without having NXT, as well as the following books:

In my articles I will describe only my projects, since I see no reason to rewrite information from one source to another. I will accept any constructive criticism, I will answer any questions regarding the platforms considered. Thank you in advance!

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


All Articles