Program Examples:Create Motion:CAM Table/zh-hans
语言: | English • 中文(简体) |
---|
以下示例演示如何创建和使用CAM表。
请参考Axis Setup Procedure了解如何设置轴的说明和示例。
'**********************************************************************************************************
' File: CAM_MOVE.PRG
' Purpose: Move two axes with CAM table and master-slave
' Version: 1.00
' Author: Nir Geller
' Description: This is an example of use of a CAM table. Initialize a CAM table with a sinus function character,
' and set master - slave relations between two axes. Move the master axis and see how the slave axis
' follows according to the cam table.
'
' Record or watch the PFB of AX_MASTER and AX_SLAVE.
'
'**********************************************************************************************************
'Declaring a cam-table type global variable:
common shared AX_MASTER as generic axis = A1
common shared AX_SLAVE as generic axis = A2
common shared CamTable1 as cam
program
call SetCAM
attach AX_MASTER
attach AX_SLAVE
'call EC_SET_MOTION_OPMODE(AX_MASTER, POSITIONMODE)
AX_MASTER.en = 1
AX_SLAVE.en = 1
sleep 1000
while 1
MOVE AX_MASTER 1000 vcruise=1000 starttype=immediate abs = 1
while AX_MASTER.IsMoving <> 0
sleep 1000
end while
MOVE AX_MASTER 0 vcruise=1000 starttype=immediate abs = 1
while AX_MASTER.IsMoving <> 0
sleep 1000
end while
end while
detach AX_MASTER
detach AX_SLAVE
end program
'****************************************************************************
' Subroutine Name: SetCAM
' Description: Initialize a CAM table with a sinus function character, and set
' master - slave relations between two axes.
' Called From: Program
' Author: Nir Geller
' Input Parameters: None
' Output Parameters: None
' Return Value: None
' Algorithm:
' Global Variables Used:
' Revisions:
'****************************************************************************
sub SetCAM
dim camsize as long = 10000
dim cam_amplitude as long = 100
dim i as long = 0
'Creating an empty cam table:
'This table is cyclic (infinite cycle repetitions):
CamTable1.Cycle = -1
'Not linked to any other cam-tables:
CamTable1.Next = none
CamTable1.Prev = none
'Making it 10000 points
createcamdata camsize CamTable1
'Defining a 360 deg sine table:
for i = 1 to CamTable1.Size
CamTable1.MasterData [i] = 360*(i-1)/CamTable1.Size ' Master in degrees
CamTable1.SlaveData [i] = cam_amplitude *sin (CamTable1.MasterData [i] * pi/180)
next
'Store the newly created file onto flash disk:
storecamdata ct1.cam CamTable1
'Once the table is stored on the flash it can be reloaded as:
'loadcamdata ct1.cam CamTable1
print "CAM table set"
attach AX_MASTER
attach AX_SLAVE
AX_SLAVE.MasterSource = AX_MASTER.PCMD
AX_SLAVE.GearRatio = 1.0
AX_SLAVE.CamOffset = 0
AX_SLAVE.FirstCam = CamTable1
AX_SLAVE.slave = cam
detach AX_MASTER
detach AX_SLAVE
print "Master-Slave relation set"
end sub
该示例对应于在GIT中的提交的SHA-1: 6b843ca272c3e3d28d36d7116ba9812f4166d97f.