-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathisMotorMoving.m
More file actions
executable file
·49 lines (38 loc) · 1022 Bytes
/
isMotorMoving.m
File metadata and controls
executable file
·49 lines (38 loc) · 1022 Bytes
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
function [ out ] = isMotorMoving( s, id )
% Function returns 1 if motor is moving or 0 if motor is not moving.
% create a command packet
packet=[255, 255, id, 4, 2, 46, 1];
packet = [packet 255-(mod(sum(packet(3:end)),256))];
% number of trials
j=3;
while true
% empty serial port buffer
if(s.BytesAvailable~=0)
fread(s, s.BytesAvailable);
end
% send the command packet
fwrite(s,uint8(packet));
% read status packet with reply
status=getStatusPacket(s);
% if checksum is OK, break out of the loop
if CSCheck(status)
break;
else
disp('isMotorMoving: CS is not correct!!!')
disp(['trial number: ' num2str(j)])
disp(status)
if j<=1
out=NaN;
return;
end
j=j-1;
end
pause(0.3);
end
% get the answer
out=status(6);
if out~=0 && out ~=1
disp('isMotorMoving: wrong output!!!')
disp(['motors ID: ' num2str(id)])
end
end