Code from Sublime Text 2 (like NP++) not working in Eclipse

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

Moderators: 99jonathan, roger, imaqine

Code from Sublime Text 2 (like NP++) not working in Eclipse

Postby abcde13 » Mon Jul 09, 2012 9:33 pm

So, I had the behavior programming in the code below working great in Sublime Text 2 which is like NotePad++, with which I compiled, linked, and uploaded from the command prompt. However, I went ahead and download eclispe and set it all up because it, in general is much more user friendly (though I don't have any problems command line wise). In doing so, I wanted to recreated my project in eclipse, so I created a new Lejos NXT Project, and setup 3 classes: Scan, Stop, and SwarmFind (This is supposed to be for swarm robotics). When I downloaded and ran it, for some reason, it waited until something moved in front of the US sensor, then it ran displaying the distance, and once it got in front of something < 25 cm away, it stopped. The program didn't stop, its just, it doesn't move again when it has vision > 25 centimeters. It still displays the numbers, of course. I assume it is still in the stop behavior rather than the scan behavior, but it worked just fine in my Sublime Text 2, and now, from Eclipse it doesn't.

It supposed to: Run forward until find something, wait until it is moved, and repeat.

Here are the classes:

Code: Select all
package com.mydomain;

import lejos.nxt.*;
import lejos.robotics.subsumption.*;


//Behavior "Scan"
//Search for objects in vicinity. Stop when something is in sight.

public class Scan implements Behavior {

   /**
    * @param args
    */
   private UltrasonicSensor sonar = new UltrasonicSensor(SensorPort.S4);
   private boolean suppressed = false;

   public void suppress() {
      suppressed = true;
   }

   public boolean takeControl() {
      return (sonar.getDistance() > 25);
   }

   public void action() {
      suppressed = false;
      Motor.A.setSpeed(180);
      Motor.C.setSpeed(180);
      Motor.A.forward();
      Motor.C.forward();
      while(!suppressed) {
         Thread.yield();
         LCD.drawInt(sonar.getDistance(),3, 5, 3);
      }
      Motor.A.stop();
          Motor.C.stop();
    }

}


Code: Select all
package com.mydomain;

import lejos.nxt.*;
import lejos.robotics.subsumption.*;

//Stop behavior
//Just stops when it is 25 centimers/less away from object

public class Stop implements Behavior{
   private UltrasonicSensor sonar = new UltrasonicSensor(SensorPort.S4);
   private boolean suppressed = false;

   public void suppress() {
      suppressed = true;
   }

   public boolean takeControl() {
      return (sonar.getDistance() < 25);
   }

   public void action() {
      suppressed = false;
      Motor.A.stop();
          Motor.C.stop();
      while(!suppressed) {
         Thread.yield();
         LCD.drawInt(sonar.getDistance(),3, 5, 3);
      }
      Motor.A.stop();
          Motor.C.stop();
    }

}


Code: Select all
package com.mydomain;

import lejos.robotics.subsumption.*;


//SwarmFind
//Meant to cycle through behaviors to help swarm gather around desirable object.

public class SwarmFind {

   /**
    * @param args
    */
   public static void main(String[] args) {
      Behavior scanner = new Scan();
      Behavior stop = new Stop();
      Behavior[] behaviors = {scanner,stop};
      Arbitrator arby = new Arbitrator(behaviors);
      arby.start();

   }

}


Can anyone tell me if it's a coding issue, not understanding behaviors, or ide issue?
abcde13
New User
 
Posts: 7
Joined: Mon Jul 09, 2012 2:37 pm

Return to NXJ Software

Who is online

Users browsing this forum: No registered users and 3 guests

cron
more stuff