plc:plc
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
plc:plc [2018/09/25 17:32] – skirillov | plc:plc [2022/10/27 13:41] – ivan | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | {{mycnc: | ||
- | |||
- | |||
====== PLC ====== | ====== PLC ====== | ||
- | PLC - programmable logic controller. | + | PLC stands for " |
PLC controller can load and run small binary programs (PLC procedures). PLC procedure should be written in a simplified C-like language, compiled and stored in PLC controller memory to be ready to run. myCNC software includes [[plc: | PLC controller can load and run small binary programs (PLC procedures). PLC procedure should be written in a simplified C-like language, compiled and stored in PLC controller memory to be ready to run. myCNC software includes [[plc: | ||
+ | {{mycnc: | ||
myCNC control has 2 types of built-in PLC systems that named | myCNC control has 2 types of built-in PLC systems that named | ||
- | [[#Hardware PLC]] and [[#Software PLC]] | + | [[#Hardware PLC]] and [[#Software PLC]]. |
+ | |||
+ | Note that hardware PLC can be launched from software PLC if necessary, through the use of // | ||
==== Hardware PLC ==== | ==== Hardware PLC ==== | ||
Line 32: | Line 31: | ||
=== PLC Language === | === PLC Language === | ||
- | * PLC operates with 32 bits integer values only. Floating point operations don't work in PLC. | + | * PLC operates with 32 bits integer values only. Floating point operations don't work in PLC (typically need to use coefficient conversions to allow for more granular control). |
* There is no need to declare variables. There is very limited space of 32 elements for variables. | * There is no need to declare variables. There is very limited space of 32 elements for variables. | ||
* There a number of pre-defined variables in the PLC | * There a number of pre-defined variables in the PLC | ||
- | * eparam - External Parameter variable. | + | * eparam - External Parameter variable. |
- | L=eparam>> | + | |
* **proc** - variable is used to identify a process running in the PLC. \\ The value is sent to the CNC control software and can be used to display Current PLC state (like Idle, Ignition (for plasma cutting), preheat (gas cutting), Tool change, Probing etc) | * **proc** - variable is used to identify a process running in the PLC. \\ The value is sent to the CNC control software and can be used to display Current PLC state (like Idle, Ignition (for plasma cutting), preheat (gas cutting), Tool change, Probing etc) | ||
+ | * The **proc** variable can impact many behaviours of the myCNC software, such as jogging speed (using the User Settings value for when the **proc** is Idle, and using the cutting speed for **Plasma** and **Cutting** states). | ||
* **timer** - value can be used as time counter inside PLC procedure | * **timer** - value can be used as time counter inside PLC procedure | ||
* vexit - variable contains additional exit code. In case of error CNC control software can display Error message depends on **vexit** exit code. | * vexit - variable contains additional exit code. In case of error CNC control software can display Error message depends on **vexit** exit code. | ||
Line 49: | Line 48: | ||
* adc01 - variable mapped to ADC #0 register. Reading this variable will return ADC #0 value. | * adc01 - variable mapped to ADC #0 register. Reading this variable will return ADC #0 value. | ||
* adc02 - variable mapped to ADC #1 register. Reading this variable will return ADC #1 value. Variables adc01, adc02 are a bit obsolete. It's better to use **gvarget**, | * adc02 - variable mapped to ADC #1 register. Reading this variable will return ADC #1 value. Variables adc01, adc02 are a bit obsolete. It's better to use **gvarget**, | ||
+ | |||
+ | For example, changing the value of PWM01 can be done using the following PLC procedure: | ||
+ | |||
+ | < | ||
+ | { | ||
+ | | ||
+ | if (val> | ||
+ | if (val<0) {val=0;}; | ||
+ | | ||
+ | | ||
+ | };</ | ||
< | < | ||
Line 58: | Line 68: | ||
^ Operator ^ Description ^ Example ^ | ^ Operator ^ Description ^ Example ^ | ||
- | | "+" | + | | < |
- | | "-" | + | | < |
- | | "*" | + | | < |
- | | "/" | + | | < |
- | | "&" | + | | < |
- | |< | + | | < |
- | | ">>" | + | | <code>>></ |
- | | "<<" | + | | <code><<</ |
- | | "==" | + | | < |
- | | "!=" | + | | < |
- | | ">" | + | | < |
- | | ">=" | + | | < |
- | | "<" | + | | <code><</ |
- | | "<=" | + | | < |
- | | "++" | + | | < |
- | | "--" | + | | < |
* PLC functions | * PLC functions | ||
Line 84: | Line 94: | ||
^ Address ^ Description ^ | ^ Address ^ Description ^ | ||
- | | 20000...20100 | Print variable value in myCNC control message widget for debugging purpose. Values written to this registers will be printed in myCNC control software in Message widget {{mycnc: | + | | 20000...20100 | Print variable value in myCNC control message widget for debugging purpose. Values written to this registers will be printed in myCNC control software in Message widget |
+ | |||
+ | It is possible to access the state of the output via gvarget commands from within the PLC process: | ||
+ | |||
+ | < | ||
+ | b=gvarget(0x407); | ||
+ | |||
+ | Starting from 0x400 to represent OUT0, this is a hexadecimal system that is simple to convert to dotted decimals (through the likes of a simple reference site [[https:// | ||
=== The hardware access registers === | === The hardware access registers === | ||
Line 93: | Line 111: | ||
| GVAR_HW_INPUTS2 | 7182 | | | | GVAR_HW_INPUTS2 | 7182 | | | ||
| GVAR_HW_INPUTS3 | 7183 | | | | GVAR_HW_INPUTS3 | 7183 | | | ||
- | | GVAR_HW_OUTPUTS0 | 7184 | | | + | | GVAR_HW_OUTPUTS0 | 7184 | [[https:// |
| GVAR_HW_OUTPUTS1 | 7185 | | | | GVAR_HW_OUTPUTS1 | 7185 | | | ||
| GVAR_HW_OUTPUTS2 | 7186 | | | | GVAR_HW_OUTPUTS2 | 7186 | | | ||
Line 155: | Line 173: | ||
* All Software PLC procedures (except " | * All Software PLC procedures (except " | ||
- | * " | + | * " |
Line 163: | Line 181: | ||
| < | | < | ||
| < | | < | ||
+ | | < | ||
+ | |||
+ | Variables used in Software PLC: | ||
+ | |||
+ | ^Variable^Use^Example^Comment^ | ||
+ | | 100020 | Jog the selected axis (100020 through to 100027) | // | ||
+ | | 100040 | Launch a Hardware PLC from within a Software PLC | // | ||
+ | | 100041 | Eparameter to feed into the Hardware PLC being launched using 100040 | // | ||
* [[software_plc_examples|Software PLC Examples]] | * [[software_plc_examples|Software PLC Examples]] | ||
Line 225: | Line 251: | ||
=== PLC defines === | === PLC defines === | ||
- | |||
| Name | Value | Comment | | | Name | Value | Comment | | ||
Line 302: | Line 327: | ||
| PLCCMD_SET_PIDTIME | 1240 | | | | PLCCMD_SET_PIDTIME | 1240 | | | ||
+ | == Note on PLC define naming== | ||
+ | |||
+ | Please note that there exist some limitations of the preprocessor that parses the //#define// lines. Specifically, | ||
+ | |||
+ | For example, an argument name such as // | ||
+ | |||
+ | < | ||
+ | OUTPUT_SPINDLE_BEARING | ||
+ | OUTPUT_SPINDLE_CONE</ | ||
+ | |||
+ | are NOT allowed, ssince they all contain the string " | ||
+ | |||
+ | < | ||
+ | |||
+ | or | ||
+ | |||
+ | < | ||
+ | |||
+ | since those do not contain the exact string from before. Failure to properly define your arguments in such a manner and then utilizing them in your PLC commands will result in a error during compilation with a label //" | ||
+ | |||
+ | |||
+ | == PLCCMD_MOTION_CONTINUE and PLCCMD_MOTION_SKIP == | ||
+ | |||
+ | The abovementioned PLCCMD_MOTION_CONTINUE and PLCCMD_MOTION_SKIP commands are highly useful for certain applications since typically the motion controller runs commands one by one. By design, if within a running program the next code is a PLC M-code, then the movement will be stopped and the controller will run the PLC program. A message from within the PLC called PLCCMD_MOTION_CONTINUE is used to instruct the Motion controller to read and run the next code from the buffer (thus starting the next motion command). | ||
+ | |||
+ | After this code, the PLC procedure continues running through its code while at the same time the next motion code is launched. In this way, both the PLC procedure and the motion command will be running simultaneously. | ||
+ | |||
+ | This is useful for applications such as homing since it makes it possible to both move the axis and monitor the home sensor in the PLC procedure at the same time. That way when the sensor is activated, the current movement command will need to be stopped. A different message called PLCCMD_MOTION_SKIP is then used - the motion controller will cancel current motion (it will stop moving) and will read the next code from the buffer. | ||
+ | |||
=== PLC processes named === | === PLC processes named === | ||
Line 423: | Line 477: | ||
| GVAR_CURRENT_PROGRAM_POSITION | 5041, 5042, 5043, 5044, 5045, 5046 | | | | GVAR_CURRENT_PROGRAM_POSITION | 5041, 5042, 5043, 5044, 5045, 5046 | | | ||
| GVAR_ENCODER_Z_EVENT | | | | | GVAR_ENCODER_Z_EVENT | | | | ||
- | | --- | 17000 | Return Current PROGRAM X Position in PLC units (0.01mm) | | + | | --- | 17001 | Return Current PROGRAM X Position in PLC units (0.01mm) | |
- | | --- | 17001 | Return Current PROGRAM Y Position in PLC units (0.01mm) | | + | | --- | 17002 | Return Current PROGRAM Y Position in PLC units (0.01mm) | |
- | | --- | 17002 | Return Current PROGRAM Z Position in PLC units (0.01mm) | | + | | --- | 17003 | Return Current PROGRAM Z Position in PLC units (0.01mm) | |
- | | --- | 17003 | Return Current PROGRAM A Position in PLC units (0.01degree) | | + | | --- | 17004 | Return Current PROGRAM A Position in PLC units (0.01degree) | |
- | | --- | 17004 | Return Current PROGRAM B Position in PLC units (0.01degree) | | + | | --- | 17005 | Return Current PROGRAM B Position in PLC units (0.01degree) | |
- | | --- | 17005 | Return Current PROGRAM C Position in PLC units (0.01degree) | | + | | --- | 17006 | Return Current PROGRAM C Position in PLC units (0.01degree) | |
- | | --- | 17006 | Return Current PROGRAM U Position in PLC units (0.01mm) | | + | | --- | 17007 | Return Current PROGRAM U Position in PLC units (0.01mm) | |
- | | --- | 17007 | Return Current PROGRAM V Position in PLC units (0.01mm) | | + | | --- | 17008 | Return Current PROGRAM V Position in PLC units (0.01mm) | |
- | | --- | 17008 | Return Current PROGRAM W Position in PLC units (0.01mm) | | + | | --- | 17009 | Return Current PROGRAM W Position in PLC units (0.01mm) | |
- | | --- | 17020 | Return Current MACHINE X Position in PLC units (0.01mm) | | + | | --- | 17021 | Return Current MACHINE X Position in PLC units (0.01mm) | |
- | | --- | 17021 | Return Current MACHINE Y Position in PLC units (0.01mm) | | + | | --- | 17022 | Return Current MACHINE Y Position in PLC units (0.01mm) | |
- | | --- | 17022 | Return Current MACHINE Z Position in PLC units (0.01mm) | | + | | --- | 17023 | Return Current MACHINE Z Position in PLC units (0.01mm) | |
- | | --- | 17023 | Return Current MACHINE A Position in PLC units (0.01degree) | | + | | --- | 17024 | Return Current MACHINE A Position in PLC units (0.01degree) | |
- | | --- | 17024 | Return Current MACHINE B Position in PLC units (0.01degree) | | + | | --- | 17025 | Return Current MACHINE B Position in PLC units (0.01degree) | |
- | | --- | 17025 | Return Current MACHINE C Position in PLC units (0.01degree) | | + | | --- | 17026 | Return Current MACHINE C Position in PLC units (0.01degree) | |
- | | --- | 17026 | Return Current MACHINE U Position in PLC units (0.01mm) | | + | | --- | 17027 | Return Current MACHINE U Position in PLC units (0.01mm) | |
- | | --- | 17027 | Return Current MACHINE V Position in PLC units (0.01mm) | | + | | --- | 17028 | Return Current MACHINE V Position in PLC units (0.01mm) | |
- | | --- | 17028 | Return Current MACHINE W Position in PLC units (0.01mm) | | + | | --- | 17029 | Return Current MACHINE W Position in PLC units (0.01mm) | |
+ | |||
+ | ====Launching a PLC command using an on-screen button==== | ||
+ | |||
+ | The following video illustrates the process of creating a button to launch a software PLC command (a similar process can also be used for hardware PLCs): | ||
+ | |||
+ | {{youtube> | ||
+ | |||
+ | ====Launching a Hardware PLC procedure from Software PLC==== | ||
+ | |||
+ | It is possible to launch Hardware PLC procedures from within a Software PLC command. This can be done for purposes such as utilizing certain commands are not available from the Software PLC, and that some require low-latency sensor monitoring. It also has the added benefit of utilizing the unlimited number of procedures that can work simultaneously in Software PLC, allowing the user create things such as permanent while loops, etc. | ||
+ | |||
+ | For example, a code such as: | ||
+ | |||
+ | <code C> | ||
+ | { | ||
+ | |||
+ | gvarset(100040, | ||
+ | |||
+ | exit(99); | ||
+ | |||
+ | };</ | ||
+ | |||
+ | |||
+ | will launch Hardware PLC M602 from the specified Software PLC. | ||
+ | |||
+ | Additionally, | ||
+ | |||
+ | For example, adding a line such as | ||
+ | |||
+ | <code C> | ||
+ | gvarset(100041, | ||
+ | </ | ||
+ | |||
+ | will launch the M602 Hardware PLC with the Param variable. | ||
+ | |||
+ | ====Jog from PLC==== | ||
+ | |||
+ | //**NOTE**: Jog from PLC requires a firmware update. As of February 2022, the feature is available in the Testing firmware branch.// | ||
+ | |||
+ | myCNC allows the user to call for a jog command from within PLCs. The advantage of this motion mode is that it allows to perform tasks (such as changing the speed and direction of movement, as well as turning the motion for a particular axis on or off), all without stopping. This is useful in such applications as homing along multiple (for example, three) axes. Such an example is available here: [[plc: | ||
+ | |||
+ | In this mode, the acceleration is set via the following command: | ||
+ | |||
+ | <code C> | ||
+ | |||
+ | while the speed is set via the global variable #8634 (the axis mask is stored in the high-order byte): | ||
+ | |||
+ | <code C> | ||
+ | gvarset(8634, | ||
+ | gvarset(8634, | ||
+ | |||
+ | A sample motion code may therefore look the following way: | ||
+ | |||
+ | <code C> | ||
+ | { | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | |||
+ | | ||
+ | | ||
+ | | ||
+ | { | ||
+ | | ||
+ | if ((timer& | ||
+ | | ||
+ | |||
+ | | ||
+ | | ||
+ | | ||
+ | do | ||
+ | { | ||
+ | | ||
+ | if ((timer& | ||
+ | | ||
+ | |||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | { | ||
+ | | ||
+ | if ((timer& | ||
+ | | ||
+ | |||
+ | | ||
+ | | ||
+ | | ||
+ | { | ||
+ | | ||
+ | if ((timer& | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | |||
+ | | ||
+ | | ||
+ | |||
+ | The following variables may be used for this jog functionality: | ||
+ | ^ Variable name ^ Variable # ^ | ||
+ | | GVAR_G0PLC_SPEED | 8630 | | ||
+ | | GVAR_G0PLC_TIME | 8631 | | ||
+ | | GVAR_G0PLC_SPEED_UNITS | 8632 | | ||
+ | | GVAR_PLC_JOGSPEED_UNITS | 8634 | | ||
+ | | GVAR_PLC_JOG | 8635 | |
plc/plc.txt · Last modified: 2022/11/07 16:03 by ivan