Calculus Report
Calculus Report
UNIVERSITY OF SCIENCE
ASSIGNMENT REPORT
Contents
List of Figures .......................................................................................................................3
1 Introduction ................................................................................................................... 4
  1.1 Motivation and Purpose ........................................................................................... 4
  1.2 Goal ............................................................................................................................. 4
4 Methodology ..................................................................................................................12
  4.1 Path Planning Algorithm ....................................................................................... 12
      4.1.1 Bezier to Chromosome Encoding Strategy............................................... 12
      4.1.2 Danger Map Generation ............................................................................ 13
      4.1.3 Initialize Population ................................................................................... 14
      4.1.4 Fitness Function ......................................................................................... 14
      4.1.5 Crossover and Mutation ............................................................................. 15
      4.1.6 Overal Algorithm Workflow ...................................................................... 16
  4.2 Trajectory Tracking Algorithm .............................................................................. 17
      4.2.1 Vehicle model .............................................................................................. 17
      4.2.2 Initialization ................................................................................................ 18
      4.2.3 Control loop ................................................................................................. 18
      4.2.4 Overall Workflow........................................................................................22
List of Figures
  1      Electric Cars ............................................................................................................... 4
  2      Linear Interpolation .................................................................................................. 6
  3      General Form of Bézier Curves................................................................................. 7
  4      Some cases of Bézier Curve ....................................................................................... 7
  5      Examples of different P Gain values ....................................................................... 8
  6      Steady-state Error ..................................................................................................... 8
  7      Examples of several values of I-Gain ....................................................................... 9
  8      Examples of several values of D-Gain ..................................................................... 9
  9      Combined PID Control ........................................................................................... 10
  10     Artificial Potential Field ......................................................................................... 10
  11     Genetic Algorithm Visualization ........................................................................... 11
  12     Gaussian Distribution ............................................................................................. 11
  13     Binary Search Visualization ................................................................................... 11
  14     Chromosome Encoding Strategy ............................................................................ 13
  15     Crossover mechanism ............................................................................................. 15
  16     Add gene................................................................................................................... 15
  17     Remove gene ............................................................................................................ 16
  18     Edit gene .................................................................................................................. 16
  19     Algorithm Workflow ............................................................................................... 16
  20     Calculating Error..................................................................................................... 20
  21     PID Workflow .......................................................................................................... 21
  22     Overall Workflow .................................................................................................... 22
  23     Generated Map ........................................................................................................ 23
  24     Car following path ................................................................................................... 23
                                           Abstract
          The goal of this project is to develop a new approach to solve two well-known
      problems in robotics engineering: Path Planning and Trajectory Tracking for Au-
      tomated Vehicles. Our novel approach introduced Artificial Potential Field and
      Genetic Algorithm to generate a collision-free Bezier spline-based trajectory for the
      automated vehicle. Then the PID control algorithm is used to help the car steer
      itself to follow the generated path from the starting point to the ending point.
1     Introduction
1.1   Motivation and Purpose
With the current technological trend, cars, robots, and vehicles have been able to move
autonomously basically without any human interaction. Artificial intelligence is such
a technology that has provided electric car auto-driving and complex problem solving
capabilities to transport humans and objects to desired location. Having seen the vast
potential in technological development, we chose Path Planning and Trajectory Tracking
problems to start with with the hope of finding new solutions and being a motivational
foundation for further researches from other engineers.
1.2 Goal
Currently, AI is the most robust tool to provide the self-driving capability for au-
tonomous vehicles. However, since the technology requires data with high speciality
such that it may become hard to obtain (data from specified sensors, high-cost periph-
erals and devices), we aim to achieve the collision-free motion using another way, which
is Genetic Algorithm
2 Project Summary
This project presents an advanced path planning and trajectory tracking system aimed
at optimizing navigation in complex environments. The system generates smooth, ef-
ficient paths while ensuring safe navigation through obstacle avoidance. It also tracks
trajectories with high accuracy, ensuring the system follows the planned path precisely.
Path Planning
   • Bézier Curve: Used to generate smooth and continuous paths, ensuring feasibil-
     ity in constrained environments.
   • Artificial Potential Fields (APF): For local obstacle avoidance by generating
     a recursive danger map that reflects obstacles and their danger level, guiding the
     system to avoid collisions.
   • Genetic Algoritm (GA): Inspired by natural selection. The algorithm evaluates
     multiple possible paths, selects the most efficient ones based on fitness criteria, and
     evolves the best path through successive generations.
Trajectory Tracking
   • PID Controller: Ensures precise adherence to planned trajectories by making
     real-time adjustments to reduce deviations caused by environmental disturbances
     or system dynamics.
   • Normal Distribution: Introduces noise into the system, closely mimicking real-
     world conditions and enabling the algorithm to adapt to unpredictable variations
     in vehicle performance and environmental factors.
   • Binary Search: An algorithm designed to determine the projection of a point onto
     a Bézier curve. This serves as a critical component for the PID controller, ensuring
     the vehicle remains aligned with the path. Additionally, it aids the Genetic model
     in validating the feasibility of the Bezier trajectory.
