Skip to content
This repository has been archived by the owner on Sep 16, 2022. It is now read-only.
/ pso-car Public archive

A sandbox practice for the particle swarm optimization.

License

Notifications You must be signed in to change notification settings

seanwu1105/pso-car

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Car Control Simulator Based on Particle Swarm Optimization

Requirements Status

A sandbox practice for the particle swarm optimization.

preview

Objective

Use PSO to find the best the RBFN parameters, which input is the distances detected from car radar and output is the angle of wheel.

Objective Function

Minimize the err:

err = (1 / N) * sum(abs(d.expected_output - RBFN(d.input)) for d in training_dataset)

N is the total number of training data.

On the other word, we want to maximize the fitness value (1 / err ).

PSO Position and Velocity Update Formula

The position and velocity for each individual in population of PSO is updated by following formula.

  • Velocity
self.velocity = inertia_weight * self.velocity + \
    cognitive_const * (self.best_position - self.position) + \
    social_const * (global_best_position - self.position)

# limit the velocity
np.clip(self.velocity, -self.v_max, self.v_max, out=self.velocity)

self.position += self.velocity

# limit the position to fit the range of RBFN parameters
rbfn_params_limiter(self.position)

Installation

  • Download this project
git clone https://gitlab.com/seanwu1105/pso-car.git
  • Change directory to the root of the project
cd pso-car/
  • Run with Python interpreter
python3 main.py

Training Data Format

Input (Distances) Output (Wheel Angle)
22.0000000 8.4852814 8.4852814 -16.0709664
# Front_Distance Right_Distance Left_Distance Wheel_Angle

22.0000000 8.4852814 8.4852814 -16.0709664
21.1292288 9.3920089 7.7989045 -14.7971418
20.3973643 24.4555821 7.2000902 16.2304876
19.1995799 25.0357595 7.5129743 16.0825385
18.1744869 42.5622911 8.0705896 15.5075777

Add Customized Map Cases

The data location

The data location is /data. The application will load every files with *.txt extension automatically after the execution.

Example Format

0,0,90  // the starting position and angle of car (x, y, degree)
18,40   // the top-left coordinate of the ending area
30,37   // the bottom-right coordinate of the ending area
-6,-3   // the first point for the wall in map
-6,22
18,22
18,50
30,50
30,10
6,10
6,-6
-6,-3   // the last point for the wall in map

Every coordinates between the fourth and last line are the corner point of the walls in map.

Dependencies

pip3 install numpy
pip3 install matplotlib
pip3 install pyqt5
pip3 install pyside2

About

A sandbox practice for the particle swarm optimization.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages