Free Floating Robot
Users Guide for dyn.Opt, Example 6a, 6b, 6c
A free floating robot
Contents
Problem description
Find u over t in [0; 5 ] to minimize
6c is free end time
6a:
6b:
6c:
subject to:
6b - x(5) = [4 0 4 0 0 0]; 6c - x(5) = [4 0 4 0 pi/4 0]; 6c - -5 <= u <= 5
% Copyright (c) 2007-2008 by Tomlab Optimization Inc.
Problem setup
toms t for i=1:3
if i==3 toms tf else tf = 5; end p1 = tomPhase('p1', t, 0, tf, 40); setPhase(p1); tomStates x1 x2 x3 x4 x5 x6 tomControls u1 u2 u3 u4 % Initial guess if i==1 x0 = {icollocate({x1 == 0; x2 == 0; x3 == 0 x4 == 0; x5 == 0; x6 == 0}) collocate({u1 == 0; u2 == 0 u3 == 0; u4 == 0})}; elseif i==2 x0 = {icollocate({x1 == x1_init; x2 == x2_init x3 == x3_init; x4 == x4_init x5 == x5_init; x6 == x6_init}) collocate({u1 == u1_init; u2 == u2_init u3 == u3_init; u4 == u4_init})}; else x0 = {tf == tf_init icollocate({x1 == x1_init; x2 == x2_init x3 == x3_init; x4 == x4_init x5 == x5_init; x6 == x6_init}) collocate({u1 == u1_init; u2 == u2_init u3 == u3_init; u4 == u4_init})}; end % Box constraints if i<=2 cbox = {icollocate({ -100 <= x1 <= 100; -100 <= x2 <= 100 -100 <= x3 <= 100; -100 <= x4 <= 100 -100 <= x5 <= 100; -100 <= x6 <= 100}) collocate({-1000 <= u1 <= 1000; -1000 <= u2 <= 1000 -1000 <= u3 <= 1000; -1000 <= u4 <= 1000})}; else cbox = { icollocate({-100 <= x1 <= 100; -100 <= x2 <= 100 -100 <= x3 <= 100; -100 <= x4 <= 100 -100 <= x5 <= 100; -100 <= x6 <= 100}) collocate({-5 <= u1 <= 5; -5 <= u2 <= 5 -5 <= u3 <= 5; -5 <= u4 <= 5})}; end % Boundary constraints cbnd = initial({x1 == 0; x2 == 0; x3 == 0 x4 == 0; x5 == 0; x6 == 0}); if i==2 cbnd6b = {cbnd final({x1 == 4; x2 == 0 x3 == 4; x4 == 0 x5 == 0; x6 == 0})}; elseif i==3 cbnd6c = {cbnd final({x1 == 4; x2 == 0 x3 == 4; x4 == 0 x5 == pi/4; x6 == 0 1 <= tf <= 100})}; end % ODEs and path constraints M = 10.0; D = 5.0; Le = 5.0; In = 12.0; s5 = sin(x5); c5 = cos(x5); ceq = collocate({ dot(x1) == x2 dot(x2) == ((u1+u3).*c5-(u2+u4).*s5)/M dot(x3) == x4 dot(x4) == ((u1+u3).*s5+(u2+u4).*c5)/M dot(x5) == x6 dot(x6) == ((u1+u3)*D-(u2+u4)*Le)/In}); % Objective
Solve the problem
options = struct; if i==1 objective = (final(x1)-4)^2+(final(x3)-4)^2+final(x2)^2+ ... final(x4)^2+final(x5)^2+final(x6)^2 + ... integrate(0.5*(u1.^2+u2.^2+u3.^2+u4.^2)); options.name = 'Free Floating Robot 6a'; solution1 = ezsolve(objective, {cbox, cbnd, ceq}, x0, options); tp = subs(collocate(t),solution1); x1p = subs(collocate(x1),solution1); x2p = subs(collocate(x2),solution1); x3p = subs(collocate(x3),solution1); x4p = subs(collocate(x4),solution1); x5p = subs(collocate(x5),solution1); x6p = subs(collocate(x6),solution1); u1p = subs(collocate(u1),solution1); u2p = subs(collocate(u2),solution1); u3p = subs(collocate(u3),solution1); u4p = subs(collocate(u4),solution1); tf1 = subs(final(t),solution1); x1_init = subs(x1,solution1); x2_init = subs(x2,solution1); x3_init = subs(x3,solution1); x4_init = subs(x4,solution1); x5_init = subs(x5,solution1); x6_init = subs(x6,solution1); u1_init = subs(u1,solution1); u2_init = subs(u2,solution1); u3_init = subs(u3,solution1); u4_init = subs(u4,solution1); elseif i==2 objective = integrate(0.5*(u1.^2+u2.^2+u3.^2+u4.^2)); options.name = 'Free Floating Robot 6b'; solution2 = ezsolve(objective, {cbox, cbnd6b, ceq}, x0, options); x1_init = subs(x1,solution2); x2_init = subs(x2,solution2); x3_init = subs(x3,solution2); x4_init = subs(x4,solution2); x5_init = subs(x5,solution2); x6_init = subs(x6,solution2); u1_init = subs(u1,solution2); u2_init = subs(u2,solution2); u3_init = subs(u3,solution2); u4_init = subs(u4,solution2); tf_init = subs(final(t),solution2); else objective = tf; options.name = 'Free Floating Robot 6c'; solution3 = ezsolve(objective, {cbox, cbnd6c, ceq}, x0, options); end
Problem type appears to be: qpcon ===== * * * =================================================================== * * * TOMLAB - Tomlab Optimization Inc. Development license 999001. Valid to 2010-02-05 ===================================================================================== Problem: --- 1: Free Floating Robot 6a f_k 13.016949152618103000 sum(|constr|) 0.000000000121647941 f(x_k) + sum(|constr|) 13.016949152739752000 f(x_0) 0.000000000000000000 Solver: snopt. EXIT=0. INFORM=1. SNOPT 7.2-5 NLP code Optimality conditions satisfied FuncEv 1 ConstrEv 35 ConJacEv 35 Iter 31 MinorIter 328 CPU time: 0.906250 sec. Elapsed time: 0.906000 sec.
Problem type appears to be: qpcon ===== * * * =================================================================== * * * TOMLAB - Tomlab Optimization Inc. Development license 999001. Valid to 2010-02-05 ===================================================================================== Problem: --- 1: Free Floating Robot 6b f_k 76.800001530400650000 sum(|constr|) 0.000000005285607311 f(x_k) + sum(|constr|) 76.800001535686263000 f(x_0) 6.802639150498489300 Solver: snopt. EXIT=0. INFORM=1. SNOPT 7.2-5 NLP code Optimality conditions satisfied FuncEv 1 ConstrEv 30 ConJacEv 30 Iter 21 MinorIter 370 CPU time: 0.718750 sec. Elapsed time: 0.734000 sec.
Problem type appears to be: lpcon ===== * * * =================================================================== * * * TOMLAB - Tomlab Optimization Inc. Development license 999001. Valid to 2010-02-05 ===================================================================================== Problem: --- 1: Free Floating Robot 6c f_k 4.160935929052688400 sum(|constr|) 0.000000006428671067 f(x_k) + sum(|constr|) 4.160935935481359300 f(x_0) 5.000000000000000000 Solver: snopt. EXIT=0. INFORM=1. SNOPT 7.2-5 NLP code Optimality conditions satisfied FuncEv 1 ConstrEv 67 ConJacEv 67 Iter 27 MinorIter 749 CPU time: 0.859375 sec. Elapsed time: 0.859000 sec.
end
Plot result
tf2 = tf_init; tf3 = subs(tf,solution3); disp(sprintf('\nFinal time for 6a = %1.4g',tf1)); disp(sprintf('\nFinal time for 6b = %1.4g',tf2)); disp(sprintf('\nFinal time for 6c = %1.4g',tf3)); subplot(2,1,1) plot(tp,x1p,'*-',tp,x2p,'*-',tp,x3p,'*-',tp,x4p,'*-' ... ,tp,x5p,'*-',tp,x6p,'*-'); legend('x1','x2','x3','x4','x5','x6'); title('Free Floating Robot state variables'); subplot(2,1,2) plot(tp,u1p,'+-',tp,u2p,'+-',tp,u3p,'+-',tp,u4p,'+-'); legend('u1','u2','u3','u4'); title('Free Floating Robot control');
Final time for 6a = 5 Final time for 6b = 5 Final time for 6c = 4.161