Professional Documents
Culture Documents
02 - Kinematics
02 - Kinematics
• Home exercise
Contents
1 Trajectory Tracking Control 3
4 Exercises 19
4.1 Exercise 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
4.2 Exercise 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
4.3 Exercise 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
1
List of Figures
1 Space Trajectory . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2 Rigid body AUV with six degree of freedon . . . . . . . . . . . . 4
3 Referencial Frames . . . . . . . . . . . . . . . . . . . . . . . . . . 4
4 Position Vectors AUV . . . . . . . . . . . . . . . . . . . . . . . . 6
5 Fullyactuated AUV with Six Fixed Thrusters . . . . . . . . . . . 8
6 Underactuated AUV with Four Fixed Thrusters . . . . . . . . . . 9
7 Linearized System . . . . . . . . . . . . . . . . . . . . . . . . . . 10
8 Kinematics Position Control Loop Diagram . . . . . . . . . . . . 12
2
Trajectory Tracking - AUV Kinematics Model
1
z
−1
−2
2 2
1 1
0 0
−1 −1
y −2−2 x
3
2 Underwater Vehicle Model
The AUV is modeled as a rigid body with six degree of freedon since six
independent coordinates are necessary to determine his position and
orientation.
CG
B E
CG xb xe
yb ye
zb ze
yi
I xi
zi
4
Using the standard notation of ocean engineering, the general motion
of an AUV in 6 DOF can be described by the following vectors:
5
B r1BE E
CG xb xe
yb ye
zb ze
I I
ηCG ηE
yi
I xi
zi
η̇1ICG = J1BI
CG
(η2ICG )v1BCG
η̇2ICG = J2BI
CG
(η2ICG )v2BCG
in which J1BI
CG
and J2BI
CG
are transformation matrices which are related
through the functions of the Euler angles: roll (φ), pitch (θ) and yaw (ψ),
given by:
cos ψcosθ −sinψcosθ + cosψsinθsinφ sinψsinφ + cosψsinθcosφ
J1BI
CG
= sin ψcosθ cosψcosθ + sinψsinθsinφ −cosψsinφ + sinψsinθcosφ
sin θ cosθsinφ cosθcosφ
1 sinθtanθ cosθtanθ
J2BI
CG
= 0 cosψ −sinφ
0 sinφ/cosθ cosφ/cosθ
The relationship between linear velocity of the gravity center (CG)
v1BCG and the linear velocity of the head point (E) v1BE is given by:
6
which generate the said motion. Modeling of the kinematic states involves
the study of the geometrical aspects of motion.
In this section, the kinematic equations of motion of the head E o an
AUV moving in a 3D space are presented.
In order to obtain the kinematic control law to ensure the position desired
E of the AUV follows the trajectory, the following kinematic model is consid-
ered:
η̇1IE = J1BI
CG
(η2ICG )v1BE (8)
η̇2IE = J2BI
CG
(η2ICG )v2BE (9)
in which the velocity inputs to be used to control the AUV can be some, any
B
or all the CG velocities vCG = {u, v, w, p, q, r} and the controlled position
outputs can be again some, any or all of the absolute position vector of
I
the head point E, ηE = {xe , ye , ze , φ, θ, ψ}. Notice that the number of velocity
inputs must be the same as the number of the position outputs.
Equations (8) and (9) can be assembled together as follows:
η̇EI = JCG
BI I
(η2CG )vEB (10)
7
Let’s define three vectors to represent variables to be used in the control:
• ha a vector with one (true) and zero (false) to represent the velocities
degree of freedom used to actuate in the center of mass CG.
• hu to be the negation of vector ha , in other words, to represent the ve-
locities degree of freedom not used to actuate (unactuated) in
the center of mass CG.
• he with one (true) and zero (false) to represent the position degrees of
freedom of the reference point E chosen to be controlled by the
torque imposed on the center of mass CG.
The idea behind these vector is to allow us to work with both, fully or
any kind of under actuated AUVs. Using these vectors is possible to select
appropriate lines and columns of a full matrix for the necessary calculations
to work in a reduced space.
For example, imagine that we have a fully actuated AUV with six thrusters,
two on the left and right pointing backwards (P1 ,P2 ), two on the top and
botton pointing backwards (P3 ,P4 ) and two on the left and right pointing
down (P5 ,P6 ) as shown on figure 5.
P3
P5
CGP2
P1
P6 P4
8
Imagine now that we have an underactuated AUV with only four thrusters,
two in the sides left and right pointing backwards (P1 ,P2 ) and two on the
sides top and botton pointing backwards (P3 ,P4 ) as shown on figure 6.
-ψ ψ
P3
CGP2
x -x x
P1
P4
-θ y θ
z
9
2.3 Linearization of Kinematic Model
Looking at the kinematic model, equation (10)
where:
cos ψcosθ −sinψcosθ + cosψsinθsinφ sinψsinφ + cosψsinθcosφ 0 0 0
sin ψcosθ cosψcosθ + sinψsinθsinφ −cosψsinφ + sinψsinθcosφ 0 0 0
sin θ cosθsinφ cosθcosφ 0 0 0
J BI =
0 0 0 1 sinθtanθ cosθtanθ
CG
0 0 0 0 cosψ −sinφ
0 0 0 0 sinφ/cosθ cosφ/cosθ
it is possible to notice that the equation is non linear only on the input.
Therefore to apply the linear control technique it is necessary to linearize
the equation. Applying the technique of Feedback Linearization, adopting
the right hand side of the equation as the control law force u to be added
to the system we obtain
BI I
u = JCG (η2CG )vEB
Isolating now the input vEB ,
−1
vEB = JCG
BI
(η2ICG )u (13)
we obtain the appropriate velocity vEB that will depend of θ and linearizes
the nonlinear system equation (10).
Substituting the input equation (13) into the nonlinear differential equa-
tion (10)
η̇EI = JCG
BI I
(η2CG )vEB
results:
−1
η̇EI = JCG
BI I BI
(η2CG )(JCG (η2ICG )u (14)
: [I]
I BI I BI −1
(η2ICG )u
η̇E = JCG (η
2 CG
)J
CG
(15)
η̇EI = u (16)
u −1
vEB ηEI
BI
JCG (η2ICG ) η̇EI = JCG
BI I
(η2CG )vEB
10
3 Kinematic Control Law
The design problem can be formulated as follows:
1
I I
ηEd (t), η̇Ed (t),
z
0
−1
−2
2 2
1 1
0 0
−1 −1
y −2−2 x
vC uC
derive a control law vEB that forces output ηEI (t) of the model
η̇EI = JCG
BI I
(η2CG )vEB
I I
to track asymptotically the desired trajectory ηEd (t),η̇Ed (t), despite of the drift
terms that might have.
Let’s consider that we want to start from a position pc, follow a spiral tra-
jectory of radius r with a angular velocity wmin looking at a fixed center point
of the spiral pa. The reference trajectory components can be given as:
I
ηEd (t) = {xr, yr, zr, phir, thetar, psir}
I
η̇Ed (t) = {dxr, dyr, dzr, dphir, dthetar, dpsir}
and can be written in MatLab format as follows:
wmin = 0.1;
pa = [0;0;0]; %center of observation point
pc = [0;0;-3]; %center of the begining of the trajectory
r = 2; ang=pi/2;
% Spiral reference trajectory controlling all dofs x,y,z,ox,oy,oz
% looking to the center of point pa
xr = (pc(1) + r*sin(wmin*t)).*(t>=0);
yr = (pc(2) - r*cos(wmin*t)).*(t>=0);
zr = (pc(3) + 0.25*wmin*t).*(t>=0);
phir = atan2(sqrt((xr-pa(1)).^2+(yr-pa(2)).^2),zr-pa(3)).*(t>=0);
thetar = 0.*(t>=0);
psir = wmin*t.*(t>=0);
dxr = r*cos(wmin*t).*(t>=0);
dyr = r*sin(wmin*t).*(t>=0);
dzr = 0.25*wmin.*(t>=0);
dphir = (1./(1+(phir).^2)).*(t>=0);
dthetar = 0.*(t>=0);
dpsir=wmin;
11
3.1 Feedfoward and Feedback Control Model
The linearized transfer function P (s) relating the output ηEI with the input
u calculated from the time domain equation,
η̇EI = u
uf f
I
ηEd (t) ep uf b + u −1
vEB ηEI (t)
+ Kp + BI
JCG (η2ICG ) η̇EI = JCG
BI I
(η2CG )vEB
−
12
3.2 Dynamics Error Equation of Closed-Loop Kinematic
Control System
From Figure 8
I
η̇Ed (t)
d
dt
uf f
I
ηEd (t) ep uf b + u −1
vEB ηEI (t)
+ Kp + BI
JCG (η2ICG ) η̇EI = JCG (η2CG )vEB
BI I
−
13
3.3 Dynamic Control Law Reference Velocities to Track
the Trajectory
B
Let’s define velocities VCG as the truth desired actuated velocities on
adt
the CG which satisfies the dynamics error equation (26), which also are
B
the components of the velocity VCG of the AUV.
B
To obtain these velocities VCG , let’s start substituting equation (22)
adt
I
ep = ηEd − ηEI
ėp + λep = 0
which results:
I
(η̇Ed − η̇EI ) + λ(ηEd
I
− ηEI ) = 0 (27)
I
Isolating η̇E from equation (27) results the closed-loop kinematic equa-
tion:
η̇EI = η̇Ed
I I
+ λ(ηEd − ηEI ) (28)
Substituting equation (10)
η̇EI = JCG
BI I
(η2CG )vEB
Using the velocity equations of two points fixed on a rigid body (6)
and (7)
v2BE = v2BCG ,
the velocity vector vEB can be written as:
B B
v1CG + v2BCG × r1BE
v1E
vEB = = (31)
v2BE v2BCG
14
Using the angular velocities equation (2),
v2BCG = {p q r}T
r1BE = {x y z }T
the calculus of the vectorial product v2BCG × r1BE of equation (31) can be written
as:
p q r p q
v2BCG × r1BE = = (qz − ry )~i + (rx − pz )~j + (py − qx )~k
x y z x y
~k
~i ~j ~i ~j
(32)
Expanding the terms of equation (31)
B
v1CG + v2BCG × r1BE
vEB =
v2BCG
v2BCG × r1BE = (qz − ry )~i + (rx − pz )~j + (py − qx )~k
u + uC
qz − ry
u + qz − ry + uC
v + vC rx − pz v + rx − pz + vC
w + wC py − qx w + py − qx + wC
vEB = + = (33)
p
0
p
q 0 q
r 0 r
15
the velocity necessary vEBn to track the choosen trajectory can be rewritten as
only:
1 u + qz − ry + uC
1 v + rx − pz + vC
u + qz − ry + uC
1 w + py − qx + wC
(34)
B
vEn = = v + rx − pz + vC
0 p
w + py − qx + wC
0 q
0 r
Now, taking into account the actuated degrees of freedom ha from equation
(11),
1
0
0
ha =
0
1
1
where:
1 00 0 1 1 0 1
1 1 0 0
z }| { z }| {
1
1 0 0 0 z −y
1
1 0 0 0 z −y
1
0 1 0 −z 0 +x
1
0 1 0 −z 0 +x
1 0 0 1 +y −x 0 1 0 0 1 +y −x 0
Sh = Shn =
0
0 0 0 1 0 0
0
0 0 0 1 0 0
0
0 0 0 0 1 0
0
0 0 0 0 1 0
0 0 0 0 0 0 1 0 0 0 0 0 0 1
1 u + uC
uat
0 u + uC
0 v + vC vat 1 v + vC
0 w + wC wat 1 w + wC
B B
VCG = = VCG =
adt
0
p
pat
uat
1
p
1 q qat 0 q
1 r rat 0 r
16
therefore, vEBn equation (34) can be written in a simplified way as:
B
vEBn = Sh VCG B
+ Vdrif t (36)
adt
B
and isolating the truth desired actuated velocities VCG results the kine-
adt
B
matics CG control velocities VCG that guarantees the necessary head
adt
velocities vEBn to achieve the position error ep null:
−
B
VCG = Sh−1 (JCG
BI 1
(η2ICG )(η̇Ed
I I
+ λ(ηEd − ηEI )) − Vdrif
B
t) (37)
adt
uadt uC
B
VCG = qadt − 0 (38)
adr
radt 0
| {z } | {z }
VB B
Vcurr
CGadt
where:
1 uC
1 uat
0 vC
0 vat
0 wC
0 wat
B
Vcurr =
B
VCG =
0
0
adt 0 pat
1 0
1 qat
1 0
1 rat
B
The resultant vector VCG is the reference desired actuated velocity to
adr
be used in the Dynamic control law (next class) to calculate the necessary
torque of the AUV to track the desired trajectory in presence of sea current.
17
In MatLab, the previous calculation can be done in the following form:
18
4 Exercises
4.1 Exercise 1
Given the desired bounded and continuous spiral 3D trajectory:
wC
1
I I
ηEd (t), η̇Ed (t),
z
0
−1
−2
2 2
1 1
0 0
−1 −1
y −2−2 x
vC uC
η̇EI = JCG
BI I
(η2CG )vEB
P3
P5
CGP2
P1
P6 P4
uf f
I
ηEd (t) ep uf b + u −1
vEB ηEI (t)
+ Kp + BI
JCG (η2ICG ) η̇EI = JCG
BI I
(η2CG )vEB
−
19
4.2 Exercise 2
Make the necessary modifications to the ref_traj(t) function to simulate a
trajectory track control ηEI (t) to track a desired 3D space reference position
I
trajectory ηEd (t) by a fullyactuated AUV always looking straight ahead.
4.3 Exercise 3
Make the necessary modifications to the code attached to simulate a trajectory
track control ηEI (t) to track a desired 3D space reference position trajectory
I
ηEd (t) subject to sea current v1BC by an underactuated AUV with only four
thrusters, two in the sides left and right pointing backwards (P1 ,P2 ) and
two on the sides top and botton pointing backwards (P3 ,P4 ) as shown
on figure below. With these thrusters you are going to actuate torque in three
degrees of freedom of the AUV x, θ, ψ and you want to control control position
x, y, z of the head E of the AUV.
-ψ ψ
P3
CGP2 E
x -x x
P1
P4
-θ y θ
z
20
Full Actuated Base Program
% ======================================================================= %
% Kinematic AUV
% ======================================================================= %
clear all
close all
clc
% =============================Simulation Datas========================== %
epsilonx = 1/2;
epsilony = 0;
epsilonz = 0;
Lambdap = 10*eye(6); % proportional control gain of kinematic part
re = [epsilonx;epsilony;epsilonz]; % distance vector between G and E
% Datas
data = struct(’re’,re,’Lambdap’,Lambdap);
% ================================Simulation============================= %
% Initial conditions
x0 =-epsilonx;
y0 = 0;
z0 = 0;
phi0 = 0;
theta0 = 0;
psi0 = 0;
xe0 = 0;
ye0 = 0;
ze0 = 0;
s0 = [x0 y0 z0 phi0 theta0 psi0 xe0 ye0 ze0];
% Solver precision
options = odeset(’RelTol’,1e-3,’AbsTol’,1e-6);
21
% Integration
[t,s] = ode45(@(t,s) kinematic_auv(t,s,data),tspan,s0,options);
x = s(:,1);
y = s(:,2);
z = s(:,3);
phi = s(:,4);
theta = s(:,5);
psi = s(:,6);
xe = s(:,7);
ye = s(:,8);
ze = s(:,9);
pe = phi;
qe = theta;
re = psi;
[xr,yr,zr,pr,qr,rr,dxr,dyr,dzr,dpr,dqr,drr,ucI,vcI,wcI] = ref_traj(t);
% =============================Plots===================================== %
% To see the position and orientation of point E of the AUV
for k = 1:length(phi)
posxyzp1 = J1*[1;0;0];
posxyzp2 = J1*[0;1;0];
posxyzp3 = J1*[0;0;1];
end
% Reference trajectory
for i = 1:length(t)
[xr(i,1),yr(i,1),zr(i,1),phir(i,1),thetar(i,1),psir(i,1),dxr(i,1),dyr(i,1),dzr(i,1),...
dphir(i,1),dthetar(i,1),dpsir(i,1),ucg(i,1),vcg(i,1),wcg(i,1)] = ref_traj(t(i));
end
video_auv(xe,ye,ze,xyzp1,xyzp2,xyzp3,xr,yr,zr,epsilonx,t)
22
function dsdt = kinematic_auv(t,s,data)
% ----------------------------Diferential Equations------------------------
% Initialize state vector
dsdt = zeros(6,1);
% Define states
x = s(1);
y = s(2);
z = s(3);
phi = s(4);
theta = s(5);
psi = s(6);
xe = s(7);
ye = s(8);
ze = s(9);
% Parameters
epsilonx = data.re(1);
epsilony = data.re(2);
epsilonz = data.re(3);
Lambdap = data.Lambdap;
% ================================Parameters===============================
J1 = [ cos(theta)*cos(psi),...
-cos(phi)*sin(psi)+sin(phi)*sin(theta)*cos(psi),...
sin(phi)*sin(psi)+cos(phi)*sin(theta)*cos(psi);...
cos(theta)*sin(psi),...
cos(phi)*cos(psi)+sin(phi)*sin(theta)*sin(psi),...
-sin(phi)*cos(psi)+cos(phi)*sin(theta)*sin(psi);...
-sin(theta),...
sin(phi)*cos(theta),...
cos(phi)*cos(theta) ];
J2 = [1,sin(phi)*sin(theta)/cos(theta),...
cos(phi)*sin(theta)/cos(theta);...
0,cos(phi),-sin(phi);
0,sin(phi)/cos(theta),cos(phi)/cos(theta)];
% ==============================Controller=================================
S = [1 0 0 0 epsilonz -epsilony
0 1 0 -epsilonz 0 epsilonx
0 0 1 epsilony -epsilonx 0
0 0 0 1 0 0
0 0 0 0 1 0
0 0 0 0 0 1];
23
[xr,yr,zr,pr,qr,rr,dxr,dyr,dzr,dpr,dqr,drr,ucI,vcI,wcI] = ref_traj(t);
eta1ed = [xr;yr;zr;pr;qr;rr];
deta1ed = [dxr;dyr;dzr;dpr;dqr;drr];
pe = phi;
qe = theta;
re = psi;
eta12e = [xe;ye;ze;pe;qe;re];
J = [J1 zeros(3);
zeros(3) J2];
p = vadt(4);
q = vadt(5);
r = vadt(6);
ve = S*vadt - [q*epsilonz-r*epsilony;r*epsilonx-p*epsilonz;...
p*epsilony-q*epsilonx;0;0;0];
u = ve(1);
v = ve(2);
w = ve(3);
p = ve(4);
q = ve(5);
r = ve(6);
% ==============================Dynamic model==============================
dsdt(1) = J1(1,:)*[u;v;w];
dsdt(2) = J1(2,:)*[u;v;w];
dsdt(3) = J1(3,:)*[u;v;w];
dsdt(4) = J2(1,:)*[p;q;r];
dsdt(5) = J2(2,:)*[p;q;r];
dsdt(6) = J2(3,:)*[p;q;r];
return
24
%function ref_traj(t)
function [xr,yr,zr,phir,thetar,psir,dxr,dyr,dzr,...
dphir,dthetar,dpsir,ucI,vcI,wcI] = ref_traj(t)
wmin = 0.1;
r = 2;
ang=pi/2;
% Reference trajectory spiral controlling x,y,z,ox,oy,oz looking to the center of point pa.
xr = (pc(1) + r*sin(wmin*t)).*(t>=0);
yr = (pc(2) - r*cos(wmin*t)).*(t>=0);
zr = (pc(3) + 0.25*wmin*t).*(t>=0);
phir = atan2(sqrt((xr-pa(1)).^2+(yr-pa(2)).^2),zr-pa(3)).*(t>=0);
% phir = atan2(sqrt((xr-pa(1))^2+(yr-pa(2))^2),pa(3)).*(t>=0);
thetar = 0.*(t>=0);
psir = wmin*t.*(t>=0);
dxr = r*cos(wmin*t).*(t>=0);
dyr = r*sin(wmin*t).*(t>=0);
dzr = 0.25*wmin.*(t>=0);
dphir = (1./(1+(phir).^2)).*(t>=0);
dthetar = 0.*(t>=0);
dpsir=wmin;
return
25
function J1 = rotxyz(phi,theta,psi);
J1 = [ cos(theta).*cos(psi),...
-cos(phi).*sin(psi)+sin(phi).*sin(theta).*cos(psi),...
sin(phi).*sin(psi)+cos(phi).*sin(theta).*cos(psi);...
cos(theta).*sin(psi),...
cos(phi).*cos(psi)+sin(phi).*sin(theta).*sin(psi),...
-sin(phi).*cos(psi)+cos(phi).*sin(theta).*sin(psi);...
-sin(theta),...
sin(phi).*cos(theta),...
cos(phi).*cos(theta)];
return
26
%function video_auv(xe,ye,ze,xr,yr,zr,x,y,z,phi,theta,psi,epsilon,t)
function [F] = video_auv(xe,ye,ze,xyzp1,xyzp2,xyzp3,xr,yr,zr,epsilon,t)
dt = t(2)-t(1);
fig = figure;
mov = VideoWriter(’movieauv.avi’);
open(mov);
plot3(xr,yr,zr,’r--’)
xlabel(’X (m)’);
ylabel(’Y (m)’);
zlabel(’Z (m)’);
grid on
hold on
axis([-3 3 -3 3 -3 3])
xl=abs(min(xr)*2)+abs(max(xr)*2);
yl=abs(min(yr)*2)+abs(max(yr)*2);
zl=abs(min(zr)*2)+abs(max(zr)*2);
% axis([-2 2 -2 2 0 3])
% axis([min(xr)*2 max(xr)*2 min(yr)*2 max(yr)*2 min(zr)*2 max(zr)*2])
k=0;
for i=1:10:size(xe,1)
k=k+1;
if i==1,
h1r = line([xe(i) xyzp1(1,i)],[ye(i) xyzp1(2,i)],[ze(i) xyzp1(3,i)],...
’Marker’,’.’,’LineStyle’,’-’,’Color’,’b’);
h2r = line([xe(i) xyzp2(1,i)],[ye(i) xyzp2(2,i)],[ze(i) xyzp2(3,i)],...
’Marker’,’.’,’LineStyle’,’-’,’Color’,’k’);
h3r = line([xe(i) xyzp3(1,i)],[ye(i) xyzp3(2,i)],[ze(i) xyzp3(3,i)],...
’Marker’,’.’,’LineStyle’,’-’,’Color’,’g’);
else
set(h1r,’XData’, [xe(i) xyzp1(1,i)],’YData’,[ye(i) xyzp1(2,i)],...
’ZData’,[ze(i) xyzp1(3,i)])
set(h2r,’XData’, [xe(i) xyzp2(1,i)],’YData’,[ye(i) xyzp2(2,i)],...
’ZData’,[ze(i) xyzp2(3,i)])
set(h3r,’XData’, [xe(i) xyzp3(1,i)],’YData’,[ye(i) xyzp3(2,i)],...
’ZData’,[ze(i) xyzp3(3,i)])
end
F(k) = getframe;
writeVideo(mov,F(k))
end
close(mov);
return
27