Three troubleshooting tips for NXT-G

Troubleshooting NXT-G programs can be a little challenging. There aren’t any traditional debugging tools built into the environment. Here are three ways you can emulate common troubleshooting techniques when your program isn’t working the way you expected.

  1. Watch variables – You probably know you can monitor a sensor in the bottom left corner of the screen. If you keep the NXT connected to the computer, you’ll see the value of the highlighted sensor block in real time. But what if you can’t keep the robot tethered or you’re trying to monitor another value? Put it on screen! Use the Number To Text Block to send data to input B of the Text Block. Use A to name the variable and C to pad the output with blank spaces. Send each value to a different line using the Display Block. If you drop this all into a MyBlock, you’ll have a simple routine to watch a variable without cluttering up your program.
  2. Set breakpoints – Breakpoints are really useful because they halt the program at a certain spot so you can inspect the state of your robot. When I’m trying to isolate a program bug, I use the Stop Block and just move it down the line to test each step of the program. This works great when you’re trying to navigate and aren’t sure why your robot is going off course.
  3. Set alerts – If I’m not sure which branch my program is using in a switch, I’ll add audio cues to my program for each branch. For instance, I wrote a program to read color codes and perform different actions depending on which color it identified using the color sensor. To confirm the color sensor was seeing the colors accurately, I made each value in my switch say the color name out loud.

NXT-G Debugging
Use these methods alone or together to quickly get to the root when your programs are misbehaving. You’ll save a lot of guesswork by using these three simple techniques to pinpoint problems and isolate failures.

The following two tabs change content below.
Bill Shaw has been an entrepreneur for over 20 years. He currently provides after school and summer robotics programs for kids. He loves building robots, dabbling in electronics and playing badly on the guitar.

Latest posts by Bill Shaw (see all)