-
Notifications
You must be signed in to change notification settings - Fork 0
/
simulateFlip.m
44 lines (31 loc) · 1.51 KB
/
simulateFlip.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
38
39
40
41
42
43
44
function cost = simulateFlip(TrajectoryParams,WaypointTime,FlipTime,plotting,videoFWrite)
tic
global counter
counter = counter + 1;
% Simulation parameters
% plotting = false;
tmax = FlipTime*1.5;
interpolationpoints = 500;
% Create cubic spline input
time = linspace(0,FlipTime,interpolationpoints);
PitchInput = [time; (pi/180)*ppval(spline(WaypointTime,TrajectoryParams(1:numel(WaypointTime))),time)]';
assignin('base','PitchInput',PitchInput);
RollInput = [time; (pi/180)*ppval(spline(WaypointTime,TrajectoryParams(numel(WaypointTime)+1:end)),time)]';
assignin('base','RollInput',RollInput);
run TailobaticVariables
warning off;
simoutput = sim('TailFlip2DOF');
% simout = simoutput.simout;
assignin('base','simout',simout);
run ProcessTailobatics
warning on
Angles = [BodyRoll, BodyPitch, BodyYaw];
AngularVelocity = [BodyRollVelocity, BodyPitchVelocity, BodyYawVelocity];
DesiredAngles = [0, 0, pi/6];
AngleWeights = [1 1 1]; % Weighting for angles to prioritise one axis.
AngleError = sum(abs(abs(Angles(end,:))-DesiredAngles).*AngleWeights);
VelocityError = sum(abs(AngularVelocity(end,:).*AngleWeights));
cost = AngleError + VelocityError + TailTravel;
disp(['Angle error: ' num2str(AngleError) ', cost function: ' num2str(cost)])
disp(['Simulation count ' num2str(counter) ', duration: ' num2str(toc) 's.'])
end