-
Notifications
You must be signed in to change notification settings - Fork 3
/
optiTrans.m
97 lines (83 loc) · 3.68 KB
/
optiTrans.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
% Trajectory optimization for transition
% Author: Boyang Li
% The Hong Kong Polytechnic University
% email: boyang.li@connect.polyu.edu.hk
% Website: https://boyangli.com
% May 2018;
% Require: OptimTraj Toolbox https://github.com/MatthewPeterKelly/OptimTraj
% function [theta_cmd, throttle_cmd] = optiTrans(iniState,finState,nGrid,Time)
% solve optimal transition for tail-siiter UAV
clc; clear;
% parameters
p.mass = 1.5; % kg mass
p.g = 9.81; % m/s^2
p.rho = 1.29; % kg/m^3 density
p.Ts = 0.2; % s time constant
p.S = 0.326; % m^2 area
duration = 2; % s time to finish
% airfoid data pre-process fitting
load("NACA0012Estimation.mat");
p.pp_cl = csape(NACA_AOA,NACA_CL);
p.pp_cd = csape(NACA_AOA,NACA_CD);
% p.aoa = NACA_AOA;
% p.cl = NACA_CL;
% p.cd = NACA_CD;
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%
% Set up function handles %
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%
problem.func.dynamics = @(t,x,u)( tailsitterDyna(x,u,p) );
problem.func.pathObj = @(t,x,u)( tailsitterObj(x,u,p));
% object function cost function: change of height, throttle output?
% problem.func.pathObj = @(t,x,u)transObj(x,u,p);
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%
% Set up problem bounds %
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%
problem.bounds.initialTime.low = 0;
problem.bounds.initialTime.upp = 0;
problem.bounds.finalTime.low = duration;
problem.bounds.finalTime.upp = duration;
% states s = [x_dot; z_dot; theta]
problem.bounds.initialState.low = [0;0;0];
problem.bounds.initialState.upp = [0;0;0];
problem.bounds.finalState.low = [8;-0.5;-0.5*pi];
problem.bounds.finalState.upp = [inf;0.5;-7/18*pi]; %-80¡ã4/9pi -70 7/18pi
problem.bounds.state.low = [0;-1;-pi];
problem.bounds.state.upp = [15;0;pi];
% control u = [ft_cmd; theta_cmd] u0 = [0;0.5];
problem.bounds.control.low = [0;-pi];
problem.bounds.control.upp = [30;pi];
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%
% Initial guess at trajectory %
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%
problem.guess.time = [0,duration];
problem.guess.state = [problem.bounds.initialState.low, problem.bounds.finalState.low];
problem.guess.control = [30,0;5,-4/9*pi];
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%
% Solver options %
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%
problem.options.nlpOpt = optimset(...
'Display','iter-detailed',...
'MaxFunEvals',1e5);
% problem.options.method = 'trapezoid';
% problem.options.method = 'hermiteSimpson';
% problem.options.method = 'rungeKutta';
problem.options.method = 'chebyshev';
% problem.options.method = 'gpops';
% problem.options.chebyshev.nColPts = 50;
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%
% Solve! %
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%
% NLP solve
soln = optimTraj(problem);
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%
% Display Solution %
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%
%%%% Unpack the simulation
t = linspace(soln.grid.time(1), soln.grid.time(end), 150);
z = soln.interp.state(t);
u = soln.interp.control(t);
% t = soln.grid.time;
% z = soln.grid.state;
% u = soln.grid.control;
%%%% Plots:
plot_trans(t,u,z);