close all;
clear all;


CarriagePitch=260;
productFillSPeed=150;
LiNFillTimePerProductVolume=.7;
Seal3Time=.4;
BottleVolume=400;
BPM=450
PinchOffTime=.1;
SealTime=.4;
DistanceBetweenStations=400;



ProductFillTime=BottleVolume/productFillSPeed;
LiNFillTime=LiNFillTimePerProductVolume*ProductFillTime;

NumberOfLinkedCarriages=[5:.1:60];
Period=60*NumberOfLinkedCarriages/BPM;
TimeToMove=Period-ProductFillTime;
IndexDistance=CarriagePitch*NumberOfLinkedCarriages+DistanceBetweenStations;

%speed using trapezoid profile;
TrapSpeed=IndexDistance*3./(2*TimeToMove);
TrapAccel=TrapSpeed*3./TimeToMove;


%for 30 carriages, what is the effect of accel on speed;
numberOfLinkedCarriages=30;
AllowedAccel=[0:0.01:8]*9810;

a=-1./AllowedAccel;
b=60*NumberOfLinkedCarriages'/BPM;
c=-IndexDistance';

D=b.**2-4*c*a;

x1=(-b+sqrt(D))/(2*a);
x2=(-b-sqrt(D))/(2*a);

figure;
plot(NumberOfLinkedCarriages,TimeToMove,'LineWidth',2);
ax = gca();
set(ax, 'fontsize', 15);
%legend("AngledAxis","CrossDirAxis");
%xlabel("Number of linked carriages (#)");
ylabel("Time left to index (s)");
title("IndexTime");
grid;


figure;
subplot(2,1,1)
plot(NumberOfLinkedCarriages,TrapSpeed,'LineWidth',2);
ax = gca();
set(ax, 'fontsize', 15);
axis([min(NumberOfLinkedCarriages),max(NumberOfLinkedCarriages),0,20000]);
xlabel("Number of linked carriages (#)");
ylabel("Speed when using trapezoid profile (mm/s)");
title("Trapezoidal profile");
grid;

subplot(2,1,2)
plot(NumberOfLinkedCarriages,TrapAccel/9810,'LineWidth',2);
ax = gca();
set(ax, 'fontsize', 15);
axis([min(NumberOfLinkedCarriages),max(NumberOfLinkedCarriages),0,10]);
xlabel("Number of linked carriages (#)");
ylabel("Accel when using trapezoid profile (g)");
grid;