Loginskip to content

Archive for the 'development' Category

Debugging NXT-Programs

Saturday, May 1st, 2010

Sooner or later all users writing programs to be executed on the NXT brick find themselves in the following situation: Your program compiles fine, is transferred to the NXT, it starts running — but it doesn’t do what you want it to! Sometimes the mistake you made is obvious, but often it’s hard to spot the flaw. Well, now it’s time for debugging: the art of finding what went wrong, and especially where. Usually during debugging, you begin to understand how your program really works, and that is what helps you fix the problem. In this post, I’d like to give some general ideas and examples for debugging NXT programs.

Independent from the language you use (NXT-G, NXC, LeJOS or whatever), you have these options to get information from a running program back to you, the debugger:

  • The LCD display. This is obviously your first line of attack. Use the NXT’s display to show contents of variables, status messages, checkpoints, or anything you need. Often printing text is enough, but if you have more complex things or contents with greater volume, consider displaying graphics (pixels, graphs, symbols, etc.).
  • The speaker. Don’t underestimate the NXT’s capability to play sounds or tones. I call this “acoustic debugging”. Make the NXT play signal tones or sound files when certain conditions are met, procedures are executed or a special sensor value is detected.
  • Lights. Yes, that’s right. If you want to monitor a boolean value, maybe whether a certain task is running, you can use lights to show this information. There’s the red LED light of the classic NXT light sensor, the old LEGO lamps for motor ports (e.g. from the NXT Education Kit), or of course the LEDs of the new NXT 2.0 color sensor.
  • Motors. If you have no space left on the display and a free motor port, why not use a motor to help you visualize a variable? You can set the motor’s power to the variable if it’s confined to a range of -100 to 100. Some of the TryMe programs utilize this method (not for debugging purpose though).
  • Files. You can start generating log-files for later analysis. While this is a bit more effort initially to get yourself some helper-functions, you can re-use these routines later on in your other projects. This can be very powerful as you can include valuable information like timestamps or the calling procedure. You are however limited in available file size, and writing data to flash can sometimes take a fairly long time.
  • A computer. Once you have your PC connected to the NXT via Bluetooth or USB, you can retrieve valuable information from the brick. There are many methods of different complexity. BricxCC has a nice “Watching the brick” feature, there is an NXT debug monitor which can receive string messages from your programs via mailbox queues, or you can play around with direct commands yourself.

The main reason you should think of other ways than the display during debugging: There is limited space on the LCD, and there can be problems with updating speed. It can either influence your programs performance (and certain time critical bugs might magically disappear — a Heisenbug) or your eyes aren’t fast enough to identify a flashy change. While it’s easy to overlook a certain value / text for a split of a second, you’ll usually notice a beep! Apart from that: If your program crashes, text on the LCD display is lost, while messages stored in logfiles or sent to a computer will still be readable.
Having said all this, two things are important: Most of the time, you don’t need all the different ways at once. And it’s about the right combination of methods, which depend on your actual problem.

If you’re interested in more specific details and some examples for NXC, read on. (more…)

Weather forecasts on your NXT

Tuesday, June 16th, 2009

or communication between an NXT, a computer and the internet.

Quite some time ago I wanted to give a brief tutorial about communication between an embedded program running on the NXT (for example written in NXC) and a computer. The reasons one would want to send data from an NXC program to a PC or vice versa can be divided into two main categories: Either the NXC program wants the computer to do things it can’t (complex calculations, look up information), or a computer program needs to tell an NXC program what to do (or which information to collect or log).

Weather Demo Client Screenshot In the search for a good example I came across this idea: Wouldn’t it be great to show how the NXT could retrieve data from the internet (although the display is to small for a browser ;) )? The first kind of data I could think of were weather forecasts (or current weather conditions). So here we are: This is how it looks if your NXT can show the current temperature and brief conditions of any place around the world (screenshot taken with J. Hansen’s tool NXTScreen).

Short description: The NXC program (client) can request weather conditions by storing a string in one of its mailboxes. The computer program (server, written in MATLAB) constantly looks for messages there via direct commands. If one is found the according weather conditions will be retrieved from the internet using the Yahoo! Weather RSS service. The most important data are extracted and sent back to the NXT (again by storing a string in a mailbox). The NXC program in term waits until a string can be read from the queue, parses it and finally displays city name, current temperature, and condition.

Left and right buttons cycle through multiple locations (i.e. cities); the orange center button toggles between Fahrenheit and Celsius mode! Interested? Read on!

(more…)

Lego Pong with NXTCam

Friday, May 2nd, 2008

Here is an interesting robot from wayneage that plays Pong using a NXTCam camera to track a ball in real time. The NXTCam continuously sends the location (coordinates) of the ball to the NXT brick. The robot keeps adjusting its position to hit the ball when it is close enough. Before the robot starts, the NXTCam is taught the colours to track using another program called NXTCamView (this is not shown in the video). As you can see it works quite well - nice work!


NXT-compatible infrared/ultrasonic beacon system

Monday, March 17th, 2008

We brought our old RCX-beacon system to the NXT level. Please consult

http://www.convict.lu/htm/rob/ir_us.htm

 PC-boards

 

PF Speed control (and more) in NBC/NXC

Tuesday, February 12th, 2008

John Hansen published a test release of NBC/NXC with better interface to HiTecnic IRLink, allowing speed (PWM) contol of PF motors and other stuff.

Check it here:
http://bricxcc.sourceforge.net/

SCARA Robot

Sunday, December 2nd, 2007


Check out this YouTube video of a Lego SCARA robot arm by pishita69. SCARA stands for Selective Compliant Articulated Robot Arm. This type of design is often used in pick-and-place, assembly, and packaging applications. You can find out more about scara robots here. Nice work.

