-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMoveToWithRotation.m
38 lines (31 loc) · 1.19 KB
/
MoveToWithRotation.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
function [rul] = MoveToWithRotation(agent, aimPoint, rotatePoint, sCoef, minSpeed, vicinity, minAngularSpeed, P, I, D, eps, reset)
function [Speed] = linearSpeedFunction(dist)
speedCoef = 60;
if (dist > vicinity)
Speed = minSpeed + speedCoef * sCoef * dist;
else
Speed = 0;
end
end
function [angSpeed] = PIDAngFunction(angDiff)
persistent oldAngDiff;
persistent angDiffSum;
%global outBuffer;
if (isempty(oldAngDiff) || reset)
oldAngDiff = zeros(1, 12);
end
if (isempty(angDiffSum) || reset)
angDiffSum = zeros(1, 12);
end
if abs(angDiff) > eps
angSpeed = sign(angDiff) * minAngularSpeed + angDiff * P + angDiffSum(agent.id) * I + (oldAngDiff(agent.id) - angDiff) * D;
else
angSpeed = 0;
end
%outBuffer(13) = angSpeed;
oldAngDiff(agent.id) = angDiff;
angDiffSum(agent.id) = angDiffSum(agent.id) + angDiff;
end
Speed = MoveTo(agent, aimPoint, @linearSpeedFunction);
rul = Crul(Speed(1), Speed(2), 0, RotateTo(agent, rotatePoint, @PIDAngFunction), 0);
end