plc:motion_commands_from_plc
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
plc:motion_commands_from_plc [2018/04/26 17:03] – skirillov | plc:motion_commands_from_plc [2024/02/21 13:58] (current) – ivan | ||
---|---|---|---|
Line 1: | Line 1: | ||
===== Running Motion (Positioning) commands from PLC ===== | ===== Running Motion (Positioning) commands from PLC ===== | ||
+ | ==== Option 1 ==== | ||
- | Motion Controller and PLC running on myCNC controllers as independent tasks in Rral Time multi-tasking environment. | + | Motion Controller and PLC running on myCNC controllers as independent tasks in Real Time multi-tasking environment. |
There is API to run motion commands from PLC. This features used for wide range of procedures like probing, homing, measure procedures etc. | There is API to run motion commands from PLC. This features used for wide range of procedures like probing, homing, measure procedures etc. | ||
- | Procedure **g0moveA** is used to send motion command from PLC to motion controller. | + | Procedure **g0moveA** is used to send motion command from PLC to motion controller. |
- | Procedure | + | |
* **flags** | * **flags** | ||
* bit 0 - absolute programming (0 - incremental, | * bit 0 - absolute programming (0 - incremental, | ||
Line 18: | Line 18: | ||
* bit 5 - C axis | * bit 5 - C axis | ||
* **distance** - distance to go - integer value in 0.01 units (mm or inch depends on CNC setup) | * **distance** - distance to go - integer value in 0.01 units (mm or inch depends on CNC setup) | ||
+ | |||
+ | NOTE: Use the bit conversion: | ||
+ | |||
+ | ^ bit ^ converted value ^ | ||
+ | | bit 0 | 0x01 | | ||
+ | | bit 1 | 0x02 | | ||
+ | | bit 2 | 0x04 | | ||
+ | | bit 3 | 0x08 | | ||
+ | | bit 4 | 0x10 | | ||
+ | | bit 5 | 0x20 | | ||
Examples:< | Examples:< | ||
Line 23: | Line 33: | ||
</ | </ | ||
- | Easy to see that only 1 distance value programmed in **g0moveA** procedure. **Delayed start** is used to program | + | Easy to see that only 1 distance value programmed in **g0moveA** procedure. **Delayed start** is used to program motion in several coordinates. Delayed start bit tells to Motion controller to not start motion but just store distance position for future motion. Distance for several axes can be setup with delayed |
Example <code c> //need to move to absolute position (100,50,20) | Example <code c> //need to move to absolute position (100,50,20) | ||
Line 32: | Line 42: | ||
- | Motion command is asynchronous operation. Actual motion is started a few miliseconds | + | Motion command is asynchronous operation. Actual motion is started a few milliseconds |
- | For this case PLC procedure can get current Motion Control State. Current Motion Control State is mapped to global variables array variable #6060. Return values while reading the variable are | + | //NOTE: The drawback of this motion method is that after receiving the g0move command, the controller sends the movement values (distance, speed, acceleration) to the myCNC software, after which it then receives the recalculated values from the software in the units the controller requires (pulses, etc). As can be noted, this requires some additional time for the back and forth sending of information, |
+ | |||
+ | A PLC procedure can obtain the current Motion Control State. Current Motion Control State is mapped to global variables array variable #6060. Return values while reading the variable are | ||
^ Value ^ Description ^ | ^ Value ^ Description ^ | ||
Line 46: | Line 58: | ||
Example <code c> | Example <code c> | ||
g0moveA(0, | g0moveA(0, | ||
- | timer=10; do{timer--; | + | timer=200; do{timer--; |
+ | //wait 10ms , motion should start, motion state will turn to **0** | ||
do{ code=gvarget(6060); | do{ code=gvarget(6060); | ||
</ | </ | ||
Line 71: | Line 84: | ||
gvarset(7080, | gvarset(7080, | ||
g0moveA(absolute, | g0moveA(absolute, | ||
- | timer=10; do{timer--; | + | timer=200; do{timer--; |
do { code=gvarget(6060); | do { code=gvarget(6060); | ||
}; | }; | ||
Line 98: | Line 111: | ||
}; | }; | ||
</ | </ | ||
+ | |||
+ | :!: **NOTE:** Note the '' | ||
First block of this procedure check if spindle currently is O, and **lift_up** variable is positive value and the lift tool up for given value set in plc-variables.xml configuration file. For those who don't need this lifting can remove the lines and rebuild PLC (see rebuild buttons in [[plc: | First block of this procedure check if spindle currently is O, and **lift_up** variable is positive value and the lift tool up for given value set in plc-variables.xml configuration file. For those who don't need this lifting can remove the lines and rebuild PLC (see rebuild buttons in [[plc: | ||
+ | |||
+ | |||
+ | ==== Option 2 ==== | ||
+ | |||
+ | //NOTE: At the time of writing this manual, Option 2 for motion control is available in the Testing branch of myCNC firmware (version 15,050 and above). For firmware update instructions, | ||
+ | |||
+ | If bit #13 is set for the axis mask, then Option 2 of the PLC motion command is used (instead of Option 1, described above). In this case the control board itself will handle all calculations necessary for the positioning motion without the support of myCNC software. As a result, the controller does not need to communicate with the Host PC and the movement will be started immediately (unlike Option 1, where extra communication with the Host PC leads to an additional delay of about 100-150ms). | ||
+ | |||
+ | The drawback of this method is that the movement instructions are programmed in **pulses** rather than the more conventional units of mm/inches, as the controller is not aware of the motion units that are set in the myCNC software. | ||
+ | |||
+ | Useful global variable registers: | ||
+ | * #8630 - used to set the motion speed, in pulses/ | ||
+ | * #8631 - used to set the ramp-up time to a given speed, in ms | ||
+ | |||
+ | |||
+ | Example of a motion command for this method: | ||
+ | < | ||
+ | </ | ||
+ | |||
+ | * 0x01 - Absolute coordinates | ||
+ | * 0x1001 - bit #13 (0x1000) and X-axis mask (0x01) | ||
+ | * 16000 - coordinate for the selected X-axis, in pulses (for example, if the pulse-per-mm value for the Х-axis is equal to 800, the movement will be equal 1600/ | ||
+ | |||
+ | <code c draw_square> | ||
+ | wait_motion_end() | ||
+ | { | ||
+ | timer=2; do{timer--; | ||
+ | do | ||
+ | | ||
+ | ex=0; code=gvarget(6060); | ||
+ | if (code==0x4d) {ex=1;}; | ||
+ | if (code==0x57) {ex=1;}; | ||
+ | } while(ex==0); | ||
+ | }; | ||
+ | |||
+ | square() | ||
+ | { | ||
+ | gvarset(8630, | ||
+ | gvarset(8631, | ||
+ | |||
+ | g0moveA(0x01, | ||
+ | wait_motion_end(); | ||
+ | g0moveA(0x01, | ||
+ | wait_motion_end(); | ||
+ | g0moveA(0x01, | ||
+ | wait_motion_end(); | ||
+ | g0moveA(0x01, | ||
+ | wait_motion_end(); | ||
+ | |||
+ | |||
+ | }; | ||
+ | |||
+ | </ | ||
+ | |||
+ | |||
plc/motion_commands_from_plc.txt · Last modified: 2024/02/21 13:58 by ivan