-
Notifications
You must be signed in to change notification settings - Fork 1
/
motorHold.m
90 lines (81 loc) · 3.48 KB
/
motorHold.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
function motorHold(handles, v);
% Control motor position-hold-before-reset: 'on', 'off', 'resetXY',
% 'resetZ'
global STL;
hSI = evalin('base', 'hSI');
if strcmp(v, 'on')
if STL.print.nmetavoxels(3) > 1
% If we've printed more than 1 metavoxel (lens FOV) high, we
% risk crushing what we just printed. Remind the user.
set(handles.crushThing, 'BackgroundColor', [1 0 0]);
STL.print.motor_reset_needed = true;
end
%%%%%% FIXME Disabled! STL.print.FastZhold = true;
%STL.print.FastZhold = true;
%warning('Disabled fastZ hold hack.');
STL.print.motorHold = true;
STL.motors.mom.tmp_origin = move('mom');
if STL.motors.hex.connected
[~, b] = STL.motors.hex.C887.qKEN('');
if ~strcmpi(b(1:5), 'LEVEL')
hexapod_wait();
STL.motors.hex.C887.KEN('ZERO');
end
STL.motors.hex.tmp_origin = hexapod_get_position_um();
end
end
if strcmp(v, 'off')
STL.print.motorHold = false;
STL.print.motor_reset_needed = true;
end
if strcmp(v, 'resetXY')
if isfield(STL.motors.mom, 'tmp_origin')
hSI.hMotors.motorPosition(1:2) = STL.motors.mom.tmp_origin(1:2);
end
if isfield(STL.motors.hex, 'tmp_origin')
if STL.logistics.simulated
STL.logistics.simulated_pos(1:2) = STL.motors.hex.tmp_origin(1:2);
elseif STL.motors.hex.connected
% If the hexapod is in 'rotation' coordinate system,
% wait for move to finish and then switch to 'ZERO'.
[~, b] = STL.motors.hex.C887.qKEN('');
if ~strcmpi(b(1:5), 'LEVEL')
hexapod_wait();
STL.motors.hex.C887.KEN('ZERO');
end
move('hex', STL.motors.hex.tmp_origin(1:2));
end
end
%STL.print.motorHold = false;
%STL.print.motor_reset_needed = false;
%set(handles.crushThing, 'BackgroundColor', 0.94 * [1 1 1]);
set(handles.messages, 'String', 'Restored XY position but not Z position. Crush the thing?');
end
if strcmp(v, 'resetZ')
%hSI.hFastZ.goHome; % This takes us to 0 (as I've set it up), which is not what we
%want.
hSI.hFastZ.positionTarget = STL.print.fastZhomePos;
% Don't use MOVE, since I haven't written MOVE to just move Z.
if isfield(STL.motors.mom, 'tmp_origin')
hSI.hMotors.motorPosition(3) = STL.motors.mom.tmp_origin(3);
end
if isfield(STL.motors.hex, 'tmp_origin')
if STL.logistics.simulated
STL.logistics.simulated_pos(3) = STL.motors.hex.tmp_origin(3);
elseif STL.motors.hex.connected
% If the hexapod is in 'rotation' coordinate system,
% wait for move to finish and then switch to 'ZERO'.
[~, b] = STL.motors.hex.C887.qKEN('');
if ~strcmpi(b(1:5), 'LEVEL')
hexapod_wait();
STL.motors.hex.C887.KEN('ZERO');
end
STL.motors.hex.C887.MOV('Z', STL.motors.hex.tmp_origin(3)/1e3);
end
end
STL.print.motorHold = false;
STL.print.motor_reset_needed = false;
set(handles.messages, 'String', '');
set(handles.crushThing, 'BackgroundColor', 0.94 * [1 1 1]);
end
end