User Tools

Site Tools


plc:plc

PLC - programmable logic controller.

PLC controller can load and run small binary programs (PLC procedures). PLC procedure should be wrirtten in simplified C-like language, compiled and stored in PLC controller memory to be ready to run. myCNC software includes PLC Builder - tiny IDE (Integrated Development Environment) to create and modify PLC procedure source files, compile them to binary code and upload it as RomFS iso image disk to PLC controller memory.

myCNC control has 2 types of built-in PLC systems that named Hardware PLC and Software PLC

Hardware PLC

“Hardware PLC” means PLC system runs inside CNC control board and able to access directly to CNC controller peripherals (inputs, outputs, PWMs, DACs, ADCs etc). PLC has also API to access to Motion Controller of myCNC control board, so positioning commands are possible from Hardware PLC.

Hardware PLC is a tiny virtual machine that runs pre-compiled PLC procedures. PLC procedure can be started from

  • G-code program M-code
  • On-screen button
  • Input Pin
  • From TCP Ethernet Socket through Server API

Running Motion commands from PLC

Hardware PLC Examples

Gas Cutting Control implementation

API to work with Modbus devices from PLC

THC API

Software PLC

“Software PLC” means PLC system runs inside myCNC software and controls CNC controllers peripherals through Software API.

Main advantage of Software PLC is multitasking. All PLC procedures are running simultaneously and independent each other.

Software PLC cycle time is 100ms, so Software PLC is suitable for wide range of slow applications like automatic lubricant control, fume exhaust control, alarm sensors control etc.

Software PLC Examples

Language Core for Software and Hardware PLC are almost the same so language syntax is pretty the same and similar to C-language but VERY VERY stripped down.

PLC Language

PLC predefined variables
  • var00var15 : This variables are initialised before PLC procedure start from values defined in plc-variables.xml file.
  • proc : proc variable value can be displayed on myCNC screen with display name “display-plc-proc” and can be used to show current status of PLC procedure
  • message : If message value set to non-zero value, PLC controller will send a message to myCNC Control Core or myCNC software with parameters defined in variables message, var00 (usually defined as command as well) and var01 (defined as parameter). This way PLC controller can communicate with Motion Controller and Host Software. Message variable is handled and cleared by PLC controller while “loop” operation, so message variable assign usually followed by short timeout loop like
    timer=2;do{timer--;}while(timer>0);

    Examples:

    //send to myCNC software information spindle speed is "0"
    command=PLC_MESSAGE_SPINDLE_SPEED_CHANGED;
    parameter=0;
    message=PLCCMD_REPLY_TO_MYCNC;
    timer=2;do{timer++;}while (timer>0);
    //Probing for Plasma Cutting.
    g0moveA(0x0,0x4,0-30000);                  //Start move down
    do { code=gvarget(6060); }while(code!=0);  //Wait till Motion Controller confirm moving started
    do{
     code=gvarget(6060);               //check Motion Controller (MC) current status
     sens=portget(INPUT_IHC);          //and check Probe input 
     if (sens==0)
     {
       message=PLCCMD_LINE_STOP;       //Send to MC command to Stop current line and wait next command
       code=1;                         //Set flag to exit from the loop
     };
    }while (code==0);                  //Exit from loop is motion finished OR Probe sensor pressed 
PLC defines
Name Value Comment
PLCCMD_MOTION_CONTINUE 1001
PLCCMD_MOTION_SKIP 1002
PLCCMD_MOTION_SOFT_SKIP 1003
PLCCMD_MOTION_PAUSE 1004
PLCCMD_PLC_PAUSE 1005
PLCCMD_PLC_FORK_PAUSE 1006
PLCCMD_LINE_SOFT_STOP 1007
PLCCMD_LINE_STOP 1008
PLCCMD_REPLY_TO_MYCNC 1100
PLCCMD_SET_CNC_VAR 1010
PLCCMD_SET_THC_VAR 1011
PLCCMD_SET_DEVICE_VAR16 1012
PLCCMD_SET_DEVICE_VAR32 1014
PLCCMD_SET_CNC_EXTVAR 1020
PLCCMD_MOTION_ABORT 1032
PLCCMD_MOTION_BREAK 1033
PLCCMD_SAVE_POS 1040
PLCCMD_THC_START 1050
PLCCMD_THC_STOP 1051
PLCCMD_THC_PAUSE 1052
PLCCMD_THC_CONTINUE 1053
PLCCMD_WATCHBIT1_ON 1060
PLCCMD_WATCHBIT2_ON 1061
PLCCMD_WATCHBIT3_ON 1062
PLCCMD_WATCHBIT4_ON 1063
PLCCMD_TRIGGER1_ON 1060
PLCCMD_TRIGGER2_ON 1061
PLCCMD_TRIGGER3_ON 1062
PLCCMD_TRIGGER4_ON 1063
PLCCMD_TRIGGER1_OFF 1064
PLCCMD_TRIGGER2_OFF 1065
PLCCMD_TRIGGER3_OFF 1066
PLCCMD_TRIGGER4_OFF 1067
PLCCMD_WATCHBIT1_OFF 1064
PLCCMD_WATCHBIT2_OFF 1065
PLCCMD_WATCHBIT3_OFF 1066
PLCCMD_WATCHBIT4_OFF 1067
PLCCMD_WATCHBIT5_ON 1068
PLCCMD_WATCHBIT6_ON 1069
PLCCMD_WATCHBIT7_ON 1070
PLCCMD_WATCHBIT8_ON 1071
PLCCMD_WATCHBIT5_OFF 1072
PLCCMD_WATCHBIT6_OFF 1073
PLCCMD_WATCHBIT7_OFF 1074
PLCCMD_WATCHBIT8_OFF 1075
PLCCMD_WAIT_FOR_CAMERA 1090
PLCCMD_WAIT_VARSET 1091
PLCCMD_WAIT_VARCLEAR 1092
PLCCMD_CAMERA_START 1093
PLCCMD_CAMERA_FINISH 1094
PLCCMD_PLC_DEBUG 1098
PLCCMD_PLC_RESTART 1099
PLC_BROADCAST_INQUIRY0 1200
PLC_BROADCAST_INQUIRY1 1201
PLC_BROADCAST_INQUIRY2 1202
PLC_BROADCAST_INQUIRY3 1203
PLC_BROADCAST_INQUIRY4 1204
PLC_BROADCAST_INQUIRY5 1205
PLC_BROADCAST_INQUIRY6 1206
PLC_BROADCAST_INQUIRY7 1207
PLC_BROADCAST_INQUIRY8 1208
PLC_BROADCAST_INQUIRY9 1209
PLC_BROADCAST_INQUIRY10 1210
PLC_BROADCAST_INQUIRY11 1211
PLC_BROADCAST_INQUIRY12 1212
PLC_BROADCAST_INQUIRY13 1213
PLC_BROADCAST_INQUIRY14 1214
PLC_BROADCAST_INQUIRY15 1215
PLC_BROADCAST_OK 1220
PLC_BROADCAST_ABORTED 1221
PLCCMD_MODBUS_SPINDLE_SPEED 1230
PLCCMD_MODBUS_SPINDLE_CMD 1231
PLCCMD_SET_PIDTIME 1240
PLC processes named
PLC process name Value Comment
plc_proc_check_plasma 10
plc_proc_venting 11
plc_proc_start_power 12
plc_proc_cooling 14
plc_proc_plasma 15
plc_proc_wait_plasma 18
plc_proc_pierce 27
plc_proc_no_plasma 62
plc_proc_check_preflow 16
plc_proc_check_cutflow 17
plc_proc_check_gases 23
plc_proc_test_out 24
proc_m_function 30
proc_zeroing 32
plc_proc_probing 33
plc_proc_ignition 50
plc_proc_preheat 51
plc_proc_soft_start 52
plc_proc_piercing 53
plc_proc_flame 54
plc_proc_cutting 60
plc_proc_purge 61
plc_proc_no_cutting 62
plc_proc_moveup 65
plc_proc_spindle 70
plc_proc_idle 0
PLC exit codes list.

