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

조회 수: 1 (최근 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.

답변 (1개)

Vaibhav
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!

카테고리

Help CenterFile Exchange에서 Robotics에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by