Two-Link Robotic Arm

ITERATIVE DYNAMIC PROGRAMMING, REIN LUUS

12.4.2 Example 2: Two-link robotic arm

CHAPMAN & HALL/CRC Monographs and Surveys in Pure and Applied Mathematics

Contents

Problem Formulation

Find u over t in [0; tF ] to minimize

$$ J = t_F $$

subject to:

$$ \frac{dx_1}{dt} = \frac{sin(x_3)*(\frac{9}{4}*cos(x_3)*x_1^2+2*x_2^2) + \frac{4}{3}*(u_1-u_2) - \frac{3}{2}*cos(x_3)*u_2 } {\frac{31}{36} + \frac{9}{4}*sin(x_3)^2} $$

$$ \frac{dx_2}{dt} = -\frac{sin(x_3)*(\frac{7}{2}*x_1^2+\frac{9}{4}*cos(x3)*x_2^2) - \frac{7}{3}*u_2 + \frac{3}{2}*cos(x_3)*(u_1-u_2) }{\frac{31}{36} + \frac{9}{4}*sin(x_3)^2} $$

$$ \frac{dx_3}{dt} = x_2-x_1 $$

$$ \frac{dx_4}{dt} = x_1 $$

The initial condition are:

$$ x(0)  = [0 \ 0 \ 0.5 \ 0] $$

$$ x(t_F) = [0 \ 0 \ 0.5 \ 0.522] $$

$$ -1 <= u(1:2) <= 1 $$

% Copyright (c) 2007-2008 by Tomlab Optimization Inc.

Problem setup

toms t tf
p = tomPhase('p', t, 0, tf, 30);
setPhase(p);

tomStates x1 x2 x3 x4
tomControls u1 u2

% Initial guess
x0 = {tf == 3
    icollocate({x1 == 0; x2 == 0
    x3 == 0.5; x4 == 0.522})
    collocate({u1 == 1-2*t/tf
    u2 == 1-2*t/tf})};

% Box constraints
cbox = {2.6 <= tf <= 100
    -1  <= collocate(u1) <= 1
    -1  <= collocate(u2) <= 1};

% Boundary constraints
cbnd = {initial({x1 == 0; x2 == 0
    x3 == 0.5; x4 == 0})
    final({x1 == 0; x2 == 0
    x3 == 0.5; x4 == 0.522})};

% ODEs and path constraints
ceq = collocate({
    dot(x1) == ( sin(x3).*(9/4*cos(x3).*x1.^2+2*x2.^2) ...
    +4/3*(u1-u2) - 3/2*cos(x3).*u2 )./ (31/36 + 9/4*sin(x3).^2)
    dot(x2) == -( sin(x3).*(7/2*x1.^2 + 9/4*cos(x3).*x2.^2) ...
    - 7/3*u2 + 3/2*cos(x3).*(u1-u2) )./ (31/36 + 9/4*sin(x3).^2)
    dot(x3) == x2-x1
    dot(x4) == x1});

% Objective
objective = tf;

Solve the problem

options = struct;
options.name = 'Two Link Robotic Arm';
solution = ezsolve(objective, {cbox, cbnd, ceq}, x0, options);
t  = subs(collocate(t),solution);
x1 = subs(collocate(x1),solution);
x2 = subs(collocate(x2),solution);
x3 = subs(collocate(x3),solution);
x4 = subs(collocate(x4),solution);
u1 = subs(collocate(u1),solution);
u2 = subs(collocate(u2),solution);
Problem type appears to be: lpcon
===== * * * =================================================================== * * *
TOMLAB - Tomlab Optimization Inc. Development license  999001. Valid to 2010-02-05
=====================================================================================
Problem: ---  1: Two Link Robotic Arm           f_k       2.983364855223868100
                                       sum(|constr|)      0.000000154455802150
                              f(x_k) + sum(|constr|)      2.983365009679670400
                                              f(x_0)      3.000000000000000000

Solver: snopt.  EXIT=0.  INFORM=1.
SNOPT 7.2-5 NLP code
Optimality conditions satisfied

FuncEv    1 ConstrEv   20 ConJacEv   20 Iter   16 MinorIter  272
CPU time: 0.156250 sec. Elapsed time: 0.157000 sec. 

Plot result

subplot(2,1,1)
plot(t,x1,'*-',t,x2,'*-',t,x3,'*-',t,x4,'*-');
legend('x1','x2','x3','x4');
title('Two Link Robotic Arm state variables');

subplot(2,1,2)
plot(t,u1,'+-',t,u2,'+-');
legend('u1','u2');
title('Two Link Robotic Arm control');