Script execution
This commit is contained in:
@@ -19,14 +19,14 @@ class RobotTCP(TcpDevice, Stoppable):
|
||||
self.status = None
|
||||
self.lock = threading.Lock()
|
||||
|
||||
def _sendReceive(self, msg_id, msg = "", timeout = None, retries = None):
|
||||
def _sendReceive(self, msg_id, msg = "", timeout = None):
|
||||
tx = self.header if (self.header != None) else ""
|
||||
tx = tx + msg_id + " " + msg
|
||||
if (len(tx)>127):
|
||||
raise Exception("Exceeded maximum message size")
|
||||
self.getLogger().finer("TX = '" + str(tx)+ "'")
|
||||
if (self.trailer != None): tx = tx + self.trailer
|
||||
rx = self.sendReceive(tx, msg_id, self.trailer , 0, self.timeout, self.retries)
|
||||
rx = self.sendReceive(tx, msg_id, self.trailer , 0, self.timeout if timeout is None else timeout, self.retries)
|
||||
rx=rx[:-1] #Remove 0A
|
||||
self.getLogger().finer("RX = '" + str(rx) + "'")
|
||||
if rx[:3] != msg_id:
|
||||
@@ -38,18 +38,19 @@ class RobotTCP(TcpDevice, Stoppable):
|
||||
raise Exception(rx[4:])
|
||||
return rx[4:]
|
||||
|
||||
def call(self, msg, timeout = None, retries = None):
|
||||
def call(self, msg, timeout = None):
|
||||
id = "%03d" % self.msg_id
|
||||
self.msg_id = (self.msg_id+1)%1000
|
||||
return self._sendReceive(id, msg, timeout, retries)
|
||||
return self._sendReceive(id, msg, timeout)
|
||||
|
||||
def execute(self, command, *argv):
|
||||
def execute(self, command, *args, **kwargs):
|
||||
timeout = None if (kwargs is None) or (not kwargs.has_key("timeout")) else kwargs["timeout"]
|
||||
msg = str(command)
|
||||
if len(argv)>10:
|
||||
if len(args)>10:
|
||||
raise Exception("Exceeded maximum number of parameters")
|
||||
for i in range(len(argv)):
|
||||
msg += (self.cmd_separator if (i==0) else self.array_separator) + str(argv[i])
|
||||
rx = self.call(msg)
|
||||
for i in range(len(args)):
|
||||
msg += (self.cmd_separator if (i==0) else self.array_separator) + str(args[i])
|
||||
rx = self.call(msg, timeout)
|
||||
if rx.count(self.array_separator)>0:
|
||||
return rx.split(self.array_separator)
|
||||
return rx
|
||||
@@ -59,8 +60,8 @@ class RobotTCP(TcpDevice, Stoppable):
|
||||
if ev.strip() == "": return None
|
||||
return ev
|
||||
|
||||
def evaluate(self, cmd, timeout = timeout, retries = retries):
|
||||
ret = self.execute('eval', cmd, timeout, retries)
|
||||
def evaluate(self, cmd, timeout=None):
|
||||
ret = self.execute('eval', cmd, timeout=timeout)
|
||||
if ret.strip() != "": raise Exception(ret)
|
||||
|
||||
def get_var(self, name):
|
||||
@@ -233,15 +234,18 @@ class RobotTCP(TcpDevice, Stoppable):
|
||||
def get_joint_forces(self):
|
||||
robot_tcp.evaluate("getJointForce(arr)")
|
||||
return robot_tcp.get_float_arr(6)
|
||||
|
||||
|
||||
#Tool
|
||||
#This function can timeout since it synchronizes move. Better check state before
|
||||
#This function can timeout since it synchronizes move.
|
||||
#Better check state before otherwise it can freeze the communication
|
||||
def open(self, tool):
|
||||
return self.evaluate("open(" + tool + " )")
|
||||
return self.evaluate("open(" + tool + " )", timeout=3000)
|
||||
|
||||
#This function can timeout since it synchronizes move. Better check state before
|
||||
#Better check state before otherwise it can freeze the communication
|
||||
def close(self, tool):
|
||||
return self.evaluate("close(" + tool + " )")
|
||||
return self.evaluate("close(" + tool + " )", timeout=3000)
|
||||
|
||||
#Arm position
|
||||
def herej(self):
|
||||
@@ -268,6 +272,34 @@ class RobotTCP(TcpDevice, Stoppable):
|
||||
|
||||
def position(self, point, frame):
|
||||
return self.eval_trf("position(" + point + ", " + frame + ")")
|
||||
#Task control
|
||||
|
||||
def task_create(self, program, *args, **kwargs):
|
||||
priority = 10 if (kwargs is None) or (not kwargs.has_key("priority")) else kwargs["priority"]
|
||||
name = program if (kwargs is None) or (not kwargs.has_key("name")) else kwargs["name"]
|
||||
|
||||
taskCreate "t1", 10, read(sMessage)
|
||||
cmd = 'taskCreate "' + name + '", ' + str(priority) + ', ' + program + '('
|
||||
for i in range(len(args)):
|
||||
cmd += str(args[i]) + (',' if (i<(len(args)-1)) else '')
|
||||
cmd+=')'
|
||||
self.evaluate("cmd")
|
||||
|
||||
def task_suspend(self, name):
|
||||
self.evaluate("taskSuspend(" + str(name)+ ")")
|
||||
|
||||
#waits until the task is ready for restart
|
||||
def task_resume(self, name):
|
||||
self.evaluate("taskResume(" + str(name)+ ",0)", timeout = 2000)
|
||||
|
||||
#waits for the task to be actually killed
|
||||
def task_kill(self, name):
|
||||
self.evaluate("taskKill(" + str(name)+ ")", timeout = 2000)
|
||||
|
||||
def get_task_status(self, name):
|
||||
code = self.eval_int("taskStatus(" + str(name)+ ")")
|
||||
status = self.eval_str("help(" + str(code)+ ")")
|
||||
return [code, status]
|
||||
|
||||
#Updating
|
||||
def update_status(self):
|
||||
|
||||
Reference in New Issue
Block a user