Page 1 of 1

Self Parking Car (SPC) with Wall Follower

Posted: Fri Nov 11, 2011 8:03 am
by telemarker
Hello everybody,
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);

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.


P.S.: Sorry for bad grammar and spelling mistakes

Re: Self Parking Car (SPC) with Wall Follower

Posted: Tue Dec 06, 2011 9:19 pm
by kvols
Supposing this is not simply a "please do my assignment for me", I'd like to know a little more about your thoughts about the design of your program and robot.

- How is your robot supposed to work - write some pseudo code, show a drawing...
- How do you plan control the threads to avoid two threads using the same device?
- Why are you using threads for these tasks - what are you trying to accomplish with parallel threads that is better than using sequential methods?

In general, threads are much more complicated to use for procedural tasks than, well, procedures: You need to do thread synchronization, and you need to protect common resources with semaphores. One of the main ideas with threads is actually to avoid polling, and use wait and notify to wait for events to occur without using CPU resources.

Re: Self Parking Car (SPC) with Wall Follower

Posted: Sun Dec 25, 2011 10:11 am
by telemarker
sry for my late answer.
I thought about my car and at the moment I the car is following a black line (lightsensor) and while it is following this line the ultrasonicsensor mesures the distance to the wall. If the distance changes (is bigger) the sensor should start to mesure the gap (the time the distance is bigger) then it decides if the gap is big enough to park or not. If it is big enough it stops and parks. While driving backwards the ultrasonicsensor is mesuring the distance to the back "car" until it is maybe 1". Then the sensor turns to the front direction is mesuring the distance to this car... and so on until the car parks right in the middle.

So far I think this variation is easier than the "Wallfollower".

I took Multithreads because I thought it has to be like this. (measuring the distance to the wall and searching for a gap at the same time)
Now I thing it is not neccassary anymore.
I just need one operation to follow the blackline and another operation to detect the gap. Maybe the behavior could be useful.

I hope you understand what I am thinking so far.

I defenetly don't want you to write my paper, I just would like to have some help if I am on the right way.

Merry Chrismas and a happy new year.