Mpg enable

If you have a question about the software please ask it here.

Mpg enable

Postby Battwell » Tue Apr 03, 2018 11:28 pm

I just fitted a hard wired mpg
It works really smoothly after a bit of tweaking.
When selecting an axis x y or z everything is nice
But if I switch to none of the above the last used axis is still active.( I only have xyz wired)
Can you confirm this is correct. I'd prefer if it any axis was only active if selected so there's no chance of movement while putting the mpg back on its hanger for example if I accidentally knock the wheel
Uc300eth on router and mill.
UK uccnc powered machine sales. https://cncrouter.uk/atc-cnc-routers.htm
Automateanything/duzzit cnc/mercury cnc
Battwell
 
Posts: 819
Joined: Sun Sep 25, 2016 7:39 pm
Location: South Wales. Uk

Re: Mpg enable

Postby dezsoe » Wed Apr 04, 2018 9:15 am

Could you write some details? How do you select an axis, and how do you select none?
dezsoe
 
Posts: 2049
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Re: Mpg enable

Postby Battwell » Wed Apr 04, 2018 9:52 am

the axis selector has 5 positions
off,x,y,z,a
off is no connection. a is not connected- as not used -and i run out of cores in my available cable.
if i go from x to off - ie no input active in uccnc then the x axis remains active
if i go from z to a the z axis remains active
it would be nicer if only active inputs activated an axis - instead of it being sticky.

i can write it into a macro loop to only activate mpg multi if one of the 3 inputs are active / swapping back to continuous jog if they are non active which is probably going to be my work around for the moment.
Uc300eth on router and mill.
UK uccnc powered machine sales. https://cncrouter.uk/atc-cnc-routers.htm
Automateanything/duzzit cnc/mercury cnc
Battwell
 
Posts: 819
Joined: Sun Sep 25, 2016 7:39 pm
Location: South Wales. Uk

Re: Mpg enable

Postby dezsoe » Wed Apr 04, 2018 10:25 am

OK, I see. I made a macroloop for this some time ago:

Code: Select all
// ================================================================================================
// Mxxxxx - Macroloop: Read Yaxley - Axis and mode
// ================================================================================================
// 5-state Yaxley, 0, X, Y, Z, A (0 -> cont / other -> MPG multi)
// 0 has no input = none selected
// ================================================================================================

int currState = 0;
int readState = 0;

// =============== Prepare

if (ledMPGX == -1)
{
  ledMPGX = GetLEDNumber(portMPGX, pinMPGX);
  ledMPGY = GetLEDNumber(portMPGY, pinMPGY);
  ledMPGZ = GetLEDNumber(portMPGZ, pinMPGZ);
  ledMPGA = GetLEDNumber(portMPGA, pinMPGA);
}

// =============== Do it!

currState = (exec.GetLED(modeCont) ? 1 : 0);
currState = currState << 1 | (exec.GetLED(modeMPGMulti) ? 1 : 0);
for (int i = 0; i < 4; i++)
  currState = currState << 1 | (exec.GetLED(axisX + i) ? 1 : 0);

readState = readState << 1 | GetPinState(ledMPGX, negMPGX);
readState = readState << 1 | GetPinState(ledMPGY, negMPGY);
readState = readState << 1 | GetPinState(ledMPGZ, negMPGZ);
readState = readState << 1 | GetPinState(ledMPGA, negMPGA);

if ((readState & 0x0F) != 0x00)
  readState |= 0x10;
else
  readState = 0x20;                                                             // None selected -> Cont

// 0 0 C M X Y Z A

if (readState != currState)
{
  if ((readState & 0xF0) != (currState & 0xF0))
    switch (readState & 0xF0)
    {
      case 0x10:
        exec.Callbutton(btnMPGMulti);
        break;
      case 0x20:
        exec.Callbutton(btnCont);
        exec.AddStatusmessage("Mode: Continous");
        break;
    }
  if ((readState & 0xF0) == 0x10)
    switch (readState & 0x0F)
    {
      case 0x01:
        exec.Callbutton(btnAxisA);
        exec.AddStatusmessage("Mode: MPG Multi A");
        break;
      case 0x02:
        exec.Callbutton(btnAxisZ);
        exec.AddStatusmessage("Mode: MPG Multi Z");
        break;
      case 0x04:
        exec.Callbutton(btnAxisY);
        exec.AddStatusmessage("Mode: MPG Multi Y");
        break;
      case 0x08:
        exec.Callbutton(btnAxisX);
        exec.AddStatusmessage("Mode: MPG Multi X");
        break;
    }
}

