RobotStudio event

PC SDK - Setting Program Pointer

Options
hello
 

my thesis presentation is due in the next few days so if anyone can help me it would be greatly greatly appreciated.

 

i need to set the program pointer.
i am using VB.net to program with PC SDK.


Sets program pointer to the first instruction of a routine (global or local).  
 in the PC SDK help reference file it shows SetProgramPointer as a member of Task.
However when i try to do this in Visual Studio it does not come up as an option.

 

is it possible to do using VB?

and second question if it cant be set, my current program pointer is set at main, so if i edit the routine main it would kinda do what i want anyway.
How do you edit an entire routine?

 

please if anyone can help i have spent weeks trying to get this working.
John Wiberg2011-05-30 16:16:56

Comments

  • sozdemir
    Options
    Hi,
    I managed to change the program pointer by this way (in C#):

                    control.Logon(UserInfo.DefaultUser);
                    Mastership master;
                    master = Mastership.Request(control.Rapid);
                    Task task;
                    task = control.Rapid.GetTask("T_ROB1");
                    task.SetProgramPointer("MainModule", "urunvar");
                    control.Rapid.Start();
                    control.Logoff();

    this code changes the pointer to the proc named "urunVar". Instead of editing entire routine i wrote a proc to do what i want.
    Hope this helps,
    Best


  • John Wiberg
    Options

    In this reply I'm using the "Create a simple PC SDK application" from the PC SDK Application Manual as the base. Its in the "Using the PC SDK" chapter.
    So to paste this in you need to follow the basic instruction from there first. You need a Button1 and a Button2 as well.

    You need a main and a Path_20 proc in the controller, preferably with different actions so that you can see which is run.

    Steps;
    Start controller
    Start app
    doubleclick controller
    click the buttons

    [quote]Imports ABB.Robotics
    Imports ABB.Robotics.Controllers
    Imports ABB.Robotics.Controllers.Discovery
    Imports ABB.Robotics.Controllers.RapidDomain


    Public Class Form1
        Private scanner As NetworkScanner = Nothing
        Private controller As Controller = Nothing
        Private tasks As Task() = Nothing
        Private networkWatcher As NetworkWatcher = Nothing


        Public Sub New()

            ' This call is required by the Windows Form Designer.
            InitializeComponent()

            ' Add any initialization after the InitializeComponent() call.
            Button1.Enabled = False
            Button2.Enabled = False
            Me.scanner = New NetworkScanner
            Me.scanner.Scan()
            Dim controllers As ControllerInfoCollection = Me.scanner.Controllers
            Dim controllerInfo As ControllerInfo = Nothing
            Dim item As ListViewItem
            For Each controllerInfo In controllers
                item = New ListViewItem(controllerInfo.IPAddress.ToString())
                item.SubItems.Add(controllerInfo.Id)
                item.SubItems.Add(controllerInfo.Availability.ToString())
                item.SubItems.Add(controllerInfo.IsVirtual.ToString())
                item.SubItems.Add(controllerInfo.SystemName)
                item.SubItems.Add(controllerInfo.Version.ToString())
                item.SubItems.Add(controllerInfo.ControllerName)
                Me.ListView1.Items.Add(item)
                item.Tag = controllerInfo
            Next

            Me.networkWatcher = New NetworkWatcher(Me.scanner.Controllers)
            AddHandler Me.networkWatcher.Found, AddressOf Me.HandleFoundEvent
            'AddHandler Me.networkWatcher.Lost, AddressOf Me.HandleLostEvent
            Me.networkWatcher.EnableRaisingEvents = True

        End Sub
        Private Sub HandleFoundEvent(ByVal sender As Object, ByVal e As NetworkWatcherEventArgs)
            Me.Invoke(New EventHandler(Of NetworkWatcherEventArgs)(AddressOf AddControllerToListView), New [Object]() {Me, e})
        End Sub
        Private Sub AddControllerToListView(ByVal sender As Object, ByVal e As NetworkWatcherEventArgs)
            Dim controllerInfo As ControllerInfo = e.Controller
            Dim item As New ListViewItem(controllerInfo.IPAddress.ToString())
            item.SubItems.Add(controllerInfo.Id)
            item.SubItems.Add(controllerInfo.Availability.ToString())
            item.SubItems.Add(controllerInfo.IsVirtual.ToString())
            item.SubItems.Add(controllerInfo.SystemName)
            item.SubItems.Add(controllerInfo.Version.ToString())
            item.SubItems.Add(controllerInfo.ControllerName)
            Me.listView1.Items.Add(item)
            item.Tag = controllerInfo
        End Sub

        Private Sub ListView1_MouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListView1.MouseDoubleClick
            Dim item As ListViewItem = Me.ListView1.SelectedItems(0)
            If item.Tag IsNot Nothing Then
                Dim controllerInfo As ControllerInfo = DirectCast(item.Tag, ControllerInfo)
                Button1.Enabled = True
                Button2.Enabled = True
                If controllerInfo.Availability = ABB.Robotics.Controllers.Availability.Available Then
                    If Me.controller IsNot Nothing Then
                        Me.controller.Logoff()
                        Me.controller.Dispose()
                        Me.controller = Nothing
                    End If
                    Me.controller = ControllerFactory.CreateFrom(controllerInfo)
                    Me.controller.Logon(UserInfo.DefaultUser)
                Else
                    MessageBox.Show("Selected controller not available.")
                End If
            End If
        End Sub

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Try
                If controller.OperatingMode = ControllerOperatingMode.Auto Then
                    tasks = controller.Rapid.GetTasks()
                    Using m As Mastership = Mastership.Request(controller.Rapid)
                        'Perform operation
                        tasks(0).SetProgramPointer("Module1", "main")
                        tasks(0).Start()
                    End Using
                Else
                    MessageBox.Show("Automatic mode is required to start execution from a remote client.")
                End If
            Catch ex As System.InvalidOperationException
                MessageBox.Show("Mastership is held by another clizaccent." & ex.Message)
            Catch ex As System.Exception
                MessageBox.Show("Unexpected error occurred: " & ex.Message)
            End Try

        End Sub

        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            Try
                If controller.OperatingMode = ControllerOperatingMode.Auto Then
                    tasks = controller.Rapid.GetTasks()
                    Using m As Mastership = Mastership.Request(controller.Rapid)
                        'Perform operation
                        tasks(0).SetProgramPointer("Module1", "Path_20")
                        tasks(0).Start()
                    End Using
                Else
                    MessageBox.Show("Automatic mode is required to start execution from a remote client.")
                End If
            Catch ex As System.InvalidOperationException
                MessageBox.Show("Mastership is held by another clizaccent." & ex.Message)
            Catch ex As System.Exception
                MessageBox.Show("Unexpected error occurred: " & ex.Message)
            End Try

        End Sub
    End Class[/quote]
  • John Wiberg
    Options
    As you can see I'm using this to move the PP and start execution:
                   tasks = controller.Rapid.GetTasks()
                    Using m As Mastership = Mastership.Request(controller.Rapid)
                        'Perform operation
                        tasks(0).SetProgramPointer("Module1", "Path_20")
                        tasks(0).Start()
                    End Using


  • john thank you for the help.
    this has been a great help, it allowed me to see there was a problem with my system setup.
     
    i worked out the problem i had the whole time, when my mentor was trying to fix another problem he reset all my rab libraries back to version 10. This has been behind alot of my other problems.
    i have now learnt not to listen to my mentor ;)
     
    thank you again for the help and speedy reply.
  • John Wiberg
    Options
    Glad to be of service.
    Thumbs Up
  • Hi,John!
               Maybe there is a problem here.On one controller maybe there are different modules,but it can only be one 'MAIN',and if i want to give a "main routine",i should give it another name,like "main 1""main 2""main 3"... so how can i know the routine name of a module(i want click a button to choose a ".mod"file,and then the vc perform it,so i want the pc get a name by some program)?
  • John Wiberg
    Options
    Hi doc-zoo,
     

    I am sorry, I have problems understanding what exactly you want in most of your responses, including this one. Maybe it would be easier if you posted code and showed what your issue is?

    In my example above you can just change the line

    tasks(0).SetProgramPointer("Module1", "Path_20")
    to whichever module and routine you want. So what they are called does not matter.

     

    How to load a module using the PC SDK is described in the Application manual

    "Using the PC SDK - Rapid domain 
    Working with RAPID modules and programs"

    How to search for specific procedures is described in

    "Using the PC SDK - Rapid domain
    RAPID symbol search"

     

    If you want to know which PROC a .mod file contains before loading it you can just open it like a text file and parse through it to find all PROCs.

     

    Question

     
    John Wiberg2011-09-20 09:17:41
  • hi,John!
     Maybe there is a problem when i expressed myself.The code like this:

     OpenFileDialog openFileDialog1 = new OpenFileDialog();
                openFileDialog1.Filter = "Mod Files (.mod)|*.mod|All Files (*.*)|*.*";
                openFileDialog1.FilterIndex = 1;

     string text1 = openFileDialog1.FileName;

     if (openFileDialog1.ShowDialog() == DialogResult.OK)
                {

    FileInfo filename = new FileInfo(openFileDialog1.FileName);
                    string fn = filename.Name;

    this.master = Mastership.Request(controller.Rapid);

    .................

    ..........

    tasks(0).SetProgramPointer("Module1", "?????")
                        tasks(0).Start()

     

    }

    what should i do here"?????"
  • tasks(0).SetProgramPointer(openFileDialog1.FileName??O"?????")
                        tasks(0).Start()
  • John Wiberg
    Options

    WARNING!
    The way you do that in your code is VERY dangerous. You allow the user to select ANY procedure, regardless of where the robot arm is. That means that you have no control on what the robot actually will do. The user could even mistakenly select the wrong procedure which could lead to damages and injuries.
    You have no way to control which module is loaded and which procedure is selected, I would rethink that design.
    WARNING!

    But I already told you how to do it; Read The Fantastic Manual
    [QUOTE=John Wiberg]How to search for specific procedures is described in
    "Using the PC SDK - Rapid domain
    RAPID symbol search"[/QUOTE] If you need to know the names of procedures you use the SearchRapidSymbol function.

    Continuing on the example above, you need to add two listboxes and two more buttons.
    Steps;
    Start controller
    Start app
    doubleclick controller
    click button3 to list modules in listbox1
    select a module name in listbox1
    click button4 to list procedures in listbox2

    [code]    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
            ListBox1.Items.Clear()
            Dim sProp As RapidSymbolSearchProperties = RapidSymbolSearchProperties.CreateDefault()
            sProp.Types = SymbolTypes.Module
            tasks = controller.Rapid.GetTasks()
            Dim rsCol As RapidSymbol()
            rsCol = tasks(0).SearchRapidSymbol(sProp, String.Empty)
            If rsCol.Count = 0 Then
                ListBox1.Items.Add("Not found")
                Return
            Else
                Dim rs As RapidSymbol
                For Each rs In rsCol
                    ListBox1.Items.Add(rs.Name)
                Next
            End If
        End Sub

        Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
            ListBox2.Items.Clear()
            If ListBox1.SelectedItem = "" Then
                ListBox2.Items.Add("No module selected in ls1")
            Else
                Dim sProp As RapidSymbolSearchProperties = RapidSymbolSearchProperties.CreateDefault()
                sProp.Types = SymbolTypes.Procedure
                tasks = controller.Rapid.GetTasks()
                Dim selModule As ABB.Robotics.Controllers.RapidDomain.Module
                selModule = tasks(0).GetModule(ListBox1.SelectedItem.ToString)
                Dim rsCol As RapidSymbol()
                rsCol = selModule.SearchRapidSymbol(sProp, String.Empty)
                If rsCol.Count = 0 Then
                    ListBox2.Items.Add("Not found")
                    Return
                Else
                    Dim rs As RapidSymbol
                    For Each rs In rsCol
                        ListBox2.Items.Add(rs.Name)
                    Next
                End If
            End If
        End Sub[/code]

  • John Wiberg
    Options
    Please note that in my example above it lists both system modules and program modules. In your code you load a module so then you should take the module name and just list for that directly.
  • Hi,John!
              First thanks a lot for your help ,it helps me a lot!But there is a new problem in my code.

            when i write the code like this:

    ......

    tasks[0].SetProgramPointer(listBox1.SelectedItem.ToString(),listBox2.SelectedItem.ToString());
    tasks[0].Start();

    .. ....            

    there`s an erro  like this:

                       "SetProgramPointer" is not defined in the"ABB.Robotics.Controllers.RapidDomain.Task"

    In chinese like this:

    "?"T?__ 4 ?_oABB.Robotics.Controllers.RapidDomain.Task?__?1??,_?O.?_??_oSetProgramPointer?__?s,?rs?1% F:ABB??-?"<??_? (333) WindowsApplication3WindowsApplication3Form1.cs 733 34 WindowsApplication3<BR>
  • John Wiberg
    Options
    Look at the top of the code, do you have
     using ABB.Robotics.Controllers.RapidDomain;
    Then look at the References, do they have a warning? Are they the correct version?
  • I have using ABB.Robotics.Controllers.RapidDomain;
    and i have done the References, there are no warning, i don`t know whether they are the correct version.and can you give me the address to download it?My RS is 5.13.01
  • By the way,when i use "Reset Program Pointer ",there is no error .May be i use the wrong version
  • Hi,John! Sorry to trouble you again.I have some problems trouble me a lot days.I copy a module and load it,then when i copy another module ,there`s error like:
    "

    Event Message
    Error in T_ROB1-Line6

    Description

    Global routine name main ambiguous.

    Data for this message is not saved in any robot controller event log.

    If acknowledged the message will be removed.

     

    Actions

    Global routine must have names that are unique among all the global types,data,global routines and modules in the entire program .Rename the routine or change the conflicting name.

    "

    the c# code like this:

     

    private void button7_Click(object sender, EventArgs e)
            {

    string localDir = controller.FileSystem.LocalDirectory;
                string remoteDir = controller.FileSystem.RemoteDirectory;
                controller.FileSystem.RemoteDirectory = remoteDir ;
                controller.FileSystem.LocalDirectory = localDir + "/downmod/";
                File.Copy(controller.FileSystem.LocalDirectory + "xadd.mod", controller.FileSystem.RemoteDirectory + "xadd.mod", true);

     

    ......................}

    private void button4_Click(object sender, EventArgs e)
            {
                runxadd();
            }

    public void runxadd()
            {
                string localDir = controller.FileSystem.LocalDirectory;
                string remoteDir = controller.FileSystem.RemoteDirectory;
                if (controller.OperatingMode == ControllerOperatingMode.Auto)
                {
                    tasks = controller.Rapid.GetTasks();
                    this.master = Mastership.Request(controller.Rapid);
                    UserAuthorizationSystem uas = controller.AuthenticationSystem;
                    if (uas.CheckDemandGrant(Grant.LoadRapidProgram))
                    {
                        tasks[0].LoadModuleFromFile(remoteDir + "xadd.mod", RapidLoadMode.Replace);
                        // RapidSymbolSearchProperties sProp1 = RapidSymbolSearchProperties.CreateDefault();
                        // sProp1.Types = SymbolTypes.Procedure;
                        // tasks = controller.Rapid.GetTasks();
                        //Module selModule1 = tasks[0].GetModule(strmainname);
                        //RapidSymbol[] rsCol1 = selModule1.SearchRapidSymbol(sProp1, string.Empty);
                        tasks[0].ResetProgramPointer();
                        tasks[0].Start();

                    }
                    //tasks[0].ResetProgramPointer();
                    // this.master.Dispose();
                    this.master.Dispose();

                }
  • the module code like this:
    the"Module1.MOD"code like this:

    MODULE Module1
     CONST robtarget p10:=[[524.77,-968.58,952.68],[0.422439,-0.0807052,0.55852,-0.709286],[-1,-1,-1,0],[9E+09,9E+09,9E+09,9E+09,9E+09,9E+09]];
     CONST robtarget pHome:=[[113.55,-940.17,909.68],[0.394354,-0.0151111,0.0387188,-0.918018],[-1,-1,-1,0],[9E+09,9E+09,9E+09,9E+09,9E+09,9E+09]];
     CONST robtarget p30:=[[179.47,1049.78,948.14],[0.880088,-0.416906,0.074412,0.214701],[0,-1,-1,0],[9E+09,9E+09,9E+09,9E+09,9E+09,9E+09]];
     PROC main()
      rInitAll;
      rHome;
      rMoveRoutine;
      WaitTime 0.3;
     ENDPROC
     PROC rHome()
      MoveJ pHome, v7000, z50, tool0;
     ENDPROC
     PROC rInitAll()
      AccSet 100, 100;
      VelSet 100, 5000;
     ENDPROC
     PROC rMoveRoutine()
      MoveJ p10, v4000, z50, tool0;
      MoveJ p30, v4000, z50, tool0;
     ENDPROC

    ENDMODULE

     

     

    the "xadd.mod"code like this: 

    MODULE MainModule
      PROC main()
     VAR robtarget rob_tar1;
          rob_tar1:=CRobT();
     rob_tar1:=Offs(rob_tar1,30,0,0);
     MoveL rob_tar1,v1000,z50,tool0;
      ENDPROC
    ENDMODULE
  • John Wiberg
    Options
    [code]Event Message
    Error in T_ROB1-Line6

    Description

    Global routine name main ambiguous.[/code]

    This just means that in RAPID you are not allowed to have the PROC name "main" more than once. Its a reserved name.

    Just rename your "main" PROC to something else and you will be fine, since if you use it in two different modules at the same time, then its not really a "main" PROC anyway.
  • Because i can only use "ResetProgramPointer()"method that can only reset the pp to the "main",i can`t use the "SetProgramPointer()"method. when i use "SetProgramPointer",there`s always problem i have ask you before.So can you tell me how can i solve it?
  • Because i can only use "ResetProgramPointer()"method that can only reset the pp to the "main",i can`t use the "SetProgramPointer()"method. when i use "SetProgramPointer",there`s always problem i have ask you before.So can you tell me how can i solve it?
  • John Wiberg
    Options
    How would the "ResetProgramPointer" function know which main is the true main? This is not a PC SDK issue, its a requirement in RAPID. You can only have one PROC named "main".
  • john2012
    Options

    Hi,

    I have using ABB.Robotics.Controllers.RapidDomain and i have done the References, there are no warning, i don`t know whether they are the correct version.
    john20122012-05-21 08:05:59
  • Philipp
    Options
    Hi,

    i tried to apply the example obove to start Rapid code. All is working fine but
        tasks(0).Start()
    takes no effect.

    Setting the program pointer works (Visual prof) but Rapid programm is not running. Do i have to change controller settings in RobotStudio?
    I am using a virtual controller, is it working at all?