I want to close the valve in the position I set with the G-code. But what I found was that it was always closed and on.

1 次查看(过去 30 天)
for i=1:324
tar_point=['X',num2str(pos(i,1)),' Y',num2str(pos(i,2)),' Z',num2str(pos(i,3))];
comd1=['G01 F200 ',tar_point];
writeline(s,comd1)
pause(1.0)
comd2=['M03 on',tar_point];
writeline(s,comd2)
comd2=['M05 off',tar_point];
writeline(s,'M05 off')
end
  3 个评论
Walter Roberson
Walter Roberson 2022-3-8
编辑:Walter Roberson 2022-3-8
You have
comd2=['M05 off',tar_point];
but then you call
writeline(s,'M05 off')
ignoring the comd2 that you just created.
This is unlike what you did just above,
comd2=['M03 on',tar_point];
writeline(s,comd2)
where you construct a command and then use the command you constructed.
Also, I think it would be safer to have a space between the 'on' and the content of tar_point, as in
comd2=['M03 on ',tar_point];

请先登录,再进行评论。

回答(1 个)

Pratik
Pratik 2024-2-5
Hi Matthew,
As per my understanding, you're trying to control a valve using G-code commands in a MATLAB script. From your description, it appears that the valve is always on and not responding to the commands as you expect.
In the code provided, it can be observed that during command of ‘M05 off’ the “tar_point” variable is not getting passed as it has been done for above commands. Also, adding a pause in between commands gives time to actuate.
Pleas refer to the updated code which uses above suggestions:
for i = 1:324
tar_point = ['X', num2str(pos(i,1)), ' Y', num2str(pos(i,2)), ' Z', num2str(pos(i,3))];
% Move to the target point
comd1 = ['G01 F200 ', tar_point];
writeline(s, comd1);
pause(1.0)
comd2=['M03 on ',tar_point];
writeline(s,comd2)
pause(0.5); % Wait for the valve to turn on
comd2=['M05 off ',tar_point];
writeline(s,comd2)
pause(0.5); % Wait for the valve to turn off
end
I hope this helps.

类别

Help CenterFile Exchange 中查找有关 ROS Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by