-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsendTattoo.m
More file actions
58 lines (53 loc) · 1.49 KB
/
sendTattoo.m
File metadata and controls
58 lines (53 loc) · 1.49 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
function sendTattoo(cyPath)
%Definitions
yOffset = -40;
dis2cen = 60;
rOffset = -20;
pulsesPerRev = 200;
degreesPerRev = 2*pi;
pitch = 8; %mm/rev
thetaN2 = 520;
thetaN1 = 20;
%Get data in pulses
thetaPulses = cyPath(:,2)*thetaN2*pulsesPerRev/thetaN1/degreesPerRev;
thetaPulses = round(thetaPulses);
yPulses = (cyPath(:,3)+yOffset)*pulsesPerRev/pitch;
yPulses = round(yPulses);
rPulses = dis2cen-cyPath(:,1)+rOffset;
rPulses = rPulses*pulsesPerRev/pitch;
rPulses = round(rPulses);
pathPulses = [rPulses,thetaPulses,yPulses];
%open serial connection
%if theres an error delete s from workspace and rerun
s = serialport("COM3",115200);
%increase timout
s.Timeout = 100000;
n = size(pathPulses,1);
%loading
fig = uifigure;
d = uiprogressdlg(fig,'Title','Tattooing',...
'Message','In Progress','Cancelable','on');
drawnow
%send over serial
for ii=1:n
if ~mod(ii+1,20)
d.Message = sprintf('Progress: %0.1f %% ',ii*100/n);
end
%Update progress and cancel from UI
d.Value = ii/n;
if d.CancelRequested
break
end
%write points to UART
write(s, pathPulses(ii,:), 'uint16');
%wait for acknowledge
ack = read(s,1,'uint8');
%check ack
if(ack ~= 'a')
error('Invalid acknowledge from MCU')
end
end
clear s
close(d);
close(fig);
end