// =============================================================================  -- Events --

#Events

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

// =============== LED constants

const int modeCont = 145;
const int modeMPGMulti = 154;
const int axisX = 155;

// =============== Button constants

const int btnCont = 161;
const int btnMPGMulti = 228;
const int btnAxisX = 220;
const int btnAxisY = 221;
const int btnAxisZ = 222;
const int btnAxisA = 223;

// =============== Inputs - Port, pin, negate

const int portMPGX = 1;
const int pinMPGX = 11;
const bool negMPGX = false;

const int portMPGY = 1;
const int pinMPGY = 15;
const bool negMPGY = false;

const int portMPGZ = 0;
const int pinMPGZ = 0;
const bool negMPGZ = false;

const int portMPGA = 0;
const int pinMPGA = 0;
const bool negMPGA = false;

// =============== Input LEDs

static int ledMPGX = -1;
static int ledMPGY = -1;
static int ledMPGZ = -1;
static int ledMPGA = -1;

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

// =============== Get LED number by port and pin

int GetLEDNumber(int port, int pin)
{
  int LED = -1;
  switch (port)
  {
    case 1:
      LED = pin;
      break;
    case 2:
      LED = 68 + pin;
      break;
    case 3:
      LED = 85 + pin;
      break;
    case 4:
      LED = 102 + pin;
      break;
    case 5:
      LED = 119 + pin;
      break;
  }
  return LED;
}

// =============== Get input state

int GetPinState(int led, bool neg)
{
  if (led == -1) return 0;
  bool ledState = exec.GetLED(led);
  return (ledState ^ neg ? 1 : 0);
}
dezsoe
 
Posts: 2049
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Re: Mpg enable

Postby Battwell » Wed Apr 04, 2018 10:44 am

thats long winded!
one if then , else and a 4 or lines would do the trick. :-)

il try it later
i still think that an axis shouldnt stay sticky as last axis selected though (in uccnc main program)
Uc300eth on router and mill.
UK uccnc powered machine sales. https://cncrouter.uk/atc-cnc-routers.htm
Automateanything/duzzit cnc/mercury cnc
Battwell
 
Posts: 819
Joined: Sun Sep 25, 2016 7:39 pm
Location: South Wales. Uk

Re: Mpg enable

Postby Battwell » Wed Apr 04, 2018 10:50 am

a video- shows how nice and smooth it can be run
https://www.youtube.com/watch?v=MBvUiwaubro
Uc300eth on router and mill.
UK uccnc powered machine sales. https://cncrouter.uk/atc-cnc-routers.htm
Automateanything/duzzit cnc/mercury cnc
Battwell
 
Posts: 819
Joined: Sun Sep 25, 2016 7:39 pm
Location: South Wales. Uk

Re: Mpg enable

Postby dezsoe » Wed Apr 04, 2018 10:58 am

Yes, you can do it shorter, but this has some error handling and easy to read or change. :)

If you play with input triggers, then you have to use both low and high state to trigger an axis select/cont. mode select pairs. But that won't work on program startup before the first state change. We tried it and the result was this code, because it is stable and optimized for fast running.

I always build state-machines in macroloop to prevent slow functions (e.g. button press) from running more than one time. Getting the current state and the input state, then comparing them is very fast, you cannot see any CPU load change when starting/stopping this kind of loops. (Only on first run when UCCNC compiles the macro.)
dezsoe
 
Posts: 2049
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Re: Mpg enable

Postby dezsoe » Wed Apr 04, 2018 11:06 am

