root / branches / 16299_s10 / matlab / computeTrajectories.m @ 1816
History | View | Annotate | Download (873 Bytes)
1 |
% For now I am ignoring ThetaD and just computing an arc |
---|---|
2 |
% This function expects to NOT have the quees be at index 1 |
3 |
function [V,W] = computeTrajectories(X,Y,Theta,XD,YD,ThetaD,XYError,ThetaError,LastV,LastW) |
4 |
|
5 |
Kp = 1/7; |
6 |
Ki = 1/100; |
7 |
Kd = 1/30; |
8 |
|
9 |
% how far away are we |
10 |
dists = sqrt((X-XD).^2 + (Y-YD) .^ 2); |
11 |
|
12 |
|
13 |
for idx=1:size(X,1) |
14 |
%V(idx) = dists(idx)/Kp; % linear velocity is proportional to distance |
15 |
%W(idx) = (ThetaD(idx) - Theta(idx))/Kp; |
16 |
curXYError = cos(Theta(idx))*(XD(idx) - X(idx)) + sin(Theta(idx))*(YD(idx) - Y(idx)); |
17 |
curThetaError = (-sin(Theta(idx))*(XD(idx) - X(idx)) + cos(Theta(idx))*(YD(idx) - Y(idx))); |
18 |
XYError(idx) = XYError(idx) + curXYError; |
19 |
ThetaError(idx) = ThetaError(idx) + curThetaError; |
20 |
V(idx) = curXYError*Kp + XYError(idx)*Ki + LastV(idx)*Kd; |
21 |
W(idx) = curThetaError*Kp + ThetaError(idx)*Ki + LastW(idx)*Kd; |
22 |
end |
23 |
|
24 |
|
25 |
end |