Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5

Online Program Multithreading

#1
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.

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!")
#2
Do you use a different Robolink instance for each thread?

To be able to properly use the API on different threads you should use a new Robolink instance for each thread.

A quick workaround is to call this once inside your thread:
Code:
robot.link = Robolink()
Or I recommend you to do this properly when you start your thread and retrieve objects using the same link so the correct RDK links are automatically assigned:
Code:
RDK_t1 = Robolink()
...
robot = RDK_t1.Item("robot", ITEM_TYPE_ROBOT)
...




Users browsing this thread:
1 Guest(s)