I watched the video. My macroloop also switches between cont. mode and MPG multi, depending on the axis selected. (Which you had to select manually on the PC.) If you want I can post you the pair of this macroloop for the step selection.
dezsoe
 
Posts: 2049
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Re: Mpg enable

Postby Battwell » Wed Apr 04, 2018 11:09 am

good explanation. il be using your code (what i meant first time)
- if it saves me a 4 second walk back to the control panel im happy :-)
Uc300eth on router and mill.
UK uccnc powered machine sales. https://cncrouter.uk/atc-cnc-routers.htm
Automateanything/duzzit cnc/mercury cnc
Battwell
 
Posts: 819
Joined: Sun Sep 25, 2016 7:39 pm
Location: South Wales. Uk

Re: Mpg enable

Postby dezsoe » Wed Apr 04, 2018 11:27 am

OK, then here is the macroloop for the step selection:

Code: Select all
// ================================================================================================
// Mxxxxx - Macroloop: Read Yaxley - step
// ================================================================================================
// 3-state Yaxley: select 0.001, 0.01 és 0.1 step (may be 4-state for 1.0 too!)
// Only states-1 signal is connected, if none selected the step is set to 0.001
// ================================================================================================

int currState = 0;
int readState = 0;

// =============== Prepare

if (led001 == -1)
{
  led001 = GetLEDNumber(port001, pin001);
  led01 = GetLEDNumber(port01, pin01);
  led1 = GetLEDNumber(port1, pin1);
}

// =============== Do it!

currState = (exec.GetLED(step0001) ? 1 : 0);
currState = currState << 1 | (exec.GetLED(step001) ? 1 : 0);
currState = currState << 1 | (exec.GetLED(step01) ? 1 : 0);
currState = currState << 1 | (exec.GetLED(step1) ? 1 : 0);

readState = readState << 1 | GetPinState(led001, neg001);
readState = readState << 1 | GetPinState(led01, neg01);
readState = readState << 1 | GetPinState(led1, neg1);

if (readState == 0) readState = 0x08;                                           // None selected -> 0.001

if (readState != currState)
{
  switch (readState)
  {
    case 0x01:
      exec.Callbutton(btn1);
      exec.AddStatusmessage("Step: 1.0");
      break;
    case 0x02:
      exec.Callbutton(btn01);
      exec.AddStatusmessage("Step: 0.1");
      break;
    case 0x04:
      exec.Callbutton(btn001);
      exec.AddStatusmessage("Step: 0.01");
      break;
    case 0x08:
      exec.Callbutton(btn0001);
      exec.AddStatusmessage("Step: 0.001");
      break;
  }
}

// =============================================================================  -- Events --

#Events

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

// =============== LED constants

const int step0001 = 148;
const int step001 = 149;
const int step01 = 150;
const int step1 = 151;

// =============== Button constants

const int btn0001 = 241;
const int btn001 = 164;
const int btn01 = 165;
const int btn1 = 166;

// =============== Inputs - Port, pin, negate

const int port001 = 1;
const int pin001 = 11;
const bool neg001 = false;

const int port01 = 1;
const int pin01 = 15;
const bool neg01 = false;

const int port1 = 0;
const int pin1 = 0;
const bool neg1 = false;

// =============== Input LEDs

static int led001 = -1;
static int led01 = -1;
static int led1 = -1;

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

// =============== Get LED number by port and pin

int GetLEDNumber(int port, int pin)
{
  int LED = -1;
  switch (port)
  {
    case 1:
      LED = pin;
      break;
    case 2:
      LED = 68 + pin;
      break;
    case 3:
      LED = 85 + pin;
      break;
    case 4:
      LED = 102 + pin;
      break;
    case 5:
      LED = 119 + pin;
      break;
  }
  return LED;
}

// =============== Get input state

int GetPinState(int led, bool neg)
{
  if (led == -1) return 0;
  bool ledState = exec.GetLED(led);
  return (ledState ^ neg ? 1 : 0);
}
dezsoe
 
Posts: 2049
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Next

Return to Ask a question from support here

Who is online

Users browsing this forum: No registered users and 28 guests

cron