The reservation function is basic in cobot system. It means that external controller could switch to a different task in next cycle without interrupting the executing task right now.
The default setting of CS model is event, which means it's step signal instead of edge signal. While for reservation function, usually the system use edge signal to trigger it and record it in some variables as flags. And when executing this task, it will clear flag signal.
Just as shown below, robot system decides tasks to execute based on the value of stn1 and stn2:
Event.script is as below:
def trap1():
global stn1
stn1 = True
# set global variable stn1 as True
def trap2():
global stn2
stn2 = True
# set global variable stn2 as True
pre_sig = get_standard_digital_in(1)
pre_sig2 = get_standard_digital_in(2)
while True:
sig = get_standard_digital_in(1)
# Get current di1
sig2 = get_standard_digital_in(2)
# Get current di2
if pre_sig==False and sig==True:
# if di1 is upper edge signal, enter trap1
trap1()
if pre_sig2==False and sig2==True:
trap2()
# if di2 is upper edge signal, enter trap2
pre_sig= sig
# keep current di1 as the old value of di1 of next cycle
pre_sig2 = sig2
# keep current di2 as the old value of di2 of next cycle
sleep(0.1)