我正在尝试使电动机运行,并且代码正在将正确的值发送给电动机,而电动机才刚刚不运行。我认为Movement1变量有问题。电机可以工作是因为我已经用另一个程序对其进行了测试,但是我很确定它与移动1值有关。
ScaleImage = imread('Images/Menu.jpg');
imshow(ScaleImage);
[xClick1,yClick1] = ginput(1)
Movement1 = xClick1
%Peanut butter
if Movement1>14.7 && Movement1<493
Movement1=2.75
end
%Jelly
if Movement1>500 && Movement1<1000
Movement1=8
end
%Honey
if Movement1>1123 && Movement1<1495
Movement1=13.75
end
pause(5)
if Movement1 == 2.75
MovementPB = 2
MovementJ = 0
MovementH = 0
end
if Movement1 == 8
MovementJ = 2
MovementPB = 0
MovementH = 0
end
if Movement1 == 13.75
MovementH = 2
MovementJ = 0
MovementPB = 0
end
try
s = serial('/dev/tty.usbmodem1421')
set(s,'BaudRate',115200)
fopen(s)
pause(2)
fprintf (s, 'G17 G20 G90 G94 G54')
pause(2)
CNCMotion = ['G1 x',num2str(Movement1), 'F10']
pause(2)
CNCMotion = ['G1 y',num2str(MovementJ), 'F10']
pause(2)
fprintf(s,CNCMotion)
catch ME
fclose(s)
ME.message
end