05-02-2023, 06:35 PM
(This post was last modified: 05-03-2023, 10:03 AM by Albert.
Edit Reason: Proper code formatting
)
Reposting as I realize this should be in the API section.
I have 2 meca 500s that I am attempting to run movements on at the same time. To do this I have written a synced multithreading function with movements being called to each robot on each thread. When I run in online mode the robots only move one at a time.
Is it possible to have synced movements with multithreading and online programming or do I need to do post processing?
I have attached my code below. Robot.SafeJM is a custom function uses MoveJ_test to check a joint move is safe before running.
I have 2 meca 500s that I am attempting to run movements on at the same time. To do this I have written a synced multithreading function with movements being called to each robot on each thread. When I run in online mode the robots only move one at a time.
Is it possible to have synced movements with multithreading and online programming or do I need to do post processing?
I have attached my code below. Robot.SafeJM is a custom function uses MoveJ_test to check a joint move is safe before running.
Code:
class MyThreads:
def __init__(self,threads):
self.state=[0]*threads
self.threads=[]
def RScan(self,Robot,Rlist,t):
i=0
while i< len(Rlist):
time.sleep(0.001)
if self.state[t]==0:
Robot.SafeJM(Robot.LEDT,Rlist[i])
self.state[t]=1
i+=1
if self.state==[1]*len(self.state):
self.state=[0]*len(self.state)
# elif self.state[t]==1:
# print('Race Prevented')
def GScan(self,ESP,Rlist,t):
i=0
while i< len(Rlist):
time.sleep(0.001)
if self.state[t]==0:
ESP.patch("goalposLED",Rlist[i])
ESP.get("zCurrent")
self.state[t]=1
i+=1
#print(self.state)
if self.state==[1]*len(self.state):
self.state=[0]*len(self.state)
# elif self.state[t]==1:
# print('Race Prevented')
def SyncThreads(self,fun,args):
for t in range(0,len(args)):
thread = threading.Thread(target=fun[t],args=args[t])
thread.daemon = True
thread.start()
self.threads.append(thread)
print('Threads started')
for t in self.threads:
t.join()
print("Done!")