Advertisement
Guest User

ServoDriver

a guest
Oct 3rd, 2017
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SCL 3.52 KB | None | 0 0
  1. S31M1.Reset = NOT_AUS AND vReset31M1(*ENABLE31M1*)
  2. S31M1.EnableMovement = HydrP2
  3. S31M1.DeviceName = DeviceNameS31M1
  4. S31M1.MovPosition = MovPositionS31M1
  5. S31M1.SetupMode = DS1EINRIC
  6. S31M1.ManSlowestSpeed = DS1EINZEL
  7. S31M1.ManSlowSpeed = DS1SCHLEI
  8. S31M1.ManFastSpeed = DS1EILGAN
  9. S31M1.ManDirection = DS1RICHTU
  10. S31M1.SlowestSpeed = S31SlowestSpeed
  11. S31M1.SlowSpeed = S31SlowSpeed
  12. S31M1.FastSpeed = S31FastSpeed 
  13. S31M1.AutoPosition = S31M1AutoPosition
  14. S31M1.mmpp = 0.00498 // mmm per pulse conf
  15. S31M1.RefPointStart = 815 ;[PULSE]
  16. S31M1.RefPointEnd = 845 ;[PULSE]
  17. S31M1.RefDetect = M011_UberlDSr // Input related => %IX."X20DI9371e".DigitalInput07
  18. S31M1.Zero = VWZ1Null
  19. S31M1.OvershootREQ = S31M1OvershootREQ
  20.    
  21. S31M1 FUB ServoDriverS31()
  22.    
  23. MovEnableS31M1 = S31M1.MovEnable
  24. MovSpeedS31M1 = S31M1.MovSpeed
  25. RPSM1 = S31M1.RefPoint
  26. VWZ1AUS1 = S31M1.Pos_GT_SP
  27. VWZ1AUS2 = S31M1.Pos_LT_SP
  28. VWZ1AUS3 = S31M1.Pos_EQ_SP
  29. S31M1Position = S31M1.Position
  30.  
  31. (********************************************************************
  32.  * COPYRIGHT --  
  33.  ********************************************************************
  34.  * Program: Drivers
  35.  * File: ServoDriverS31.ab
  36.  * Author: Deniss
  37.  * Created: September 10, 2016
  38.  ********************************************************************
  39.  * Implementation of program Drivers
  40.  ********************************************************************)
  41.  
  42. (* TODO: Add your comment here *)
  43. FUNCTION_BLOCK ServoDriverS31
  44.     // Mode 1 - position, Mode 2 - speed, Mode 128 - reset
  45.     IF (NOT Reset) THEN
  46.         Mode = 128
  47.         ManSlowestSpeed = FALSE
  48.         ManSlowSpeed = FALSE
  49.         ManFastSpeed = FALSE
  50.         SetupMode = FALSE
  51.         HomePosition = MovPosition
  52.     ELSE
  53.         Mode = 2
  54.     ENDIF
  55.    
  56.     // Initialize HomePosition on Zero signal positive edge
  57.     // Used in Position calculation
  58.     IF EDGEPOS(Zero) THEN
  59.         HomePosition = MovPosition
  60.     ENDIF
  61.    
  62.     // Initialize RefStartPosition on RefDetect signal positive edge
  63.     // Used in Reference Point calculation
  64.     IF EDGEPOS(RefDetect) THEN
  65.         RefStartPosition = MovPosition
  66.     ENDIF
  67.    
  68.  
  69.     // Write Mode to module
  70.     AsIOAccWrite_FB.enable = TRUE
  71.     AsIOAccWrite_FB.pDeviceName = ADR(DeviceName)
  72.     AsIOAccWrite_FB.pChannelName = ADR(ChannelNameMovementControl)
  73.     AsIOAccWrite_FB.value = Mode
  74.     AsIOAccWrite_FB FUB AsIOAccWrite()     
  75.    
  76.     // Calculate current position
  77.     Position = REAL(MovPosition - HomePosition) * mmpp
  78.     // Generate position outputs for program
  79.     // Pos_EQ_SP - servo within margin of 0.1mm from SP.
  80.     // Pos_LT_SP - servo position lower than SP
  81.     // Pos_GT_SP - servo position higher than SP
  82.     IF OvershootREQ THEN
  83.         AutoPosition = AutoPosition - 0.1
  84.     ENDIF
  85.    
  86.     Pos_EQ_SP = ABS( Position - AutoPosition ) <= 0.1
  87.     Pos_LT_SP = MovPosition < HomePosition + TRUNC(AutoPosition / mmpp)
  88.     Pos_GT_SP = MovPosition > HomePosition + TRUNC(AutoPosition / mmpp)
  89.    
  90.    
  91.     // Reference point detection
  92.     // MovPosition>HomePosition + Xmm, MovPosition<HomePosition + Xmm + Ymm
  93.     RefPoint = (MovPosition > RefStartPosition + TRUNC(RefPointStart) ) AND (MovPosition < RefStartPosition + TRUNC(RefPointEnd))
  94.    
  95.     SpeedHZ = 0.0
  96.     MovSpeed = 0
  97.  
  98.     IF SetupMode THEN              
  99.         IF ManFastSpeed AND EnableMovement THEN
  100.             SpeedHZ = FastSpeed
  101.         ENDIF
  102.         IF ManSlowSpeed AND EnableMovement THEN
  103.             SpeedHZ = SlowSpeed
  104.         ENDIF
  105.         IF ManSlowestSpeed AND EnableMovement THEN
  106.             SpeedHZ = SlowestSpeed
  107.         ENDIF
  108.         IF NOT ManDirection THEN
  109.             SpeedHZ = -1 * SpeedHZ
  110.         ENDIF
  111.         SpeedHZ = LIMIT(-100000.0, SpeedHZ, 100000.0)
  112.         MovSpeed = TRUNC(SpeedHZ * 16777216 / 1000 * 2)
  113.     ENDIF
  114.    
  115.     MovEnable = (Mode = 2)
  116.        
  117. END_FUNCTION_BLOCK
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement