发表于:2007-09-29 17:58:00
39楼
' Rotating Cutter Example:
' sector in sync: sis (degrees)
' pulses/rotor turn: prt (encoder edges) - integer
' rotor diameter: dia (mm)
' cut length: length (mm)- input via VR(1) dynamically
' edges/mm on conveyor epmm (edges) - may be fractional
sis = 90
prt = 4000
dia = 75
epmm = 16.98
cutter_axis=0
conv=1
BASE(cutter_axis)
' calculate shortest length where stopping will just occur (mm):
stop_length = dia * PI * (720 - sis) / 360
PRINT "stop_length:";stop_length
' build a profile based on "stop length"
' used for this length and larger, also stop/start of "continuous" case
tablestart=1000
link_mm = stop_length
GOSUB build_profile
' In this example use a FORWARD move on conveyor axis:
IF MTYPE AXIS(conv)=0 THEN FORWARD AXIS(conv)
standstill=0
REPEAT
' Check if length has changed:
IF VR(1)<>length THEN
length=VR(1)
' build a profile for non-stopping case if required:
IF VR(1)<stop_length THEN
PRINT "calculating continuous curve:"
tablestart=2000
link_mm = length
GOSUB build_profile
ENDIF
ENDIF
IF IN(7)=ON THEN ' switch on/off using IN(7)
IF VR(1)>stop_length THEN
' Stopping case:
CAMBOX(1050,1100,1,stop_length*epmm/2,conv)
CAMBOX(1000,1050,1,stop_length*epmm/2,conv)
MOVELINK(0,(VR(1)-stop_length)*epmm,0,0,conv)
ELSE
IF nonstop=FALSE THEN
' accelerate from standstill:
TRIGGER
CAMBOX(1050,1100,1,stop_length*epmm/2,conv)
ENDIF
' Non-stopping case:
CAMBOX(2000,2100,1,VR(1)*epmm,conv)
nonstop=TRUE
IF standstill=1 THEN
' decelerate to standstill:
CAMBOX(1000,1050,1,stop_length*epmm/2,conv)
nonstop=FALSE
TRIGGER
ENDIF
ENDIF
ENDIF
UNTIL FALSE
build_profile:
ratio = (prt/(dia*PI*epmm))
link_dist = link_mm * epmm * ratio
excitelink = link_dist - (sis/360) * prt
x1 = (link_dist - excitelink)/(2 * link_dist)
x2 = 1.0 - x1
excitedist = prt - link_dist
points = 101
start_y = 0
a = excitedist / (x2 - x1)
c = -excitedist * x1 / (x2 - x1)
' create the table points
FOR i = 0 TO 100
x = i / 100
IF x < x1 THEN
TABLE(tablestart + i,start_y + x * link_dist)
ELSE
IF x < x2 THEN
alpha = (x - x1) / (x2 - x1)
y = (x - (x2 - x1) * SIN(2 * PI * alpha) / 2 / PI) * a + c
TABLE(tablestart + i,INT(0.5+start_y + y + x * link_dist))
ELSE
TABLE(tablestart + i,INT(0.5+start_y + excitedist + x * link_dist))
ENDIF
ENDIF
NEXT i
RETURN