New ScreenPanel
This commit is contained in:
54
script/51_Parallelization.js
Executable file
54
script/51_Parallelization.js
Executable file
@@ -0,0 +1,54 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//// Using Parallelization API to execute tasks concurrently
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
//Simple parallization
|
||||
function task1(){
|
||||
m1.moveRel(1.0)
|
||||
return m1.getPosition()
|
||||
}
|
||||
|
||||
function task2(){
|
||||
m2.moveRel(1.0)
|
||||
return m1.getPosition()
|
||||
}
|
||||
|
||||
function task3(){
|
||||
return ai1.read()
|
||||
}
|
||||
|
||||
ret = parallelize(task1, task2, task3)
|
||||
print (ret
|
||||
)
|
||||
|
||||
|
||||
//Fork amd join
|
||||
ret = fork(task1, task2, task3)
|
||||
print (ai1.read()
|
||||
)
|
||||
ret = join(ret)
|
||||
print (ret
|
||||
)
|
||||
|
||||
|
||||
|
||||
//Functions with parameters
|
||||
function moveRelative(motor, step){
|
||||
motor.moveRel(step)
|
||||
return motor.getPosition()
|
||||
}
|
||||
|
||||
ret = parallelize([moveRelative,[m1,-2]], [moveRelative,[m2,-2]])
|
||||
print (ret
|
||||
)
|
||||
|
||||
|
||||
//Exception in parallel task is thrown back to script
|
||||
try{
|
||||
parallelize([moveRelative,[ai1,1]], [moveRelative,[ai2,1]])
|
||||
}catch (ex){
|
||||
print ("Ok, caught exception:"
|
||||
)
|
||||
print(ex)
|
||||
}
|
||||
Reference in New Issue
Block a user