(old)Matlab

% All Dimensions in milimeters [mm] !!! %

clear all;
clc;
close;
spd=1; % StepsPerDecimeter
motor_step=0.5;

L=1140;
Initial_length=1000;
l1(1)=Initial_length;
l2(1)=Initial_length;
step=sqrt(l1(1)^2-(L/2)^2)-sqrt((l1(1)+motor_step)^2-(L/2)^2);
x(1)=L/2;
y(1)=sqrt(Initial_length^2-(L/2)^2);
disp(x(1));
disp(y(1));

s=serial(‘COM4′); % Creates a serial object
fopen(s); % Opens serial communications with the Arduino

% String (str) generation start %
% len=200;
% for k=1:len
%     str(k)=’s’;
% end
% for k=length(str):length(str)+len;
%     str(k)=’d’;
% end
% for k=length(str):length(str)+len;
%     str(k)=’a’;
% end
% for k=length(str):length(str)+len;
%     str(k)=’s’;
% end

% String generation end %

str=’qqddaass’; % Here you can paste any string you like
% JUST REMEBER TO SHUTTHE STRING GENERATION OFF !!!

for i=2:length(str) %runs
ch=str(i);
%ch=input(‘Enter Q A S D (?):’,’s’);
%clc;
% calculates the movements in X and Y
if ch==’q’
y(i)=y(i-1)+step;
x(i)=x(i-1);
end
if ch==’a’
y(i)=y(i-1)-step;
x(i)=x(i-1);
end
if ch==’s’
x(i)=x(i-1)-step;
y(i)=y(i-1);
end
if ch==’d’
x(i)=x(i-1)+step;
y(i)=y(i-1);
end

% Calculates the lengths of the wires
l1(i)=sqrt(x(i)^2+y(i)^2);
l2(i)=sqrt((L-x(i))^2+y(i)^2);
%     disp(l1(i));
%     disp(l2(i));
step=0.5;

%step=abs(sqrt(l1(i)^2-(L/2)^2)-sqrt((l1(i)+motor_step)^2-(L/2)^2));

%     disp(x(1));
%     disp(y(1));
if l1(i)<l1(i-1)
fprintf(s,’7′);
end
if l1(i)>l1(i-1)
fprintf(s,’4′);
end
if l2(i)<l2(i-1)
fprintf(s,’9′);
end
if l2(i)>l2(i-1)
fprintf(s,’6′);
end
end

close;
plot(x,y);

% jj=input(‘delay…’);
fclose(s); % Closes serial communications
clc;
% close;
% clear all;
disp(‘***’);
disp(‘*** Keer run finished successfully!’);

Leave a Reply

Your email address will not be published. Required fields are marked *