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 view (last 30 days)
Show older comments
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 Comments
Walter Roberson
on 8 Mar 2022
Edited: Walter Roberson
on 8 Mar 2022
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];
Answers (1)
Pratik
on 5 Feb 2024
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.
0 Comments
See Also
Categories
Find more on ROS Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!