Normally PLC procedure should return code 99.

exit(99);

In case Error happened PLC procedure may return erroe code. MyCNC software will catch exit code and report about Error if error code is in PLC exit codes list.

Exit code name Value Comment
plc_process 0 exit code is zero when PLC process is not finished yet
plc_exit_gas_fail 2 PLC aborted, No air pressure sensor
plc_exit_plasma_timeout 3 PLC aborted, No Arc sensor signal Timeout
plc_exit_plasma_fail 4 PLC aborted, PLC Plasma Start cutting procedure error
plc_exit_alarm_key 5 PLC aborted, Emergency key pressed
plc_exit_coolant_fail 6 PLC aborted, No Coolant flow sensor
plc_exit_probe_error 7 PLC aborted, No signal from probe sensor
plc_exit_motor_shorted 8 PLC aborted, Motor short circuit detected (ET2/ET4 boards)
plc_exit_broadcast_error 10 Error send broadcast message in multi-device configuration
plc_exit_normal 99 Normal exit
plc_exit_extern_break 100 PLC procedure aborted from outside of PLC core
PLC messages
Message name Value Comment
PLC_MESSAGE_PLASMA_OK 101
PLC_MESSAGE_WATCHBIT_ACTION 110
PLC_MESSAGE_SPINDLE_SPEED_CHANGED 120
PLC_MESSAGE_PULL_OUT_TOOL 130
PLC_MESSAGE_SPINDLE_TURNING 131
PLC_MESSAGE_ENCODER_DATA 140
PLC_MESSAGE_GVAR_VALUE 141
PLC_MESSAGE_UID 142
PLC_MESSAGE_HCONTROL_OFFSET 144
PLC_MESSAGE_TANGENT_ANGLE 145
PLC_MESSAGE_USER 146
PLC_MESSAGE_HCONTROL_JSPEED 147
PLC_MESSAGE_HCONTROL_DC 148
PLC_MESSAGE_ASK_RECALC 150
PLC_MESSAGE_SOFTLIMIT_STOP 151
PLC_MESSAGE_GVARSET 153
PLC_MESSAGE_IHC_NOT_CONNECTED 155
PLC_MESSAGE_IHC_ERROR 156
PLC_MESSAGE_LATHE_GEARS 160
PLC_MESSAGE_ERR_VM -1
PLC_MESSAGE_ERR_ROMFS -2
PLC_MESSAGE_MOTION_BUFFER_EMPTY -5
PLC_MESSAGE_ERR_SENSOR_COOLANT -10
PLC_MESSAGE_ERR_SENSOR_AIR -11
PLC_MESSAGE_ERR_SENSOR_GAS -12
PLC_MESSAGE_ERR_SENSOR_OXYGEN -13
PLC_MESSAGE_ERR_SENSOR_PLASMA -14
PLC_MESSAGE_ERR_PROBING -15
PLC_MESSAGE_ERR_PLASMA_FAIL -20
PLC_MESSAGE_ERR_PLASMA_TIMEOUT -21
PLC_MESSAGE_PRESSED_ALARM_KEY -30
PLC_MESSAGE_PRESSED_STOP_KEY -31
PLC_MESSAGE_MOTOR_SHORTED -35
MAPPED_OUT_THC_LOWSPEED 63
MAPPED_OUT_LOW_MOTOR_CURRRENT 65
plc/plc.txt · Last modified: 2017/11/10 00:20 by skirillov