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;
}
