Program Examples: PIPEMODE library and motion commands
Language: | English • 中文(简体) |
---|
The following example demonstrates how to define an PIPEMODE functions library, and a basic use of it with simple motion commands.
PIPEMODE Library
The following is an optional library for PIPEMODE:
'------------------------------------------------------------------------------
' File: Pipe.lib
' Purpose: Pipe-Mode auxiliary functions
' Version: 1.00
' Author: Mirko.Borich
' Description:
' History:
'
'------------------------------------------------------------------------------
' User C-functions:
import_c ECFAST_HOST_DOUBLE_SET(byval as long,byval as double) as long
import_c MOT_GET_PIPE_ERROR(byval as long) as long
import_c MOT_GET_PIPE_PICOUNTER(byval as long) as long
import_c MOT_GET_PIPE_VICOUNTER(byval as long) as long
import_c MOT_GET_PIPE_VELTOL(byval as long) as double
import_c MOT_GET_PIPE_POSTOL(byval as long) as double
import_c MOT_SET_PIPE_VELTOL(byval as long, byval as double) as long
import_c MOT_SET_PIPE_POSTOL(byval as long, byval as double) as long
' Module local errors
dim shared pipe_pos_host_error as error "Error while writing position to hostdouble"
dim shared pipe_vel_host_error as error "Error while writing velocity to hostdouble"
dim shared pipe_error as error "Pipe=Mode Error"
'************************************************************************************************
' Function: PipeWritePosition
' Description: Writing position value into HOSTDOUBLE array. The position will be written into
' array element that corresponds to the given axis and active sys.PipeMode
' it is important to select right sys.PipeMode before calling this function.
' Arguments: axis, position value (in user units, pcmd and similar)
' Type: subroutine
'************************************************************************************************
public sub PipeWritePosition(ax as generic axis, byval inp_val as double)
dim err as long
select case sys.pipemode
case 1 ' pos
err = ECFAST_HOST_DOUBLE_SET(ax.elementid, inp_val)
case 2 ' pos vel
err = ECFAST_HOST_DOUBLE_SET(2*(ax.elementid-1) + 1, inp_val)
case 3 ' vel
throw pipe_pos_host_error
case else
throw pipe_pos_host_error
end select
if err then
throw pipe_pos_host_error
end if
end sub
'************************************************************************************************
' Function: PipeWriteVelocity
' Description: Writing velocity value into HOSTDOUBLE array. The velocity will be written into
' array element that corresponds to the given axis and active sys.PipeMode
' it is important to select right sys.PipeMode before calling this function.
' Arguments: axis, velocity value (in user units, vcmd and similar)
' Type: subroutine
'************************************************************************************************
public sub PipeWriteVelocity(ax as generic axis, byval inp_val as double)
dim err as long
select case sys.pipemode
case 1 ' pos
throw pipe_vel_host_error
case 2 ' pos vel
err = ECFAST_HOST_DOUBLE_SET(2*ax.elementid, inp_val)
case 3 ' vel
err = ECFAST_HOST_DOUBLE_SET(ax.elementid, inp_val)
case else
throw pipe_vel_host_error
end select
if err then
throw pipe_vel_host_error
end if
end sub
'************************************************************************************************
' Function: GetPipeError
' Description: Retrieving the current pipe-error, topically comes from reading hostdoublearray
' which is obtained from esfast_HostdblGet
' Arguments: axis
' Type: long
'************************************************************************************************
public function GetPipeError(ax as generic axis) as long
GetPipeError = MOT_GET_PIPE_ERROR(ax.elementid)
end function
'************************************************************************************************
' Function: GetPipePositionInaccuracy
' Description: position-inccurcy error event counter
' occurs when ratio between position/velocity increments is invalid
' Arguments: axis
' Type: long
'************************************************************************************************
public function GetPipePositionInaccuracy(ax as generic axis) as long
GetPipePositionInaccuracy = MOT_GET_PIPE_PICOUNTER(ax.elementid)
end function
'************************************************************************************************
' Function: GetPipeVelocityInaccuracy
' Description: position-inaccuracy error event counter
' occurs when ratio between position/velocity increments is invalid
' Arguments: axis
' Type: long
'************************************************************************************************
public function GetPipeVelocityInaccuracy(ax as generic axis) as long
GetPipeVelocityInaccuracy = MOT_GET_PIPE_VICOUNTER(ax.elementid)
end function
'************************************************************************************************
' Function: GetPipeVelocityTolerance
' Description: Retrieves the current velocity-tolerance value
' Arguments: axis
' Type: double
'************************************************************************************************
public function GetPipeVelocityTolerance(ax as generic axis) as double
GetPipeVelocityTolerance = MOT_GET_PIPE_VELTOL(ax.elementid)
end function
'************************************************************************************************
' Function: GetPipePositionTolerance
' Description: Retrieves the current position-tolerance value
' Arguments: axis
' Type: double
'************************************************************************************************
public function GetPipePositionTolerance(ax as generic axis) as double
GetPipePositionTolerance = MOT_GET_PIPE_POSTOL(ax.elementid)
end function
'************************************************************************************************
' Function: SetPipePositionTolerance
' Description: set new position-tolerance value
' percentage multiplier (1 = 100)%1 defining how big the deviation between
' commanded velocity and position increment can be. If exceeded the
' position-inaccuracy error event counter is incremented
' Arguments: axis, new value
' Type: subroutine
'************************************************************************************************
public sub SetPipePositionTolerance(ax as generic axis,byval inp_val as double)
dim err as long
err = MOT_SET_PIPE_POSTOL(ax.elementid,inp_val)
if err then
throw pipe_error
end if
end sub
'************************************************************************************************
' Function: SetPipeVelocityTolerance
' Description: set new velocity-tolerance value
' defines the maximum allowed difference between commanded velocity and the previous one
' in user units. If exceeded the velocity-inaccuracy error event counter is incremented
' Arguments: axis, new value
' Type: subroutine
'************************************************************************************************
public sub SetPipeVelocityTolerance(ax as generic axis,byval inp_val as double)
dim err as long
err = MOT_SET_PIPE_VELTOL(ax.elementid,inp_val)
if err then
throw pipe_error
end if
end sub
Motion-Command Example
NOTE | |
This command used the previous library |
'------------------------------------------------------------------------------
' File: <MyTask>.prg
' Purpose: Just an example of a module header
' Version: 1.00
' Author: <MyFullName>
' Description:
' History: YYYY-MM-DD <MyShortCut> V1.00
' Created
'------------------------------------------------------------------------------
' module global "constants"
' module global variables
import pipe.lib
common shared pipe_vel as double = 0
common shared pipe_pos as double = 0
program
dim tmp as long
dim x as double
dim omega as double
Attach A1
sys.PipeMode = 1
a1.pipemode = 0
sys.PipeMode = 0
Detach A1
with a1
attach
en=0
sleep 100
simulated = 1
pfac = 10000
vfac = pfac/1000
afac = vfac/1000
jfac = afac/1000
positionerrordelay = 4
pemax = 1
vmax = 1000
amax = 10000
dmax = 10000
jmax = 100000
vospd = 1100
smooth = -1
prftype = -1
velocitysafetylimit = 100000
en = 1
detach
end with
Attach a1
a1.en = 1
sleep 100
move a1 0 abs = 1
waitformotion a1
sleep 100
a1.En = 0
record test.rec 50000 gap = 1 recdata = a1.PCmd,a1.vCmd, a1.pfb, a1.PipeMode , a1.en, a1.accelcmd
recordon
Print "Start Position"
sys.PipeMode = 1 ' pos only
call PipeWritePosition(a1,0)
a1.pipemode = 1
a1.en=1
call SetPipePositionTolerance(a1, 1.3) ' Questionable, but we start with very high velocity
call SetPipeVelocityTolerance(a1, 50)
for x = 0 to 2*pi+0.5*2*pi/360 step 2*pi/360 ' 1 deg per 4 ms or 0.017 rad /4ms = 0.0043 rad/ms = 4.3 rad/sec
call PipeWritePosition(a1,10*sin(x))
' First velocity will be 43 uu/sec
sleep 4
next
sleep 100
a1.pipemode = 0
sleep 100
a1.En = 0
sleep 100
sys.PipeMode = 2 ' pos & vel only
Print "Start Position & Velocity"
call PipeWritePosition(a1,0)
call PipeWriteVelocity(a1,0)
a1.pipemode = 1
a1.en=1
omega = 2*pi/360/4*1000 ' in rad/sec
call SetPipeVelocityTolerance(a1, 50) ' First velocity will be 43 uu/sec
for x = 0 to 2*pi+0.5*2*pi/360 step 2*pi/360 ' 1 deg per 4 ms or 0.017 rad /4ms = 0.0043 rad/ms = 4.3 rad/sec
call PipeWritePosition(a1,10*sin(x))
call PipeWriteVelocity(a1,10*omega*cos(x))
sleep 4
next
sleep 100
a1.pipemode = 0
sleep 100
a1.En = 0
sleep 100
sys.PipeMode = 3 ' vel only
Print "Start Velocity"
call PipeWriteVelocity(a1,0)
a1.pipemode = 1
a1.en=1
omega = 2*pi/360/4*1000 ' in rad/sec
call SetPipeVelocityTolerance(a1, 50) ' First velocity will be 43 uu/sec
for x = 0 to 2*pi+0.5*2*pi/360 step 2*pi/360 ' 1 deg per 4 ms or 0.017 rad /4ms = 0.0043 rad/ms = 4.3 rad/sec
call PipeWriteVelocity(a1,10*omega*cos(x))
sleep 4
next
sleep 100
a1.pipemode = 0
sleep 100
a1.En = 0
sleep 100
recordclose
Detach A1
end program ' <MyTask>.prg
Another task option:
'------------------------------------------------------------------------------
' File: <MyTask>.prg
' Purpose: Just an example of a module header
' Version: 1.00
' Author: <MyFullName>
' Description:
' History: YYYY-MM-DD <MyShortCut> V1.00
' Created
'------------------------------------------------------------------------------
' module global "constants"
' module global variables
program continue
with a1
attach
en=0
sleep 100
simulated = 1
pfac = 10000
vfac = pfac/1000
afac = vfac/1000
jfac = afac/1000
REM positionerrordelay = 4
pemax = 100
vmax = 1000
amax = 10000
dmax = 10000
jmax = 100000
vospd = 1100
smooth = -1
prftype = -1
velocitysafetylimit = 10*vmax
vospd = 1.2*vmax
en = 1
detach
end with
terminate program ' <MyTask>.prg
See Also
You can find more information at the PIPEMODE page