Need Help! Coolant M8 Rapids (Air Blast/Mister)

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

Need Help! Coolant M8 Rapids (Air Blast/Mister)

Postby Jasonrm1983 » Tue Jun 13, 2023 9:08 pm

Hi Everyone,
I have a 4x8 CNC that I made a while ago, and I finally got an air blaster for when I cut aluminum, etc...
So I need some help.

The code below I am trying to get up and working, but I am having issues with regard to the macro loop side of things. I have an air blaster/mister that uses siphoning. I have the solenoid and solid state relay tied to M8 (Flood), the pinout is Port 2 Pin 14 for the relay (C94 Board - ETH300). I am also using Garry's screen set 2022. When I use the macro loop the air blast stays on but only when, say, I set the Zheight for instance to 2, the solenoid goes on and off as it passes the desired number instead of staying off as it passes. I am using output triggers as well.

I used Dan911's macro below but modified it to try and get it working. Basically, this macro is to turn off coolant on rapids. I just want it to read that M8 is activated and to use the Z height to determine when to turn off the pinout and on, using the information from DRO Z Height. If anyone could come up with a solution to my problem that would be great!



Code: Select all
/ ================================================================================================
// Flood on/off  M8 and ZHeight
// ================================================================================================

double Zpos = AS3.Getfielddouble(228);
bool stateNow = ((Zpos < ZHeight) &&  (exec.GetLED(53)

 
 
  if(stateNow) {exec.Setoutpin(2, 14);}   

  else
 
  if(ButOnOff) {exec.Setoutpin(2, 14);}

else

{exec.Clroutpin(2, 14);}

// ================================================================================================

#Events

// ================================================================================================

const int Port = 2;     // Port number
const int Pin = 14;     // Pin number
const double ZHeight = 2; // Set  Z Height below on above off

Dan911
 
Posts: 613
Joined: Mon Oct 31, 2016 1:22 am
Location: USA
Top
Re: Coolant on/off on Rapids
Jasonrm1983
 
Posts: 18
Joined: Sat Mar 13, 2021 1:29 am

Re: Need Help! Coolant M8 Rapids (Air Blast/Mister)

Postby Jasonrm1983 » Wed Jun 14, 2023 12:28 am

...So I have got this to work...but it keeps going off and on repeatedly when below Z 0, but it should just be a solid on.


Code: Select all
// Flood on/off M8 and ZHeight

// Constants
const int Port = 2;           // Port number
const int Pin = 14;           // Pin number
const double ZHeight = 0.0;   // Set Z Height below to turn on, above to turn off

// Get Z position
double Zpos = AS3.Getfielddouble(228);

// Check if flood should be on or off
bool stateNow = (Zpos < ZHeight) && exec.GetLED(53);

// Control the flood
if (stateNow) {
    exec.Setoutpin(Port, Pin);  // Turn flood on
} else {
    exec.Clroutpin(Port, Pin);  // Turn flood off
}
Jasonrm1983
 
Posts: 18
Joined: Sat Mar 13, 2021 1:29 am

Re: Need Help! Coolant M8 Rapids (Air Blast/Mister)

Postby Jasonrm1983 » Wed Jun 14, 2023 2:50 am

Okay, I am back to square one but with a twist. I put the "script" as macro (M20303) and have it running as a macro loop. It works but only when it's not running a program for some reason it will activate one time when M8 is activated and turn on after passing negative Z 0 as it should but when it comes up to positive Z it just stays on, it should stay off... The ports and pins work fine if I am not running a program.

Here is Dan911 script I am using with my modifications...

Code: Select all
// ================================================================================================
// Switch output on Zheight and Mist/Flood is on
// ================================================================================================

double Zpos = AS3.Getfielddouble(228);
bool stateNow = Zpos < ZHeight &&  exec.GetLED(53);

if (lastState != stateNow)
{
lastState = stateNow;

if(stateNow)
{exec.Setoutpin(Port, Pin);
exec.Code("G4"+"P"+pause);
while(exec.IsMoving()){}
}   
  else
  {exec.Clroutpin(Port, Pin);}
}

// ================================================================================================

#Events

// ================================================================================================

const int Port = 2;                  // input  Port number
const int Pin = 14;                  // input  Pin number
const int pause = 0;                     //input Pause for mist/flood startup
static bool lastState = false;
const double ZHeight = 0;               // Set Z height for below on and above off
Jasonrm1983
 
Posts: 18
Joined: Sat Mar 13, 2021 1:29 am

Re: Need Help! Coolant M8 Rapids (Air Blast/Mister)

Postby dezsoe » Wed Jun 14, 2023 8:31 am

Where did you find this macro? I think it was uploaded to show how to do it, but the real operation was remarked. Here is a tested and working version:

Code: Select all
// ================================================================================================
// Switch output on Zheight and Mist/Flood is on
// ================================================================================================

double Zpos = exec.GetZpos();
bool stateNow = (Zpos < ZHeight) && exec.GetLED(52);

if (lastState != stateNow)
{
  lastState = stateNow;
  if (stateNow)
  {
    exec.Setoutpin(MistPort, MistPin);
    exec.AddStatusmessage("ON");
  else
  {
    exec.Clroutpin(MistPort, MistPin);
    exec.AddStatusmessage("OFF");
  }
}

// ================================================================================================

#Events

// ================================================================================================

const int MistPort = 1;                  // input  Port number
const int MistPin = 1;                  // input  Pin number
static bool lastState = false;
const double ZHeight = 0;               // Set Z height for below on and above off
dezsoe
 
Posts: 2093
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Re: Need Help! Coolant M8 Rapids (Air Blast/Mister)

Postby Jasonrm1983 » Wed Jun 14, 2023 4:28 pm

Yes, I found it in the macro section here, I believe from Dan911 !? or You!?. It works when jogging but half way working when a program is running.
Jasonrm1983
 
Posts: 18
Joined: Sat Mar 13, 2021 1:29 am

Re: Need Help! Coolant M8 Rapids (Air Blast/Mister)

Postby Jasonrm1983 » Wed Jun 14, 2023 4:37 pm

I tested this version it said it has errors. the other one has no errors


dezsoe wrote:Where did you find this macro? I think it was uploaded to show how to do it, but the real operation was remarked. Here is a tested and working version:

Code: Select all
// ================================================================================================
// Switch output on Zheight and Mist/Flood is on
// ================================================================================================

double Zpos = exec.GetZpos();
bool stateNow = (Zpos < ZHeight) && exec.GetLED(52);

if (lastState != stateNow)
{
  lastState = stateNow;
  if (stateNow)
  {
    exec.Setoutpin(MistPort, MistPin);
    exec.AddStatusmessage("ON");
  else
  {
    exec.Clroutpin(MistPort, MistPin);
    exec.AddStatusmessage("OFF");
  }
}

// ================================================================================================

#Events

// ================================================================================================

const int MistPort = 1;                  // input  Port number
const int MistPin = 1;                  // input  Pin number
static bool lastState = false;
const double ZHeight = 0;               // Set Z height for below on and above off
Jasonrm1983
 
Posts: 18
Joined: Sat Mar 13, 2021 1:29 am

Re: Need Help! Coolant M8 Rapids (Air Blast/Mister)

Postby dezsoe » Wed Jun 14, 2023 6:39 pm

Yes, sorry, I missed a }.

Code: Select all
// ================================================================================================
// Switch output on Zheight and Mist/Flood is on
// ================================================================================================

double Zpos = exec.GetZpos();
bool stateNow = (Zpos < ZHeight) && exec.GetLED(52);

if (lastState != stateNow)
{
  lastState = stateNow;
  if (stateNow)
  {
    exec.Setoutpin(MistPort, MistPin);
    exec.AddStatusmessage("ON");
  }
  else
  {
    exec.Clroutpin(MistPort, MistPin);
    exec.AddStatusmessage("OFF");
  }
}

// ================================================================================================

#Events

// ================================================================================================

const int MistPort = 1;                  // input  Port number
const int MistPin = 1;                  // input  Pin number
static bool lastState = false;
const double ZHeight = 0;               // Set Z height for below on and above off
dezsoe
 
Posts: 2093
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Re: Need Help! Coolant M8 Rapids (Air Blast/Mister)

Postby Jasonrm1983 » Wed Jun 14, 2023 10:10 pm

Thanks so much Dezsoe!
The above macro works awesome! Also, for those looking to use this just create a text file in your profile macro directory, name it something in the ranges of 20000~29999 just make sure no other macros are using these names. Set the "Get LED to (57) for M7 Mist or (53) M8 for flood, then configure your ports and pins below Event's, run as a Macroloop, done.
Jasonrm1983
 
Posts: 18
Joined: Sat Mar 13, 2021 1:29 am


Return to Macros

Who is online

Users browsing this forum: No registered users and 3 guests