NXTCam Follower

Monday, November 19th, 2007


Check out NXTCam Follower by Mark R. It uses the new mindsensors NXTCam sensor to keep a ball at a set distance from the robot. Mark has posted his programs on the NXTCam Wiki. Nice work!

Comparison of Programming Environments for NXT

Tuesday, November 13th, 2007

The winter issue of Robot magazine contains a comparison of the various programming solutions for the NXT. It’s available online at http://www.botmag.com/articles/10-31-07_NXT.shtml. The comparison includes implementation of a simple line following program using the different programming languages including screenshots from the different environments. [Note: I wrote the article and also helped author ROBOTC].

Another NXT programming language discussion was justed posted on the Wired magazine web site at http://blog.wired.com/geekdad/2007/11/the-best-progra.html. Chris Anderson of Wired has been using his NXT to control his UAV — Unmanned Aerial Vehicle — and has tried many of the programming environments. For more on his airplane, see the videos at http://diydrones.com/video/video/show?id=705844:Video:43 

Conveying NXT state with spoken text

Thursday, August 23rd, 2007

When building NXT models, I like to get feedback on the state of the program or the state of sensors to make sure they are working as intended. The matrix display on the front of the NXT brick is great for some types of output and has some neat features.  These include - showing up to 7 lines of text, drawing shapes and images, and doing simple animations. Some projects have used this to great effect. However, it has its limitations. The display is not very big, so you can’t read it from across the room.  You need to be directly in front of it, so it can’t be covered or facing away.  And finally it only shows black or white pixels.

Your other options for outputing state include; the motors (a precious resource), the red led on the light sensor (only good for binary output), and the speaker. Of these, the speaker is the best suited to fill the gaps where the display is lacking.  It it quite loud, can be heard in any direction and can quicky convey different types of information.

Since the NXT can play sound files, we can use the speaker to play short spoken phrases.  I use these to provide feedback in my models.  So – where do get the spoken phrases from? One option is to record your own voice. For me, I prefer to use one of the text-to-speech web sites that convert written text into wave files you can download. I quite like the voices at the AT&T Text-to-Speech Demo site. You just follow these simple steps –

  1. Choose a voice (mens/womans/regional etc.)
  2. Enter the phrase to speak.  Keep it down to a couple of words.
  3. Download it to your PC

The downloaded phrase is in a wave file that needs to be converted to an RSO file format which the NXT can play. There’s a nifty program written by John Hansen called wav2rso which does this conversion for you.  It can convert a number of files at a time. You can set the quality of the conversion which effects the size of the file produced (higher frequency = better quality = larger files)

Now upload the RSO file into your NXT. You can do this with either; the standard NXT programming environment using the Memory Tab on the connection window, or one of the file managers in either RobotC or the BricxCC development environment.

Finally, you add code to your program to play the file at the appropriate time (e.g. when changing program state, or detecting an object). In NXT-G you use the Sound block to play the file. In RobotC you use the PlaySoundFile function. In either case, you specify the name of the sound file to be played.
And that’s it! With a few simple steps your model is speaking!

Here are some examples of my projects that have speech in them - OneMotorNXT, NXTShot

Coding4Fun: MS Robotics Studio

Tuesday, July 24th, 2007

Last week, Coding4Fun posted an article/tutorial on using MS Robotics Studio with the LEGO Mindstorms NXT.

In this article, Brian Peek will demonstrate how to use Microsoft Robotics Studio to control the Lego Mindstorms NXT kit. A simple remote-controlled robot will be built and controlled using C# and the MSRS Visual Programming Language (VPL).

leJOS NXJ version 0.3 released!

Wednesday, July 18th, 2007

As you all know, there are allready several programming alternatives for the NXT. These include, for example, NXT-G, RobotC, NXC etc. One other option is leJOS, a Java object-oriented language built on top on TinyVM. As you can read in the following email I got from Brian Bagnall, one of leJOS developers, this new release starts taking shape into a mature firmware alternative for the LEGO and RobotC firmwares:

The latest version of leJOS NXJ is finally ready! For those who aren’t familiar with leJOS, it’s a full replacement firmware for the LEGO Mindstorms NXT brick that allows you to run Java programs on the NXT brick. leJOS NXJ works with Windows, Linux and Mac OS X (a dedicated Mac build is coming soon). Version 0.3 now includes some key features:

- A flash file system including implementations of java.io.File,
FileInputStream, and FileOutputStream.
- CompassPilot and CompassNavigator
- A menu system that supports executing and deleting programs, and LCP commands with NXJ extensions over USB and Bluetooth
- Java streams over Bluetooth and USB
- USB support
- Flash native methods
- Working flash build of leJOS NXJ
- Improved LCP support (LEGO Communication Protocol) including file commands
- Improved Bluetooth support including setting the NXT name
- A file explorer that runs on your PC
And much more…

Check out www.lejos.org for more information.

I hope these guys release some tutorials soon, since understanding how to use leJOS from the examples source and the API is somewhat challenging….

Microsoft Robotics Studio 1.5 (CTP May 2007)

Wednesday, May 2nd, 2007

A new (Community Technical Preview) version of Microsoft Robotics Studio was released from microsoft. A short description from the website:

“The Microsoft® Robotics Studio is a Windows-based environment for academic, hobbyist and commercial developers to easily create robotics applications across a wide variety of hardware. This installation package installs the Microsoft Robotics Studio along with samples and tutorials.”

You can download it here.

URBI for Mindstorms NXT

Saturday, March 17th, 2007

A new programming language for NXT was released - URBI. You can find the download, documentation and toturials at http://www.gostai.com/lego.html.