Program stops without explanation

This is where you talk about the NXJ software itself, installation issues, and programming talk.

Moderators: 99jonathan, roger, imaqine

Program stops without explanation

Postby paulreiners » Mon Oct 08, 2007 1:45 pm

I'm having a problem with a maze-solving robot program I'm writing. First, I had the program so that it hugged a straight left wall (without any passages to the left) using an UltrasonicSensor and that more or less worked okay. Then I added code so that, when there is a passage to the left, the robot makes a 90-degree left-turn.

Now, when I run the program, it will stop after a short while and just show the leJOS J icon on the screen. I'm not sure what is causing this problem. Any help anyone can give me would be appreciated.

Below is the code. Note that I actually commented out the code to do the left turn, hoping that might help, but it didn't.

Code: Select all
import lejos.navigation.Pilot;
import lejos.nxt.Button;
import lejos.nxt.Motor;
import lejos.nxt.SensorPort;
import lejos.nxt.Sound;
import lejos.nxt.UltrasonicSensor;

 * @author Paul Reiners
public class WallFollower {
   private static final int LEFT_TURN = -2;
   private static final float WHEEL_DIAM = 5.6F;
   private static final float TRACK_W = 13F;
   private static final int WALL_HUGGING_CORRECTION_ANGLE = 2;
   private static final int WALL_HUGGING_MIN = 9;
   private static final int WALL_HUGGING_MAX = 11;
   private UltrasonicSensor us = new UltrasonicSensor(SensorPort.S1);
   private Pilot sc = new Pilot(WHEEL_DIAM, TRACK_W, Motor.C, Motor.B);

    * @param args
    * @throws InterruptedException
   public static void main(String[] args) throws InterruptedException {
      WallFollower wallFollower = new WallFollower();

   public void runMaze() {
      sc.setSpeed(700); // Movement speed

      while (!Button.ESCAPE.isPressed()) {
         int distance = us.getDistance();
         if (distance < WALL_HUGGING_MIN) {
            int adjustAngle = -WALL_HUGGING_CORRECTION_ANGLE;
         } else if (distance > 2 * WALL_HUGGING_MAX) {
            // Passage to left.  Turn left.
            // adjustDirection(LEFT_TURN);
         } else if (distance > WALL_HUGGING_MAX) {
            int adjustAngle = WALL_HUGGING_CORRECTION_ANGLE;
         try {
         } catch (InterruptedException e) {
            // Keep going.

   private void adjustDirection(int adjustAngle) {
      if (adjustAngle > 0) {;
      } else if (adjustAngle == LEFT_TURN) {
      } else {
New User
Posts: 8
Joined: Sun Oct 07, 2007 12:20 am
Location: Minnesota

Postby lawrie » Fri Oct 12, 2007 7:41 pm

If the leJOS J Icon shows again the firmware must have crashed. One possible reason is your flash memory is full and not all the program has uploaded. Try deleing any unused programs and run Defrag from System menu. Usually in the firmware crashes you get a Data Abort.
leJOS Team Member
Posts: 840
Joined: Mon Feb 05, 2007 1:27 pm

Postby gloomyandy » Sat Oct 13, 2007 7:29 pm

You may also want to check the batteries if seen this happen when the nxt goes into a "brown out"...

User avatar
leJOS Team Member
Posts: 3642
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Return to NXJ Software

Who is online

Users browsing this forum: No registered users and 1 guest

more stuff