Вы находитесь на странице: 1из 4

Fakultt fr Physik und Geowissenschaften

Physikalisches Grundpraktikum

M20e Robot Programming (NXT)

Tasks
0. During preparation time derive the equations for the variables not given in Figs. 4 and 5, but
necessary for the programming in task 2.

1. Write a program to a) let the NXT drive in a straight line and stop in front of a
barrier;
b) generate random numbers x, y and the product xy with
the NXT and display these on the LCD-display;
c) let the NXT move in a sine-curve.

2. Complete the cloze source-code to let the NXT do a parking maneuver.

Additional task: Program (a) a dancing robot, (b) a robot that always moves forward and tries to
avoid obstacles or (c) design a program using your own ideas.

Literature

If interested, download a LabVIEW manual and a LabVIEW demo version and have a try yourself.

Accesories

LEGO NXT, PC with the software LabVIEW for LEGO MINDSTORMS 2010

Keywords for preparation

- Variable types in programming languages (integer, boolean, ...)


- Logical functions (and, or, ...)
- Loops and other control structures in programming languages (if, if ... then, if ... then ... else,
goto, for, while, ...)
- LabVIEW

1
General

In experimental physics one often encounters the necessity to collect data electronically and to
automate the control of experiments. In the field of robotics that is loosely related to mechanics
complex motion patterns are automated. A basic knowledge of programming and the properties of
computer interfaces should belong to the tool box of experimental physicists. This experiment should
allow for a first experience with programming of motion sequences. To this end a Lego NXT-module
is used that has undergone a firmware update to enable writing of complex motion-sequence scripts
in LabVIEW.
The Lego NXT is a microcontroller activated robot construction-kit. This incorporates three stepping
motors, two touch-sensors (switches), one RGB-colour-sensor as well as an ultrasound-sensor. The
setup used in the Undergraduate Physics Lab (see Fig. 1) is a single-axle vehicle-robot driven by two
wheels and balanced by a back wheel. The central control unit contains a LCD-display, an USB-
interface as well as three outputs and four inputs.

Fig. 1 NXT Tribot


1 Outputs A, B, C
2 USB-interface
3 NXT module with LCD display and
operating controls
4 Ultrasound sensor
5 Touch sensor
6 RGB colour-sensor
7 Stepping motor
8 Inputs 1, 2, 3, 4

LabVIEW (Laboratory Virtual Instrument Engineering Workbench)

LabVIEW is a visual programming environment that allows for the efficient construction of complex
programs, e.g. for instrument control and data acquisition. Due to a large variety of precompiled
modules and functions as well as due to the intelligent interface management, LabVIEW is simplifying
the work of the programmer considerably.
The environment of a VI (Virtual Instrument) in LabVIEW consists of two parts, namely the so-called
front panel and the corresponding block diagram. On the front panel the program interface with
inputs and outputs is constructed, in the block diagram the program to be executed is set up by
graphical programming.
For a graphic explanation the simple program in Fig. 2 is used. On the front panel the input objects A,
B, OK and Stopp as well as the output object C are arranged. In the block diagram the input and
output elements are mapped onto variables (terminals). For the program these input terminals act as
data sources (data are read) and the output terminal as a data sink (data are shown or exported).
Data types are marked, as seen in the block diagram, by different colours. The type Boolean is
represented in green ( ), the type Integer in blue ( ), the type Double in orange ( ) and the
type String in pink ( ). These standard data types do not only vary in the kind of data, but also in
their length in bits. The numeric formats Integer and Double are further differentiated in LabVIEW.
Arrays of a data type are shown by thicker wires (e.g. 1D-Array Double).

2
Fig. 2 Front panel and
block diagram in
LabVIEW

In order to perform operations on data, these are combined in a so-called node (e.g. ). These
nodes are used for data processing. Data have to be send to a node and after processing the node
reports values back according to the function it realizes. Also VIs (Sub-VIs) might serve as nodes. This
has the obvious advantage that the programs might be modularized into a main sequence and Sub-
VIs for clarity and simplicity. In order to equip a self-programmed VI with data inputs and outputs,
the input and output objects on the front panel have to be connected with the connectors of the VI.
The selection panel for the choice of the connectors appears on right-clicking the VI symbol.
Similar to other programming languages LabVIEW offers various structures for the control of the
program sequence. Table 1 shows basic structure types.
Case structure: dependent on the input variable a certain case is executed
(comparable to if()-elseif()-else in text based programming languages.
For loop: is repeated as often as specified by the input N. The connector i
returns the value of the iteration counter (0 to N-1).
While loop: performs the loop either (a) until the loop condition is true or (b) as
a) b) long as the loop condition is true. The while loop is executed at least once,
before the loop condition is examined (comparable to the do{} while() loop in
text based programming languages).
Formula node: executes equations or comparisons. Does not directly serve for
controlling the program sequence, but helps for a clearer structuring of the
program, since in case of complex calculations many wire nodes are replaced.
Table. 1 A selection of program structures from LabVIEW

In order to move data within a loop from one iteration to the next, shift registers ( ) are used.
For the conversion of a loop output into a shift register this option has to be chosen after right
clicking the output. In our example the value calculated last is stored in C, when OK = False (Fig. 3).

Fig. 3 Representation of a block diagram for OK = False

By local variables ( C read, C write) the values of an object can be called and modified within a VI.
For all functions in LabVIEW there is a short description under Help show context help. When
starting to program in LabVIEW this help menu should be extensively used.

3
Hints to task 0

Fig. 4 Schematics of the path of task 2.


Brown: parking space
Black: path of the wheels of the NXT
Blue: path of the center of the axle
Given: , sy, a

Fig. 5 Drive wheel of the NXT


Given: , d

Hints to task 1

The necessary VIs to control and read the inputs and outputs of the NXT are located in the function
menu NXT Robotics NXT I/O.
On approach of an obstacle the ultrasound sensor is providing distance information, such that the
point may be determined at which the robot stops.
Random numbers should be displayed on the display in various rows. Experienced programmers
might as well chose the form x*y = z in one row.
To drive along a sine curve the power of the motors has to be modulated according to P=P0+xsin(t),
where P0 = 50% and the modulation amplitude is x = 10%. The necessary step width of t should be
generated within a loop.

Hints to task 2

The cloze source-code is handed out and discussed at the beginning of the laboratory session.
The aim of this task is to have the NXT drive into a parking space (Fig. 2). At first the NXT should drive
forward in a straight line until reaching a reflective mark. This is located such that the axle of the NXT
is at the front end of the parking space. Consecutively the NXT should turn by 45, move forward into
the parking space and subsequently turn in the other direction.
At the end of the parking maneuver the NXT should move 2-5 cm towards the back wall of the
parking space.

Additional

In the additional task you might write your own complete program. First you should make a list with
the tasks the NXT should accomplish.

Вам также может понравиться