User Tools

Site Tools


plc:plc

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
plc:plc [2022/10/28 09:47] ivanplc:plc [2022/11/07 16:03] (current) ivan
Line 605: Line 605:
 | GVAR_PLC_JOGSPEED_UNITS | 8634 | | GVAR_PLC_JOGSPEED_UNITS | 8634 |
 | GVAR_PLC_JOG | 8635 | | GVAR_PLC_JOG | 8635 |
 +
 +An example of a homing PLC that utilized this functionality is shown below. This PLC is designed for the Z-axis only:
 +
 +<code C>#include pins.h
 + 
 +wait_move()
 +{
 +    do { code=gvarget(6060); }while(code!=0x4d);  //wait till motion finished
 +};
 + 
 +show_error()
 +{
 +    gvarset(9121,1); //bring up popup message 21 - this can be customized
 +    timer=50;do{timer--;}while(timer>0);
 +    message=PLCCMD_MOTION_BREAK; //1033
 +    exit(99);
 +};
 + 
 +find_home_z()
 +{
 + 
 +  gvarset(5521,1); //disable hardware limits
 +  gvarset(5525,1); //disable software limits
 + 
 +  gvarset(8631,50); //acceleration time 100ms = 0.05s
 + 
 +  statez=0; //we set the "triggered" state to 0 by default
 +  speed=500;
 +  speed_slow=100; //used on rollback for better precision
 + 
 +  direction=(4<<8); //set the direction variable to Z-
 + 
 +  gvarset(8634,(4<<24)|speed); //Jog speed for Z
 + 
 +  gvarset(8635,direction); //jog in the set direction Z-
 +  timer=0;
 +  do
 +   {
 +      changed=0;
 +      if (statez==0) //to home X
 +       {
 +          sens=portget(INPUT_HOME_Z); //get state of home x sensor
 +          if (sens!=0)
 +          {
 +            statez=1;
 +            gvarset(8634,(4<<24)|speed_slow); //Jog speed for Z
 +            changed=1;
 +          };
 +       };
 +      if (statez==1) //rollback from home Z
 +       {
 +          sens=portget(INPUT_HOME_Z); //receive the state of the sensor 
 +          if (sens==0)
 +          {
 +            statez=2; 
 +            changed=1; 
 +          };
 +       };
 + 
 + 
 +  if (changed!=0) //if any of the sensors state is changed
 +  {
 +    direction=0; //set direction to 0 (no movement) before flipping
 +    if (statez==0) { direction=direction | (4<<8);  };  //direction set to X-
 +    if (statez==1) { direction=direction | 4;  }; //direction set to X+
 +    gvarset(8635,direction); //jog in new direction for the axes
 +  };
 + 
 + 
 + 
 +      if ((timer&0xff)==0)       gvarset(8635,direction);    };
 +      timer++;
 +      ready=(statez==2);
 + 
 +    }while(ready==0);
 + 
 + 
 +   gvarset(8635,0); wait_move(); //stop jog
 + 
 +};
 + 
 +main()
 +{
 + 
 +  gvarset(8631,50); //acceleration time 50ms = 0.05s
 +  gvarset(5539,1); //switch to fast g0moveA implementation
 + 
 +  find_home_z();
 + 
 + 
 +  exit(99);  //normal exit 
 +};</code>
 +
 +The PLC above can be combined with the XY homing (linked at the start of this section) to create simultaneous XYZ homing. In general, the Jog from PLC functionality allows for this simultaneous movement, cutting down on the previously required separate procedures per each axis. 
plc/plc.txt · Last modified: 2022/11/07 16:03 by ivan

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki