## Automatic-Parking

Automatic parallel parking system including path planning, path tracking, and parallel parking in a designed environment written in python.

This repository contains an automatic parallel parking system including path planning, path tracking, and parallel parking in a designed environment written in python.
The agent, which is the car, navigates its route through the environment and is directed to the assigned park location by the MPC controller.

## Inference

run the code using this command:

``````\$ python main_autopark.py --x_start 0 --y_start 90 --phi_start 0 --parking 7
``````

you can choose the parking spot from 1 to 24:

## Envroinment

Our first step to develop an auto park system was to design and develop an environment capable of giving visual render using `OpenCV` library.
Environment is implemented in `environment.py` as a class and recieves obstacles at the beginning `env = Environment(obs)`.
Agent can be placed using `env.render(x,y,angle)`.
A sample of environment is displayed bellow.

## Path Planning

#### A* Algorithm

The agent will find a path from start to its goal using A*.
This implementation of A* from PythonRobotics, considers parameters like obstacles and robot radius.

#### Interpolating Path With B-spline

After finding a path in a descrete 100*100 space, the path is smoothed and scaled to 1000*1000 space of environment using b-spline.
The result is a set of points to guide our agent!

## Path Tracking

Kinematic model of the car, is:

``````x = vcos(ϕ)
y = vsin(ϕ)
v = a
ϕ = vtan(δ)/L
``````

State vector is:

``````z=[x,y,v,ϕ]
``````

x: x-position, y: y-position, v: velocity, φ: yaw angle

Input vector is:

``````u=[a,δ]
``````

a: accellation, δ: steering angle

The MPC controller controls vehicle speed and steering based on the model and car is directed through the path.

## Parallel Parking

This part consists of 4 rules that agent must choose one according to parking position.
At first the agent will find a path to park position then it will compute the arriving angle.
Based on the arriving angle, agent chooses a coordinate as ensure1.
After that, parking path is planned from ensure1 to ensure2 using 2 circle equations as mentioned below.
MPC controls the agent and car parks in ensure2 coordinate.

## GitHub

https://github.com/Pandas-Team/Automatic-Parking