please help me I want to command the valve on-off with G-code at the mark point I want, where I have 324 mark positions. and make it loop until 324 positions are complete
2 次查看(过去 30 天)
显示 更早的评论
for i=1:11
tar_point=['X',num2str(pos(i,1)),' Y',num2str(pos(i,2)),' Z',num2str(pos(i,3))];
comd1=['G01 F200 ',tar_point];
writeline(s,'M03 on') ;
writeline(s,comd1);
pause(1.0);
writeline(s,'M05 off') ;
end
%Each mark point is in the pos variable.
0 个评论
回答(1 个)
Vaibhav
2023-10-19
Hi Matthew,
I understand that you would like to loop over for 324-mark positions.
You can update the code by replacing "for i = 1:11" with "for i = 1:324"; this change ensures the loop encompasses all 324 mark positions and the rest of the code remains the same.
You can refer to the updated code below:
for i = 1:324
% Create a G-code command for the target point
tar_point = ['X', num2str(pos(i, 1)), ' Y', num2str(pos(i, 2)), ' Z', num2str(pos(i, 3))];
comd1 = ['G01 F200 ', tar_point];
% Send commands to turn on the valve (M03), move to the target point, and turn off the valve (M05)
writeline(s, 'M03 on');
writeline(s, comd1);
pause(1.0); % Pause for 1 second (adjust as needed)
writeline(s, 'M05 off');
end
You can refer to below MathWorks documentation to know more about "for" loop to repeat specific number of times:
Hope this helps!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Robotics 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!