API
API
API
if point.interpolationType == 'PTP':
statement = routine.addStatement(VC_STATEMENT_PTPMOTION)
statement.JointSpeed = point.speed
else:
statement = routine.addStatement(VC_STATEMENT_LINMOTION)
statement.MaxSpeed = point.speed
statement.Base = robotController.Bases[point.base]
statement.Tool = robotController.Tools[point.tool]
position = statement.Positions[0]
position.PositionInReference = mtx
position.Name = point.name
ejv = position.ExternalJointValues
for i in xrange(min(len(point.externalJointValues), len(ejv))):
ejv[i] = point.externalJointValues[i]
position.setExternalJoints(ejv)
position.Configuration = calConfiguration(point.status)
motionTarget = robotController.createTarget()
statement.writeToTarget(motionTarget)
robotController.moveImmediate(motionTarget)
statement.readIn()
position = statement.Positions[0]
turnPosition(position, point.turn)
def getRobotComponents():
app = getApplication()
robotComponents = []
for component in app.Components:
cat = component.getProperty('Category')
if 'Robots' == cat.Value:
robotComponents.append(component)
robotComponents.sort(key=lambda x: x.getProperty('Name').Value)
return robotComponents
def toCreateOnChanged(toCreate):
stopButtons = getStopButtons()
if toCreate.Value == True:
for button in stopButtons:
button.Value = True
def deleteSubroutines(robotComponent):
robotExecutor = robotComponent.findBehavioursByType("rRobotExecutor")[0]
robotProgram = robotExecutor.Program
subroutines = robotProgram.Routines
for subroutine in subroutines:
robotProgram.deleteRoutine(subroutine)
def writeMainRoutine(robotComponent):
robotExecutor = robotComponent.findBehavioursByType("rRobotExecutor")[0]
robotProgram = robotExecutor.Program
mainRoutine = robotProgram.MainRoutine
mainRoutine.clear()
statement = mainRoutine.addStatement(VC_STATEMENT_SETBIN)
statement.OutputPort = 21
statement.OutputValue = True
def getStopButtons():
comp = getComponent()
robots = getRobotComponents()
stopButtons = []
for i in range(len(robots)):
stopButtonName = 'Robot' + str(i + 1) + 'Stop'
stopButton = comp.getProperty(stopButtonName)
if not stopButton:
stopButton = comp.createProperty(VC_BOOLEAN, stopButtonName)
stopButtons.append(stopButton)
return stopButtons
def initStopButtons():
for pr in comp.Properties:
if pr.Type == 'Boolean':
if pr.Name.startswith('Robot') and pr.Name.endswith('Stop'):
num = int(pr.Name[5])
if num > len(robots):
comp.deleteProperty(pr)
def createAllRobotSubroutines(robots):
for i in range(len(robots)):
if i+1 < len(robots):
otherRobots = robots[:i] + robots[i + 1:]
else:
otherRobots = robots[:i]
deleteSubroutines(robots[i])
createSubroutines(robots[i], i + 1, otherRobots)
writeMainRoutine(robots[i])
def OnRun():
if toCreate.Value == True:
createAllRobotSubroutines(robots)
app = getApplication()
sim = app.getSimulation()
sim.reset()
def OnReset():
setRobotStop(stopButtons, robots)
comp = getComponent()
robots = getRobotComponents()
stopButtons = getStopButtons()
toCreate = comp.getProperty('ToCreate')
toCreate.OnChanged = toCreateOnChanged
initStopButtons()