Teach Instruction via API

Hi!
How to teach a Move instruction via API? I have found how to set active tool, wobj, task and path. But what shall I do next?
Thanks a lot!

Hi Saibel
Here is code for teaching targets in API

Private Sub CreateTarget(ByVal X As Single, ByVal y As Single, ByVal Z As Single)

’ Check that we have an active station

Dim CurX As Single

Dim CurY As Single

Dim CurZ As Single

Dim CurRX As Single

Dim CurRY As Single

Dim CurRZ As Single

X = X / 1000

y = y / 1000

Z = Z / 1000

Dim station As Station = Project.ActiveProject

If station Is Nothing Then

Exit Sub

End If

Dim activeTask As RsTask = station.ActiveTask

If activeTask Is Nothing Then

Exit Sub

End If

’ ’ Find an unused name

Dim targetName As String = “”

For i As Int32 = 0 To Int32.MaxValue

targetName = “Jim_1A_” + i.ToString()

If activeTask.DataDeclarations.Contains(targetName) = False Then

Exit For

End If

Next

'Get current TCP position.

’ ’ Create a robtarget

Dim robTarget As New RsRobTarget()

Dim trans1 As Quaternion

robTarget.Name = targetName

’ Add the robtarget to the active task

activeTask.DataDeclarations.Add(robTarget)

’ Create a target associated with the robtarget and the active workobject

Dim workObject As RsWorkObject = station.ActiveTask.DataDeclarations(“Wobj0”)

Dim myTarget As New RsTarget(workObject, robTarget)

myTarget.Name = targetName

’ Add the target to the active task

activeTask.Targets.Add(myTarget)

Logger.AddMessage(New LogMessage("Created " + targetName + " in " + activeTask.Name))

’ If the task has an active path procedure, create a new move instruction and add it

Dim path As RsPathProcedure = activeTask.ActivePathProcedure

If path IsNot Nothing Then

Dim tool As RsToolData = activeTask.ActiveTool

CurX = tool.Frame.GlobalMatrix.t.x

CurY = tool.Frame.GlobalMatrix.t.y

CurZ = tool.Frame.GlobalMatrix.t.z

trans1 = tool.Frame.GlobalMatrix.Quaternion

'CurRX = tool.Frame.GlobalMatrix.EulerZYX.x

'CurRY = tool.Frame.GlobalMatrix.EulerZYX.y

'CurRZ = tool.Frame.GlobalMatrix.EulerZYX.z

myTarget.Transform.X = X

myTarget.Transform.Y = y

myTarget.Transform.Z = Z

Dim procDef As RsProcessDefinition = activeTask.ActiveProcessDefinition

Dim procTempl As RsProcessTemplate = procDef.ActiveProcessTemplate

Dim moveInstr As New RsMoveInstruction(activeTask, procDef.Name, _

procTempl.Name, procTempl.ActiveMotionType, _

workObject.Name, robTarget.Name, tool.Name)

path.Instructions.Add(moveInstr)

End If

End Sub

BR Klaus

Thanks!
Some questions:

Dim tool As RsToolData = activeTask.ActiveTool

CurX = tool.Frame.GlobalMatrix.t.x

CurY = tool.Frame.GlobalMatrix.t.y

CurZ = tool.Frame.GlobalMatrix.t.z

Here vi get tool position related to wobj0, not to our work object, isnt’ it?
Another question is axis configurations, are they missed here?

Do you know if it’s possible just to “click” on the Teach Instruction button control via API?

Hi Sergej.
First no there ain’t any axis config and second i don’t know, but you can read the current pos of the robot and then use this sub to teach a new target.

BR Klaus