Project Repository
For detailed implementation, code, and documentation on the novel robotics path-
planning and control algorithms, our project repository can be found in this link:
https://github.com/Reiko0908/NOVEL-PATH-PLANNING-ALGORITHM
3 Theoretical Basis
3.1 Bézier Curve
Bezier curves is a set of locally generated points that can be constructed and positioned
from a set of control points. The more local control points being constructed, the
smoother curve becomes. Bezier curves are widely used in real life for tasks requiring
smooth and precise shapes. They are essential in graphic design and digital art for
creating scalable vector graphics and smooth font outlines.
Where:
Example
   • n = 1, the curve is a simple straight line (single Linear Interpolation).
   • n = 2, the curve is a Quadratic Bezier Curve.
   • n = 3, the curve is a Cubic Bezier Curve.
3.1.3    Properties
   • Control Points: The curve starts at P0 and ends at Pn. Intermediate control
     points (P1, P2, . . . , Pn−1) influence the shape but are not necessarily on the curve.
   • Continuity: Bézier curves are continuous and smooth, making them ideal for
     graphics and design applications.
   • Scalability: Adding more control points increases the degree of the curve, allowing
     for more complex shapes.
P = KP · e(t)
Here are the results of too low, ideal and too high P-Gain settings:
However, only the Proportional Control alone is not enough since it does not eliminate
the steady-state error (persistent offset) and also the time-consuming convergence to the
setpoint.
(a) I Gain too low (b) I Gain ideal (c) I Gain too high
                                                    de(t)
                                    D = KD ·
                                                     dt
Implementing this term will help increase the system damping effect since the rate of
change (velocity) of the error is considered. However, to high Derivative Gain may also
lead to extensive overshoot of the system and noise is also a significant factor to be
considered when tuning this constant.
(a) D Gain too low (b) D Gain ideal (c) D Gain too high
   • Attractive Force centered at the final desired position in robot’s navigation acts as
     a directing tool.
   • Repulsive Force placed along the edge of the obstacles helps repelling the robot
     when it gets close to the obstacle, providing the collision-free capability for the
     robot’s navigation.
Relying on the natural selection principle, the chromosomes that yielded better perfor-
mance (elites) will proceed to the next evolution, converging to an answer of the problem
that we are trying to solve. Also, the randomness of natural mutation would provided
the diversity of individuals that may produce better results, hence helping the model
escape out of the local minima to find a better one.
4 Methodology
Problem Formulation
Given a car in a 2D map with predetermined start point and end point and circular
obstacles that have randomly generated radius. The goal of the project is to introduce a
collision-free Path Planning Algorithm and a Trajectory Tracking method to guide the
car along the path. The factor that we are trying to minimize is the danger of the Bezier
path. The closer the path is relative to the obstacles, the more danger the path yields.
  5. Artificial evolution: The population will undergo the crossover and mutation,
     mimicking the natural evolution of animals and organisms.
6. Loop: Return to step 4 until the number ofatraining epoch runs out.
                               1,                         if di(x, y) ≤ ri,
                                    log10(di(x,y)−ri)
                Di(x, y) =    1−      log10(Ri−ri)
                                                      ,   if ri < di(x, y) ≤ Ri,
                              0,                          if di(x, y) > Ri.
   • B(t) is the Bezier curve parametric equation with respect to t converted from P
     which yields the coordinate of the local point with specific value of t
The highest possible fitness value (most inefficient chromosome) returned is 1 when
the chromosome crosses an obstacle. The ⌊B(ti)⌋ operation is used to round down
the point’s position, calculate the nearest pixel with integer value since the parametric
equation yields floating point values. The function PB() is used to find the current point’s
projection on the Bezier Curve, which we will define later in the Trajectory Tracking
section.
After running through the finess function, the chromosomes will be separated into 2
groups: elites (fitness values < TS) and non-elites (the rest) with TS is the Separation
Threshold.
Mutation
There are three types of mutation going to be used: add gene, remove gene and edit gene.
The mutation process will be conducted only on a small proportion named Mutation
Ratio RM of the non-elite chromosomes. The mutation position will also be randomized.
The additional gene will be randomized in the scope of the map size
The chosen gene will be re-randomized in the scope of the map size.
  1. Introduce the vehicle’s model: Propose the 2D motion of the car mathemati-
     cally.
  2. Load the path: The procedure starts by loading the best chromosome saved in
     the local memory that has been trained from the Genetic Model earlier. Then the
     chromosome will need to be converted into the Bezier Curve
