User Tools

Site Tools


How to add mandatory Homing after Emergency Button and-or Servo ready alarm

For many CNC applications, it's very important to have precise machine position all the time. The homing procedure should be done to find the correct machine position if any servo driver fault happens or if the Emergency button is pressed.

Mandatory Homing procedure handler can be implemented with Software PLC:

NOTE: The homing procedure handler is OFF by default as it has the exit(99); line in the beginning of the program which immediately terminates the PLC as soon as it is started. In order to enable the homing procedure handler, add two forward slashes in front of the exit(99); line to comment it out so that the PLC can proceed uninterrupted:

There are Homing flags situated in global variables 7391-7399

Address Global variable Description
7391 X axis homing flag
7392 Y axis homing flag
7393 Z axis homing flag
7394 A axis homing flag
7395 B axis homing flag
7396 C axis homing flag

The flags are set automatically to “1” if

  1. The myCNC software has just loaded
  2. Emergency button has been pressed
  3. Corresponding Servo Ready alarm has been triggered

Software PLC Homing procedure handler monitors the flags and stops running G-code if any of the flags is set to 1.

 hx=gvarget(7391); //monitor axes flags X, Y, Z and C 
 hy=gvarget(7392) ;
 a++; if(a>9){a=1;};
 gvarset(99,c+b); //build variable to display which axis is not ready
 home=hx+hy+hz; //check if any of axis is not ready
 //home=hx+hy+hz+hc; //check if any of axis is not ready
 if (home!=0)  //if any of axis is not ready, then ...
  if (prg!=0) //Check if Program running is started and Stop it immediately
	gvarset(0xffffff,1); //Stop Program
  gvarset(9100,1); //display the message #1 on the screen, if any of home alarm activated
  gvarset(8160,2); //set XHC Homing display
  gvarset(9100,0); //hide the message #1, if everything's ok
  if (home_old!=home) //just home
     gvarset(8160,0); //set XHC Homing display

Writing a “1” to global variable #9100 will show Popup Message #0. Content to show in the Popup message should be programmed in the cnc-variables.xml configuration file.

myCNC software has configuration widget to add and setup a Popup Message Widget.

  • Press “+“ button to add new Popup Message description
  • Popup message # - ID number of popup message to show/hide. Global Variable numbers 9100…9200 are used to show hide the popup messages.
    For example, variable number 9114 is used to show Popup message with ID 14
  • Position X,Y - used to define Popup widget position on the screen. Popup message will be shown in the center, if Position x,y are not defined.
  • Size - defines size of Popup message widget
  • Header, Message, Footer - Popup message widget contains 3 sections to show a message. You can define text for each section (Header, Message, Footer). Section Size (width, height) and Font size can be defined for each section as well.
  • Button Image, Size, Action - Popup message may have a button at the bottom of the popup widget. A button image file, button size and action should be defined to get the button appeared in the widget.
  • Hide timeout - (under developing) Popup message may disappear automatically after given timeout
  • Variable - One of text lines (header, message or footer) may contain C-style format section to print variable value. If this section is present, then a variable, defined here, is printed. For example, Variable #99 will be printed in “Footer” section according to the screenshot above.
  • K - ratio to print the variable value. For example, if “K=0.001” and Variable value is “5000”, the value “5” will be printed (5000*0.001=5)
Popup message example is shown below

There is description below of the Popup message definition in the XML for those who like to low-level edit XML. However, this is not necessary since we added popup description in the configuration.

 <value name="cnc-popup-message-0" 
 width="600" height="300" 
 buttonImage="machine-home-find-all" buttonWidth="80"
 buttonHeight="80" buttonAction="direct-run:M138" 
 header="Machine position lost due to either Emergency Stop or Servo Alarm" 
 headerHeight="40" headerFontSize="16" 
 message="Please run Homing" fontSize="20" 
 footer="[%d]" footerFontSize="20" footerHeight="20" 
 timeout="5" dest="cnc-gvariable-99" K="1">0</value>

A popup message has 3 sections -

  • header,
  • message,
  • footer

For each section can be set up

  • section text
  • section font family, size and style
  • section height and width

The popup message may contain a button to run something. The button has attributes

  • buttonImage - skin image for the button
  • buttonWidth - the button width in px
  • buttonHeight - the button height in px
  • buttonAction - action for button pressed event

Any of message section may show global variable value to show for example current state or build countdown timer.

  • dest attribute defines which variable to show
  • K attribute defines show ratio for the variable value
  • section message should contain C-like format string, for example, ”%d” will print the value only as integer value

How to disable the Homing Popup Message

Homing handler has done through Software PLC procedure “HOMING_HANDLER.plc” as described.

If you need to disable the procedure and remove completely the Popup message widget, then add


command at the start of the procedure “HOMING_HANDLER” in Software PLC. Exit call is commented by default, you can just remove comment part. You need to press “Save Code” button and restart the software to apply the changes.

Homing Handler DISABLED (No popup message)


Homing Handler ENABLED (Homing popup message at the start of the software or after Emergency button pressed)

plc/how_to_add_mandatory_homing_after_emergency_button_and-or_servo_ready_alarm.txt · Last modified: 2019/09/05 13:24 by ivan

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki