Optimal Drone Acceleration

Apps.DroneFlight History

Hide minor edits - Show changes to output

March 27, 2023, at 06:42 PM by 10.35.117.248 -
Changed lines 5-6 from:
%width=550px%Attach:optimal_time.png
to:
(:html:)
<iframe width="560" height="315" src="https://www
.youtube.com/embed/1JKbjx0Ig_o" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
(:htmlend:)

Changed lines 82-84 from:
The GEKKO package is available in Python with '''pip install gekko'''. There are [[https://apmonitor.com/wiki/index.php/Main/GekkoPythonOptimization|additional example problems]] for equation solving, optimization, regression, dynamic simulation, model predictive control, and machine learning.
to:
The GEKKO package is available in Python with '''pip install gekko'''. There are [[https://apmonitor.com/wiki/index.php/Main/GekkoPythonOptimization|additional example problems]] for equation solving, optimization, regression, dynamic simulation, model predictive control, and machine learning.

%width=550px%Attach:optimal_time.png
March 27, 2023, at 06:22 PM by 10.35.117.248 -
Changed line 13 from:
{$ \begin{array}{llclr} \min_{z, u, t_f} & t_f \\ \mbox{s.t.} & \dot{z}_1 & = & z_2 \\ & \dot{z}_2 & = & u \\ & z(0) &=& (0,0)^T \\ & z(t_f) &=& (300,0)^T \\ & z_1(t) & \in & [0,330]\\ & z_2(t) & \in & [0,33] \\ & u(t) & \in & [-2,1]\\ \end{array} $}
to:
{$ \begin{array}{llclr} \min_{z, u, t_f} & t_f \\ \mbox{s.t.} & \dot{z}_1 & = & z_2 \\ & \dot{z}_2 & = & u \\ & z(0) &=& (0,0)^T \\ & z(t_f) &=& (300,0)^T \\ & 0 & \leq & z_1(t) \leq 330\\ & 0 & \leq & z_2(t) \leq 33 \\ & u(t) & \in & [-2,1]\\ \end{array} $}
March 27, 2023, at 06:21 PM by 10.35.117.248 -
Changed line 13 from:
{$ \begin{array}{llclr} \min_{z, u, t_f} & t_f \\ \mbox{s.t.} & \dot{z}_1 & = & z_2 \\ & \dot{z}_2 & = & u \\ & z(0) &=& (0,0)^T \\ & z(t_f) &=& (300,0)^T \\ & z_1(t) & \in & [0,33]\\ & z_2(t) & \in & [0,330] \\ & u(t) & \in & [-2,1]\\ \end{array} $}
to:
{$ \begin{array}{llclr} \min_{z, u, t_f} & t_f \\ \mbox{s.t.} & \dot{z}_1 & = & z_2 \\ & \dot{z}_2 & = & u \\ & z(0) &=& (0,0)^T \\ & z(t_f) &=& (300,0)^T \\ & z_1(t) & \in & [0,330]\\ & z_2(t) & \in & [0,33] \\ & u(t) & \in & [-2,1]\\ \end{array} $}
March 26, 2023, at 04:44 AM by 136.36.4.38 -
Changed lines 7-8 from:
This problem is to optimize the time for a drone to achive a fixed distance of 300 units in minimum time to a stationary target.
to:
Drone flight optimization is a critical aspect of modern UAV operations, as it can help to maximize the efficiency and effectiveness while minimizing risk and improving safety. Some objectives include reduced flight time, increased payload capacity, improved battery life, or minimized risk.

Drone flight optimization can use model predictive control (MPC) to optimize flight paths in real-time. MPC accounts for a range of factors such as wind speed and direction, altitude, and obstacles, to determine the most efficient and safest route for the drone to follow. If fast enough, MPC can adjust the drone flight path real-time to avoid obstacles or take advantage of changing weather conditions.

This simplified problem is to optimize the time for a drone to achieve
a fixed distance of 300 units in minimum time to a stationary target.
Changed line 15 from:
with {`z = (z_1, z_2)^T`}. The optimal solution is to accelerate forward until a switch point where the drone deccelerates to arrive at the final target distance with zero velocity.
to:
with {`z = (z_1, z_2)^T`}. The optimal solution is to accelerate forward until a switch point where the drone decelerates to arrive at the final target distance with zero velocity.
March 26, 2023, at 04:39 AM by 136.36.4.38 -
Changed line 9 from:
{$ \begin{array}{llclr} \min_{z, u, t_f} & t_f \\ \mbox{s.t.} & \dot{z}_1 & = & z_2, \\ & \dot{z}_2 & = & u \\ & z(0) &=& (0,0)^T \\ & z(t_f) &=& (300,0)^T \\ & z_1(t) & \in & [0,33]\\ & z_2(t) & \in & [0,330] \\ & u(t) & \in & [-2,1]\\ \end{array} $}
to:
{$ \begin{array}{llclr} \min_{z, u, t_f} & t_f \\ \mbox{s.t.} & \dot{z}_1 & = & z_2 \\ & \dot{z}_2 & = & u \\ & z(0) &=& (0,0)^T \\ & z(t_f) &=& (300,0)^T \\ & z_1(t) & \in & [0,33]\\ & z_2(t) & \in & [0,330] \\ & u(t) & \in & [-2,1]\\ \end{array} $}
March 26, 2023, at 04:34 AM by 136.36.4.38 -
Added lines 1-76:
(:title Optimal Drone Acceleration:)
(:keywords optimization, optimal control, benchmark, nonlinear control, dynamic optimization, engineering optimization, Python, GEKKO, differential, algebraic, modeling language:)
(:description Optimal acceleration for a drone to change location solved with Python Gekko.:)

%width=550px%Attach:optimal_time.png

This problem is to optimize the time for a drone to achive a fixed distance of 300 units in minimum time to a stationary target.

{$ \begin{array}{llclr} \min_{z, u, t_f} & t_f \\ \mbox{s.t.} & \dot{z}_1 & = & z_2, \\ & \dot{z}_2 & = & u \\ & z(0) &=& (0,0)^T \\ & z(t_f) &=& (300,0)^T \\ & z_1(t) & \in & [0,33]\\ & z_2(t) & \in & [0,330] \\ & u(t) & \in & [-2,1]\\ \end{array} $}

with {`z = (z_1, z_2)^T`}. The optimal solution is to accelerate forward until a switch point where the drone deccelerates to arrive at the final target distance with zero velocity.

%width=550px%Attach:optimal_time_solution.png

(:toggle hide solution button show="Optimal Time Source":)
(:div id=solution:)
(:source lang=python:)
from gekko import GEKKO
import matplotlib.pyplot as plt
import numpy as np

m = GEKKO(remote=False)
m.time = np.linspace(0, 1, 100)

# variables
Z1 = m.Var(value=0, ub=330, lb=0)
Z2 = m.Var(value=0, ub=33, lb=0)
m.fix_final(Z2, 0)
m.fix_final(Z1, 300)

# adjust final time
tf = m.FV(value=500, lb=0.1)
tf.STATUS = 1

# discrete decision - manipulated variable
u = m.MV(value=1, lb=-2, ub=1, integer=True)
u.STATUS = 1

m.Equation(Z1.dt() / tf == Z2)
m.Equation(Z2.dt() / tf == u)

m.Minimize(tf)

# options
m.options.IMODE = 6
m.options.SOLVER = 1

m.solve(disp=False)

# display solution
print("Total time: " + str(tf.value[0]))
tm = m.time * tf.value[0]
plt.figure(figsize=(6,4))
plt.subplot(211)
plt.plot(tm, Z1, label=r'$Z_1$')
plt.plot(tm, Z2, label=r'$Z_2$')
plt.ylabel('Z'); plt.legend(); plt.grid()
plt.subplot(212)
plt.plot(tm, u, label=r'$u$')
plt.ylabel('u'); plt.xlabel('Time')
plt.legend(); plt.grid(); plt.tight_layout()
plt.savefig('optimal_time.png',dpi=300); plt.show()
(:sourceend:)
(:divend:)

An MINLP solution is calculated with the APOPT solver with a minimized time of 30.31. Thanks to [[https://www.linkedin.com/in/tjasperson/|Tanner Jasperson]] for providing a solution.

----

%width=200px%Attach:gekko.png

The [[https://gekko.readthedocs.io/en/latest/|Gekko Optimization Suite]] is a machine learning and optimization package in Python for mixed-integer and differential algebraic equations.

📄 [[https://apmonitor.com/wiki/index.php/Main/APMonitorReferences|Gekko Publication and References]]

The GEKKO package is available in Python with '''pip install gekko'''. There are [[https://apmonitor.com/wiki/index.php/Main/GekkoPythonOptimization|additional example problems]] for equation solving, optimization, regression, dynamic simulation, model predictive control, and machine learning.