Author Topic: Custom function  (Read 16097 times)

artkraft

  • Newbie
  • Posts: 22
  • I'm a llama!
    • View Profile
Custom function
« on: April 11, 2020, 12:23:56 PM »
Compiles correctly but won't work.

STEEPSPEED 1, DrillRate, DrillAccel
STEPMOVE 1, DrillSteps, 9, 9999, 90  //flag 9 = DrillComplete
REfRESH
IF TESTIO (DrillComplete)
THEN
STEPSPEED 1, 9999, 90
STEPMOVEABS 1, 0, 13
ELSE ENDIF

I do have a working program calling a second CusFn for the Stepmoveabs using flag 9. However when a stop command is used
we never know where the drill is. The goal is to make the drill cycle up and then down with 1 cusFn. Can't get the then, goes up not down.

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Re: Custom function
« Reply #1 on: April 11, 2020, 03:06:09 PM »
Some issues:

STEPMOVE 1, DrillSteps, 9, 9999, 90  - too many parameters

Note that when you run the STEPMOVE1 command it does not block execution of the program. The PLC setup the parameters for the interrupt service routine to handle the stepper motion so if you are testing for a "Drill Complete" flag right after running the STEPMOVE command it will never work since it takes time for the stepper motor to complete the motion.

The Drill complete flag will be turned ON when the move it complete so you can use it to run a function to decide what is the next step to do after the move is completed.
Email: support@triplc.com
Tel: 1-877-TRI-PLCS

artkraft

  • Newbie
  • Posts: 22
  • I'm a llama!
    • View Profile
Re: Custom function
« Reply #2 on: April 12, 2020, 06:20:37 AM »
The 9999,90 is a mistake in the post only. It does run the drill up but not down. Is it possible to run the drill up and then down within 1 function. Would it work with the RFEFRESH and TESTIO removed.

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Re: Custom function
« Reply #3 on: April 13, 2020, 10:01:37 AM »
This email reply to you was provided to support for this thread:

The best way is to use the STEPMOVEABS and STEPCOUNTABS commands to change and measure position around a fixed point. What you would do is move your motor to a position you would like to call zero and run the STEPHOME command.

From there you can move forward or backward using STEPMOVEABS and return the count from your zero position using STEPCOUNTABS. If you want to define a "home" position as 1000, then you can use define variables to create constant or variable values with names relevant to you (anything allowed by the define table naming conventions), and then use these as parameters for the STEPMOVEABS command.

STEPMOVEABS 1, HOME_1000, 1

It will be even more accurate if you can provide position feedback from your stepper driver to the PLC HSC inputs. STEPCOUNTABS will account for the pulses sent out of the PLC outputs, but it can't know about the actual physical movement, which requires encoder feedback from the driver itself.

The only problem is when the PLC loses power and you don't know for sure what the position of the stepper motor is when it powers up. You can always store position and home values in permanent memory, but the motor could have physically moved after power is lost and the PLC obviously can't detect that, so your power up position will be different than expected (the same problem will exist with any additional stephome command to support your request.

To resolve the issue of position loss when the PLC is powered down, you can add limit switches to zero the motor on power up and then use my solution to create fixed or dynamic home positions.

Here is a description of the STEPMOVEABS command, which you can also view online:

http://www.triplc.com/TRiLOGI/Help/tbasic/stepmoveabs.htm

------------------------------------------------------------------------------
STEPMOVEABS ch, position, r 

Purpose
   

This new command allows you to move the stepper motor # ch to an absolute position indicated by the position parameter. At the end of the move the relay #r will be turned ON. position can be between -231 to +231 .(i.e. about ± 2 x 109) steps. The absolute position is calculated with respect to the last move from the "HOME" position. (The HOME position is set when the STEPHOME command is executed). The speed and acceleration profile are determined by the STEPSPEED command as in the original command set.

This command automatically computes the number of pulses and direction required to move the stepper motor to the new position with respect to the current location. The current location can be determined at any time by the STEPCOUNTABS( ) function.

Once STEPMOVEABS command is executed, re-execution of this command or the STEPMOVE command will have no effect until the entire motion is completed or aborted by the STEPSTOP command.

See Also
   

STEPMOVE, STEPCOUNT( ), STEPCOUNTABS( ), STEPSPEED, STEPSTOP, STEPHOME

 ------------------------------------------------------------------------------
Email: support@triplc.com
Tel: 1-877-TRI-PLCS