3. Control loop:
   • ⃗u (t) is a unit vector, representing the direction that the car is currently heading.
                (cos(α) −sin(α) l
   • R(α) =                         is the rotation matrix.
                 sin(α) cos(α)
The position of the car with respect to time X(t) is obtained by continuously integrating
velocity Vcar · ⃗u ( t) with respect to time. To further simplify the problem, we define the
speed of the car to be constant, hence the equation becomes:
The heading vector ⃗u (t) at any time t is determined by continuously rotating the vector
itself from the beginning of the simulation. The := operation means assigning the value
back to the variable. In order to control the car, helping the vehicle follow the generated
path, the introduced PID algorithm is utilized to calculate the angular velocity ωpid each
control loop.
However, in the simulated environment, all movements are represented through mathe-
matical equations so the car would perform perfectly. In real-world scenarios, physical
vibrations and inherent errors are inevitable. Therefore, incorporating these factors into
the model is essential to validate the system’s effectiveness.
ω(t) = ωpid + ωΩ
ωΩ = η · x
with                                       1
                                      2         − 1 ( x−µ 2
                             N (x|µ, σ ) =√ e 2 σ )
                                         σ 2π
where η is the maximum value of the the angular velocity noise can ever be achieved.
4.2.2 Initialization
   • Initial population: Generating C chromosomes
   • Car position: Coinciding the starting position.
   • Car heading: Facing toward the ending position.
   • Load terrain: Loading map with obstacles have been pre-created earlier.
   • Load best chromosome: Executing the control points position of the chromo-
     somes with the lowest fitness score throughout the epoches.
  1. Calculating the distance between K and the two middle points of the intervals
     [tleft; tmid] and [tmid; tright]
                                     tleft+tmid                             tmid+tright
                   d1 = B                 2       − K and d2 = B                2         −K
  3. Ignore the interval that doesn’t have the answer then update the left and right
     boundaries by assigning new values to tleft and tright
Calculate error
To steer the vehicle along the generated path, we first need to determine its position
beyond the current step.
  1. We define point Z be the predicted position of the car by calculating it’s state
     using current calulcated data in the loop.
3. Then we calculate the error Yerr, which we will be using for the PID control.
Yerr = ( ⃗u × Z⃗P ) · ∥Z − P∥
Calculate PID
  • Propotional(P): Adjusting the control output in proportion to the error magni-
    tude.The larger the error, the stronger the corrective action.
Pterm = PI · Yerr
                                  Iterm = KI ·               Yerr dt
                                                     0
  • Derivative(D): Predicting the future behavior of the error by considering its rate
    of change. This term helps to dampen oscillations and improve stability.
                                                             dYerr
                                   Dterm = KD ·
                                                              dt
  • Control Variable ωpid: Minimizing deviations from a desired target or setpoint.
                                                     t
                                                                        dYerr
                      ωpid = KP · Yerr + KI ·            Yerr dt + KD ·
                                                 0                       dt
PID Workflow
Update vehicle
  • Heading: The heading vector, representing the vehicle’s orientation, is rotated
    by an angle of plus a noise term to account for uncertainties or disturbances.
                         (cos(ω + ωΩdt) −sin(ω + ωΩdt)l
                                                        ⃗u(t)
                          sin(ω + ωΩdt) cos(ω + ωΩdt) ·
  • Noise: Introducing random disturbances into the vehicle’s steering control by gen-
    erating noise based on a normal distribution. This noise simulates the real-world
    unpredictability of vehicle dynamics and environmental effects.
                                        ωΩ = η · x
  • Position: The vehicle’s position is incremented in the direction of the updated
    heading vector, scaled by the vehicle’s velocity and normalized by the frame rate.
    This step ensures the vehicle’s movement is consistent with its velocity and the
    simulation’s time resolution.
                                          ⃗u (t)
                                         ∥⃗u (t)∥
   • We have only tested on static maps, dynamic maps with moving obstacles requires
     more complex algorithms to make the robot navigate.
   • The Bezier Curve with high number of control points (high level Bezier Curve)
     possess limitations in local control, moving one control point may impact a large
     portion of the generated curve. As a result, the process of crossover and mutation,
     which posses large modifications in the shape of the path may produce invalid chro-
     mosomes in the latter generation although their parent chromosomes performed
     astoundingly well with very low fitness score and vice versa. As having mentioned
     ealier the inheritance property of crossover in Genetic Algorithm will be the key
     to make the model converge to the solution, and the randomness in mutation will
     help the model escape from local minima. If the randomness effect out-perform
     the convergence effect, it would take along time to train the model.
In sumamry, our project has successfully solve the 2 mentioned problems and could be
used as a foundation or research inspiration for other researchers and engineers. We hope
to develop more complex algorithms, starting from what we have achieved to better the
perfomance of robots
References
[1] G. E. Ji-wung Choi, Renwick Curry. Path planning based on bezier curve for au-
    tonomous ground vehicles. In Advances in Electrical and Electronics Engineering,
    World Congress on Engineering and Computer Science, WCECS, San Francisco, CA,
    USA, 2008. IEEE.
[2] C. Lamini, S. Benhlima, and A. Elbekri. Genetic algorithm based approach for
    autonomous mobile robot path planning. Procedia Computer Science, 127:180–189,
    2018.
[4] P. G. Luan and N. T. Thinh. Hybrid genetic algorithm based smooth global-path
    planning for a mobile robot. Mechanics Based Design of Structures and Machines,
    51:1758–1774, 2021.
[5] A. E. H. Mohamed Alhoseny, Alaa Tharwat. Bezier curve based path planning in a
    dynamic filed using modified genetic algorithm. Journal of Computational Scienece,
    pages 339–350, 2017.