You are on page 1of 18

ROBOTC PROGRAMMING

4. NXTBrick and Display

d-r.Ramona Markoska, assist.prof


TEMPUS IV Project: 158644 -JPCR Development of Regional Interdisciplinary Mechatronic Studies DRIMS

ROBOTC PROGRAMMING

Topic of discusion in this chapter


NXT Brick- Overview LCD Display NXT Functions for Display Formatted output RobotC examples for NXT Display

TEMPUS IV Project: 158644 -JPCR Development of Regional Interdisciplinary Mechatronic Studies DRIMS

ROBOTC PROGRAMMING

4.1. NXT brick

TEMPUS IV Project: 158644 -JPCR Development of Regional Interdisciplinary Mechatronic Studies DRIMS

ROBOTC PROGRAMMING

4.1.1.LCD Display

TEMPUS IV Project: 158644 -JPCR Development of Regional Interdisciplinary Mechatronic Studies DRIMS

ROBOTC PROGRAMMING

4.1.1. LCD Display


100 pixels wide and 64 pixels high,monochrome, 2 States for each pixel: on, off. The bottom left corner is point (0, 0) and the top right corner of the display is point (99, 63). There are eight text lines numbers 0 to 7. 0 is the top line and 7 is the bottom line of the display

TEMPUS IV Project: 158644 -JPCR Development of Regional Interdisciplinary Mechatronic Studies DRIMS

ROBOTC PROGRAMMING

4.2. NXT Functions for Display (1)


ROBOTC has a rich set of functionality for drawing text and shapes on the LCD screen

Function
eraseDisplay(); nxtClearPixel(); nxtDisplayClearTextLine();

Semantic
Erases the complete NXT LCD display, or Clears a single pixel on the NXT LCD screen. Erases a line of text. 'nLineNum' specifies one of the 8 possible text lines
Formats a text string and displays it at any (X,Y) coordinate on the LCD display. Drawing uses a large font that is 16-pixels high. 'sFormatString' is the format string to use and 'parm1' and 'parm2' are two optional parameters that can be used within the format string. Draws outline of the circle with the specified coordinates Draws outline of the ellipse with the specified coordinates. Draws a line between two points.

Syntax
eraseDisplay(); or nxtClearPixel(xPos, yPos); nxtDisplayClearTextLine(nLineNum);

nxtDisplayBigStringAt(xPos, yPos, sFormatString, parm1, parm2);

int printMe=1; int printMeToo=2; nxtDisplayBigStringAt( 15, 15, %d, %d, printMe, printMeToo);

nxtDrawCircle(Left, Top, Diameter); nxtDrawEllipse(Left, Top, Right, Bottom); nxtDrawLine(xPos, yPos, xPosTo, yPosTo);

nxtDrawCircle(10, 20, 18); nxtDrawEllipse(10, 20, 56, 25);

nxtDrawLine(20, 50, 60, 25); ( Draw line betweeb A(20,50) and B(60,25)

TEMPUS IV Project: 158644 -JPCR Development of Regional Interdisciplinary Mechatronic Studies DRIMS

ROBOTC PROGRAMMING

4.2. NXT Functions for Display (2)


ROBOTC has a rich set of functionality for drawing text and shapes on the LCD screen

Function
nxtDrawRect(Left, Top, Right, Bottom);

Semantic
Draws outline of the rectangle with the specified coordinates. Erase something between gived borders or points. Solid Fill something between gived borders or points Inverts the pixels for the given line Shift the LCD image up one line.

Syntax
nxtDrawRect(10, 50, 60, 25);

nxtEraseEllipse(), nxtEraseLine(), nxtEraseRect(), nxtFillEllipse(), nxtFillLine(), nxtFillRect(), nxtInvertLine(xPos, yPos, xPosTo, yPosTo); nxtScrollText(sFormatString, parm1, parm2);

for(i=0; i<1000; ++i) { nxtScrollText("Scroll #%d.", i); wait1Msec(250); } bNxtLCDStatusDisplay = true; (The NXT top status line WILL display on user-drawn LCD screens.)

bNxtLCDStatusDisplay

Boolean variable that indicates whether the top status line display on the LCD should be present on user-drawn LCD screens.

TEMPUS IV Project: 158644 -JPCR Development of Regional Interdisciplinary Mechatronic Studies DRIMS

ROBOTC PROGRAMMING

4.2.1. NXT Display -formatted output used in presented functions

TEMPUS IV Project: 158644 -JPCR Development of Regional Interdisciplinary Mechatronic Studies DRIMS

ROBOTC PROGRAMMING

4.2.2. Display examples using strings, unformatted output and loops


Code-Syntax Semantic
Create the string named s1, "TempusDRIMS". Display the string, 's1' on line 2. Wait 50 milliseconds (helps refresh rate of LCD screen Display the string, Mechatronics' at position (x=4, y=5). Wait 50 milliseconds (helps refresh rate of LCD screen).

TEMPUS IV Project: 158644 -JPCR Development of Regional Interdisciplinary Mechatronic Studies DRIMS

For Loop from 0 to 12 incrementing 'i' by 1 each time: Display "Scroll #i." (%d is replaced with variable 'i' at runtime.) Wait 200 milliseconds between each iteration of the For Loop.

ROBOTC PROGRAMMING

***

More display commands are available in the RobotC On-line Support on the left side-bar under the NXT Functions->Display section.

TEMPUS IV Project: 158644 -JPCR Development of Regional Interdisciplinary Mechatronic Studies DRIMS

ROBOTC PROGRAMMING

4.3. NXT Brick Programming Examples


4.3.1. NXT Display simple use- real LEGO robot
.. Description: Displays the words "Hello World !" on the NXT display for 9 seconds

and exits.(introduction to the details of writing, saving, compiling, and running a program) Main function ( first section of instructions
Program windows: to be executed)

({, }) enclose a block of instructions.


3

first instruction is a call to the function nxtDisplayString()

first argument, 3, species the line on which to place the words after.

TEMPUS IV Project: 158644 -JPCR Development of Regional Interdisciplinary Mechatronic Studies DRIMS

second instruction is a call to the wait1Msec() Argument - (1 millisecond = 1/1000th of a second) specied in its function. argument before proceeding to the next instruction in this case 9,000 milliseconds (or 9 seconds) ROBOTC PROGRAMMING before proceeding.

. 4.3.1.Code Execution:
1.Compile

2.Save

TEMPUS IV Project: 158644 -JPCR Development of Regional Interdisciplinary Mechatronic Studies DRIMS

ROBOTC PROGRAMMING

. 4.3.1.Code Execution: Turn on the NXT brick and connect it to the USB port of the
computer. Under the main menu, choose Robot-> Compile and Download Program.

On the NXT Display go to My Files->Software Files-> HelloWorld ! HelloWorld Run.


TEMPUS IV Project: 158644 -JPCR Development of Regional Interdisciplinary Mechatronic Studies DRIMS

ROBOTC PROGRAMMING

4.3.2. NXT Display- text: RobotC t.m and Tempus DRIMS


..Descritpion:
ROBOTC has funciton to draw text on the NXT LCD display. This function is used in this example to display in big 16 pixe l font strings Tempus and DRIMS. ( Text RobotC t.m. is presented using standard 8 pixel font). . Note that ..!

1 is a line number on NXT display

(20,36) and (20,20) are (X,Y) pixel coordinates on NXT Display. (Y2-Y1=36-20= 16 pixel font)
TEMPUS IV Project: 158644 -JPCR Development of Regional Interdisciplinary Mechatronic Studies DRIMS

ROBOTC PROGRAMMING

. Code 4.3.2.

This example is tested using Compiler Target, Virtual Worlds.. This example is tested using Compiler Target, Virtual Worlds. It is not recommended after option Compile Program, to use Lego Virtual Worlds Table. That's because all programming activity can be presented on NXT Brick Display. For that purpose, it is necessary to use Debugger Windows menu and NXT Remote Screen, where results wil be presented. On next page, on the footer of picture, a compiler window is presented. This is the place where are posted messages in case of some errors in process of debugging .
ROBOTC PROGRAMMING

TEMPUS IV Project: 158644 -JPCR Development of Regional Interdisciplinary Mechatronic Studies DRIMS

4.3.2. NXT Display- text: RobotC t.m and Tempus DRIMS

TEMPUS IV Project: 158644 -JPCR Development of Regional Interdisciplinary Mechatronic Studies DRIMS

.Notice the difference !!! and comment it !

ROBOTC PROGRAMMING

Discusion, Questions ?
Use of LCD Display ? How important is it ? NXT Brick functions ? Compiler target and Remote Screen functionality ?

TEMPUS IV Project: 158644 -JPCR Development of Regional Interdisciplinary Mechatronic Studies DRIMS

ROBOTC PROGRAMMING

References
www.robotc.net http://www.doc.ic.ac.uk/~ajd/Robotics/RoboticsResources/ http://greenarmyrobotics.org/robotc/introduction-to-the-robotcdebugger Albert W. Schueller (2011), Programming with Robots, Whitman College http://www2.cs.siu.edu/~hexmoor/classes/CS404-S10/Wahl.pdf http://reference.kfupm.edu.sa/content/r/probot_programming_environ ments_52469.pdf

TEMPUS IV Project: 158644 -JPCR Development of Regional Interdisciplinary Mechatronic Studies DRIMS

ROBOTC PROGRAMMING

You might also like