Setpin(0, 0) Problem

This is where you talk about Macros, show examples of your macro scripting and SHARE handy segments of script code as examples.

Setpin(0, 0) Problem

Postby P_Pav » Wed Sep 29, 2021 1:06 pm

I'm looking for a way to edit the M31 macro in order to be able to keep an LED/Output pin high after performing the tool length measurement and then for another macro (Park 2/Tool Change Location) to switch it off. The main purpose is to able to change the tool at the Park 2 position and then press the Tool Length measure button to measure the tool with an M31 macro and after it's been measure I want the macro to set the pin high permanently until I press the M201 button after which it would clear the pin state/ return it to low. So I would know if the tool's been measure or not.

I added "Setoutpin(x, y);" at the end of the M31 macro but it just flickered on for a split second and then went off, presumably when the macro finished running an the tool length moves were still in progress.

My C Sharp skill are too basic to work out why the macro resets the state of the pins back to low after it runs.

Anyone got any ideas for this? Ideally I also like to run the macros M200 and M201 and have them keep an output high until the head is moved from those positions but for now I'll be happy to just get the output for the LED on my physical tool height measure button to stay on after the tool measuring process has finished and is complete so I know that tool has been measured.
P_Pav
 
Posts: 8
Joined: Sun Sep 27, 2020 12:55 am

Re: Setpin(0, 0) Problem

Postby dezsoe » Wed Sep 29, 2021 2:55 pm

Setoutpin works fine, but I think you selected an output which is controlled by another function and that is why it turns off. Enable and show the Pin mapping plugin which shows you the pin assignments. (I removed the other thread as you asked.)
dezsoe
 
Posts: 2093
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Re: Setpin(0, 0) Problem

Postby P_Pav » Wed Sep 29, 2021 10:33 pm

You're right...

I used the pin mapping plugin and it was being used by some other output that I had forgotten to remove.

May I now ask another question that relates directly to the one above...

I'll include the macro M31 below for all to see, it's not written by me but I've managed to work out where to put the Setoutpin(x, x) but it would be better if there was a conditional statement that only allows the Setoutpin function to run only after and if the AS3.Setfield and AS3.Validtefield have been completed. Currently if I press the Tool Measure button and press Cycle Stop before the tool has been measured the Setoutpin function runs and turn the LED on indicating that the tool has been measured which has the potential to be a false indication.

I am assuming it should be a simple snippet of code with a simple 'if' statement.

I'd also be interested to know if there is any way to have an output in high or low depending upon the current position of the machine. Eg. If the machine is parked at Park Position 1, 900,500,100 the LED/Output pin goes high and whenever it's not at that position it's off/low.



Anyway here's the M31 macro code I'm currently using...


Code: Select all
//M31 Probing Macro


//Fixed Position Tool Sensor

double probeX = 886.229;
double probeY = 501.017;

//Mobile Position Sensor
//double probeX = 31.75;
//double probeY = 31.75;


double xyFeedrate = 6000;
double Zmin = -142;
double Feedrate = 400;
double Feedrateslow = 100;
double Slowretract=5;
double SafeZ = -5;
double retractheight = 80;


// Standard MDF 40mm Pitch Bed
double platethick = 33.85;

// Trespa 16mm Pitch Bed @ 15.42mm Thick
//double platethick = 18.61;

// Homed Check
if(!exec.GetLED(56)||!exec.GetLED(57)||!exec.GetLED(58)) // If machine was not homed then it is unsafe to move in machine coordinates, stop here...
{
  MessageBox.Show("The machine was not yet homed, home the machine before run to parking position!");
  exec.Stop();
  return;
}

while(exec.IsMoving()){}
exec.Wait(200);

double Xoriginalpos = exec.GetXmachpos(); // Get the current machine coordinates
double Yoriginalpos = exec.GetYmachpos(); // Get the current machine coordinates

exec.Code("G00 G53 Z" + SafeZ); // Move Z up first
while(exec.IsMoving()){}

exec.Code("G01 G53 F" + xyFeedrate +" X" + probeX +" Y" + probeY); // Move to the probe sensor position in XY
while(exec.IsMoving()){}

exec.Code("G31 Z" + Zmin + "F" + Feedrate); // Move to the probe sensor position in XY
while(exec.IsMoving()){}
exec.Wait(200);

double Zupslow = exec.GetZmachpos() + Slowretract;
if(Zupslow > SafeZ)
{
  Zupslow = SafeZ;
}
exec.Code("G00 G53 Z" + Zupslow); // Move to slow clearance plane
while(exec.IsMoving()){}
exec.Wait(1000);

exec.Code("G31 Z" + Zmin + "F" + Feedrateslow); // Move to the probe sensor position in XY
while(exec.IsMoving()){}
exec.Wait(200);

AS3.Setfield(platethick, 228); //Sets the value of the z current coordinate field to 'platethick'
AS3.Validatefield(228); //Validates the 'platethick' valuefor the z current coordinate field  with writting the offset coordinates as nessessary.

//------------------------------------------------------------------------------------------------------------------

exec.Setoutpin(3, 14); // Turns on the Tool Measured LED

// The code to set output pin (3, 14) should only run if the 2 lines above it, starting with "AS3." have been executed and not before in order to prevent the pin going high if the tool measurment process is interupted by a 'cycle stop'. I would assume there is some snippet of C# that checks if something's been done and if it has it will run the Setoutpin line.

//------------------------------------------------------------------------------------------------------------------

 double Zup = exec.GetZmachpos() + retractheight;
 if(Zup > SafeZ)
 {
   Zup = SafeZ;
 }
 exec.Code("G00 G53 Z" + Zup); // Move 1inch above probe plate
 while(exec.IsMoving()){}
 exec.Wait(1000);

 exec.Code("G01 G53 F" + xyFeedrate +" X" + Xoriginalpos +" Y" + Yoriginalpos); // Move back to the original XY position



If you need any more information just let me know.

Many thanks once again.
P_Pav
 
Posts: 8
Joined: Sun Sep 27, 2020 12:55 am


Return to Macros

Who is online

Users browsing this forum: No registered users and 1 guest