Program Examples:Camming by Virtual Master/Full Example
'------------------------------------------------------------------------------
' File: CamDemo.prg
' Purpose: Demonstrating Cam table usage
' Version: 1.00
' Author: Mirko
' Description:
' History: YYYY-MM-DD <MyShortCut> V1.00
' Created
'------------------------------------------------------------------------------
common shared CamTable1 as cam ' the global cam table
program
' Some local variables
dim i as long
dim camsize as long = 1000
dim cam_amplitude as double = 200
' Axis parameters can not be set if the axis in slaved therefore ressetting the master-slave relationship
Attach A2
A2.Slave =0
Detach A2
' Setting the axis parameters
call SetAxis(a1,1000)
call setaxis(a2,1000)
CamTable1.Cycle = -1 ' Endless cam table
createcamdata camsize CamTable1 ' Create 1000 points
' Sine function
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
storecamdata ct1.cam CamTable1 ' save it on the disk
Attach A2
a2.MasterSource = a1.pcmd ' Master is A1's position command (PCMD)
a2.GearRatio = 1.0 ' gear 1:1
a2.CamOffset = 0 ' No offset
a2.FirstCam = CamTable1 ' connect
a2.slave = cam ' engage
A2.en = 1 ' enable slave
Detach A2
' Move the master axis
Attach A1
A1.en = 1
Jog A1 100
Detach A1
end program ' <MyTask>.prg
sub SetAxis(ax as generic axis, byval vvv as double)
dim omega as double = 15
dim profile as long = -1
with ax
attach
en = 0
sleep 10
simulated = 0
pfac = pos_units[elementid]/5 'For 5mm pitch
vfac = pfac/1000 ' mm /sec
afac = vfac/1000 ' mm /sec^2
jfac = afac/1000 ' mm / sec^3
vmax = vvv
amax = 1500
dmax = 1500
jmax = omega*amax ' Fast reacting
vcruise = vmax
acc = amax
dec = dmax
jerk = jmax
prftype = profile
smooth = -1
vospd = 2*vmax
velocitysafetylimit = 100*vmax
positionerrorsettle = 5
pemax = 1
pmaxen = 1
pminen = 1
disp = 0
abs = 1
positionrolloverenable = 0
simulated = 1
Print "axis ";elementname;" set."
detach
end with
end sub
The example corresponds to commit SHA-1: 504227da968b38aa5a4bae7473388edd13f7b929 in GIT.