my name is Tobi and I am new here. I have some Java expiriences and also some Lejos expiriences.
I have some project for my university to build and program a robot. I decided to build a self parking car which uses an ultrasonicsensor to follow a wall and detect some possible parking slots. The sensor is used to detect the current distance to the front/back car while parking (the sensor is moved by a motor).
Now my first questions:
At the moment I use multithreads (WallFollow, ParkingSpaceDetection, SPC(starts the threads) and one DataExchange) I am not sure if it would be better to use the behavior interface? Do you have some advice?
My wall follower code is:
- Code: Select all
import lejos.nxt.*;
import lejos.robotics.navigation.DifferentialPilot;
public class WallFollower extends Thread {
private DataExchange DEOpj;
private UltrasonicSensor us;
private final int minDist = 30;
DifferentialPilot pilot = new DifferentialPilot(-2.25f, -5.5f, Motor.C, Motor.B);
public WallFollower (DataExchange DE){
DEOpj = DE;
us = new UltrasonicSensor (SensorPort.S3);
}
public void run() {
while (true) {
if(DEOpj.getCMD() == 1) {
if(us.getDistance()> minDist){
pilot.arc(10, 20);
}else{
pilot.arc(-10,-20);
}
}else{
pilot.stop();
}
}
}
}
Do you think it is good so far? I am not really satisfied because the robot is not really precise but unfortunately I don't really know how to improve this.
Thank you very much for your help.
Tobi
P.S.: Sorry for bad grammar and spelling mistakes
