Problems with the first steps of my project

Post your NXJ projects, project ideas, etc here!

Moderators: 99jonathan, roger, imaqine

Problems with the first steps of my project

Postby XTinX » Fri Aug 21, 2009 1:32 pm

Hi everyones,

here is the code of my project, I have a issue when I want to execute it on my nxt. The error is something like "Java exception : classe 8 Method 107 PC 5660"

What's wrong with my code ? I guess it's about the thread mecanism but I can't see where. Is there any way I can debugg that ?

EDIT: I've deleted some part of my code which were not important as the program still crash without specifying "run" routines

Main class

Code: Select all
import lejos.navigation.CompassPilot;
import lejos.nxt.*;
import lejos.nxt.addon.CompassSensor;
import lejos.nxt.addon.NXTCam;

public class RobotBrain extends ThreadRoboticist{
   

   protected static CollisionAvoid collisionThread;
   protected static Drive driveThread;

   

   /**
    * @param args
    */
   public static void main(String[] args) {
      // TODO Auto-generated method stub
      
      
      //////// PENSER A CHANGER L'ADRESSE DE LA CAMERA ///////
      

      //Initialisation des capteurs
      rightSensor= new UltrasonicSensor(SensorPort.S1);
      leftsSensor= new UltrasonicSensor(SensorPort.S3);
                frontSensor= new UltrasonicSensor(SensorPort.S2);
                compass= new CompassSensor(SensorPort.S4);
      
      //Intialisation des moteurs
      rightMotor = new Motor(MotorPort.A);
      leftMotor = new Motor(MotorPort.C);
      cameraMotor= new Motor(MotorPort.B);

      
      pilot = new CompassPilot(SensorPort.S4, WHEEL_DIAMETER, ROBOT_WIDTH, leftMotor, rightMotor);
   
       collisionThread= new CollisionAvoid();
       collisionThread.setDaemon(true);
       driveThread=new Drive();
       driveThread.setDaemon(true);

       collisionThread.start();
       driveThread.start();
      
      for(;;)
      {
         
         
         
         
      }

   }

}


Collision Avoidment class

Code: Select all
public class CollisionAvoid extends ThreadRoboticist {

   
   
   public class SensorRecords{
      
      public float rotation;
      public float front;
      
   }
   
   protected SensorRecords[] SensorRecordsTab;
   protected static final int RECORDS_NUMBER=1;
   protected int tabCounter=0;//permet de naviguer dans le tableau
   protected int maxFrontBreak = 50;//coef lie au freinage de l'avance du robot en cas d'obstacle devant le robot
   protected float rotationSum=0.0f;
   protected float frontSum=0.0f;
   protected int leftValue=0;
   protected int rightValue=0;
   protected int frontValue=0;


   
   
   public  CollisionAvoid(){
      

SensorRecordsTab= new SensorRecords[RECORDS_NUMBER];
      initSensorRecordsTab();
   }
   
   public void run(){
   }
   
   
}


Drive class
Code: Select all
public class Drive extends ThreadRoboticist {

   protected int leftSpeed;
   protected int rightSpeed;
   protected int rotationSens;
   protected float turnRate;
   protected int outSpeed;
   protected int inSpeed;
   
//ratio = 100 - abs(turnRate)//
/*turnRate If positive, the left wheel is on the inside of the turn. If negative, the left wheel is on the
outside.*/   
   public Drive(){
      

      
   }
   
   public void run(){
      
      for(;;){
      }
      
      

   }
   
}


And the inherited thread class for shared memory between threads
Code: Select all
import lejos.navigation.CompassPilot;
import lejos.nxt.Motor;
import lejos.nxt.UltrasonicSensor;
import lejos.nxt.addon.CompassSensor;
import lejos.nxt.addon.NXTCam;

public class ThreadRoboticist extends Thread {

   protected static UltrasonicSensor rightSensor;
   protected static UltrasonicSensor leftSensor;
   protected static UltrasonicSensor frontSensor;
   protected static NXTCam camera;
   protected static Motor rightMotor;
   protected static Motor leftMotor;
   protected static Motor cameraMotor;
   protected static CompassSensor compass;
   protected static int angleEye=0;

   protected static CompassPilot pilot;
   
   protected static float collisionRotation;
   protected static float collisionTranslation;

   public static final float WHEEL_DIAMETER=5.4f;
   public static final float ROBOT_WIDTH = 12.0f;
   public static final int MAX_ROTATION_SPEED=30;
   
}
Last edited by XTinX on Fri Aug 21, 2009 2:21 pm, edited 3 times in total.
XTinX
New User
 
Posts: 11
Joined: Thu Aug 20, 2009 2:29 pm

Postby gloomyandy » Fri Aug 21, 2009 1:54 pm

Hi,
Take a look at this thread...
http://lejos.sourceforge.net/forum/viewtopic.php?t=1215&highlight=exception

The exception you are getting is a null pointer exception. It seems to me that you are never giving rightSensor/leftSensor a value. Are you sure you really want to have local variables in your main method that have the same names as the ones in your "shared memory" class?

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

Postby XTinX » Fri Aug 21, 2009 2:03 pm

Hi andy,

Indeed, I didn't see that I redeclared the sensor variables. You've got the point. I've corrected it but it still crashes :(
XTinX
New User
 
Posts: 11
Joined: Thu Aug 20, 2009 2:29 pm

Postby gloomyandy » Fri Aug 21, 2009 2:05 pm

Also you seem to be doing the same thing with your SensorTab, you are creating an array and assigning it to a local variable but you don't ever initialize the "shared memory" variable of a similar name. But you are then using the shared memory version (in for instance initSensorRecordsTab). The warning messages that you are suppressing are there for a reason. Unless you are 100% sure that your code is correct it is probably best not to suppress them...

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

Postby XTinX » Fri Aug 21, 2009 2:24 pm

I'm daydreaming a little bit :) The program still crashes

It'so just so hard to monitor the execution of the program. I looked at the topic you asked me to but I can't figure out how to use this :

System.setErr(new PrintStream(RConsole.openOutputStream()));
XTinX
New User
 
Posts: 11
Joined: Thu Aug 20, 2009 2:29 pm

Postby gloomyandy » Fri Aug 21, 2009 3:21 pm

Hi,
If you want help you have to give us more information. What exactly have you done. What don't you understand? The line you quoted allows you to redirect the output from the error stream to the USB connection. When you do that you can use the nxjconsole command to display the output from calls to RConsole.println or System.err.println on your PC. You can then add trace functions to your code to work out what is going on. You can also add the -g option to the linker command to get a stack trace if your program crashes. You can use this along with the -v output from the linker to determine what exception is being thrown and which method the error is in.

So what have you done so far, do you have the linker output? What message are you getting on the NXT display?

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


Return to NXJ Projects

Who is online

Users browsing this forum: No registered users and 1 guest

more stuff