RobotStudio event

how to update a work object in VC

Hi all,

I'm trying to have my robot grip each product that passes in front of it. Each product comes in a random orientation. I have one work object and update it in a macro by detaching it from the previous product and attaching it to the next product. This works well in the macro and the work object shows its change of host in the simulation. However, the robot still doesn't know where the new location for the work object is because it hasn't been updated to the VC.

I tried to use SyncData to update the work object in VC and always get the following error:
The given key was not present in the dictionary.
I posted it as a question and someone said it's impossible to do it since it's thru VSTA.

I tried to use SyncToController(new ArrayList()) but it would just slow everything down.

What should I do?

Sam

Comments

  • Hi
    Download Visual C# Express from Microsoft it's free and write an addin instead of a VSTA macro. Because as I said before it looks like the SyncData method doesn't work in VSTA!!! but if you write an addin it works.
    Per Svensson
    Robotics and Vision Specialist
    Consat Engineering
  • The problem is that I don't know where to start to write an add-in for RS. I know how to program in C#.
  • Per Svensson
    Robotics and Vision Specialist
    Consat Engineering
  • I read it and tried the code. However, I still couldn't compile it correctly (the compiler says there is no function for AddinMain())

    Plus, won't AddinMain() be executed automatically at the beginning of the simulation stead of be called as a macro by event manager?

  • Hi Sam,

    It is correct that Visual Studio addins don't support VSTA-style macros, so their methods cannot be called directly by the event manager.
    Instead, you can have the addin listen to virtual signals that are set by events in the event manager. For example:
    [code]public static void AddinMain()
    {
        Simulator.StateChanged += new EventHandler(Simulator_StateChanged);
    }

    static void Simulator_StateChanged(object sender, EventArgs e)
    {
        Station stn = Project.ActiveProject as Station;
        if (Simulator.State == SimulationState.Running)
        {
            stn.VirtualSignals.VirtualSignalChanged += new VirtualSignalChangedEventHandler(VirtualSignals_VirtualSigna lChanged);
        }
        else
        {
            stn.VirtualSignals.VirtualSignalChanged -= new VirtualSignalChangedEventHandler(VirtualSignals_VirtualSigna lChanged);
        }
    }

    static void VirtualSignals_VirtualSignalChanged(object sender, VirtualSignalChangedEventArgs e)
    {
        switch (e.Signal)
        {
            case "MyVirtualSignal1":
            {
                // Do something
            }
            break;
            case "MyVirtualSignal2":
            {
                // Do something else
            }
            break;
        }   
    }
    [/code]

    The AddinMain() method is executed when the addin is loaded (normally when RobotStudio is started), not when simulation starts.

    regards,
    Johannes


    Johannes Weiman
    Software Engineer
    ABB Robotics
  • Thank you, Johannes.

    I'm trying to adapt your code. First the program asks for a new reference. So I add a reference to ABB.Robotics.RobotStudio.Proxy.

    After I compile it into the *.dll file, should I place it into the DLL folder for RS to automatically run it?

    Sam

    chen2008-7-9 22:55:52
  • Hi
    You should place it in RobotStudios binaddins folder
    Per Svensson
    Robotics and Vision Specialist
    Consat Engineering
  • Hi Johannes:

    I have a compile error with your sample code:

    Error 1 An object reference is required for the non-static field, method, or property 'ABB.Robotics.RobotStudio.Stations.Simulator.StateChanged'

    The error points to:


    Simulator.StateChanged += new EventHandler(Simulator_StateChanged);

    Do you know why?

    Thanks,

    Sam

    chen2008-7-9 23:38:21
  • Hi
    You should reference to ABB.Robotics.RobotStudio.Stations

    But a good rule is to always add
    ABB.Robotics.RobotStudio
    ABB.Robotics.RobotStudio.Math
    ABB.Robotics.RobotStudio.Enviroment
    ABB.Robotics.RobotStudio.Stations
    ABB.Robotics.RobotStudio.Stations.Forms

    All located under the RobotStudio SDK directory


    Per Svensson
    Robotics and Vision Specialist
    Consat Engineering
  • You should NOT have a reference to ABB.Robotics.RobotStudio.Proxy in a Visual Studio project, it is only intended for VSTA!
    If you add the references that Per described (along with some using statements) the code should compile.

    /Johannes

    Johannes Weiman
    Software Engineer
    ABB Robotics
  • Hi Johannes,

    I followed the instructions to create an add-in thru Visual Studio for syncronizing a work object to the VC. I use the following command:

    station.ActiveTask.SyncData("Module1/workObjBattery", SyncDirection.ToController, new System.Collections.Generic.List<SyncLogMessage>());

    However, I get the following error:

    SYS_CTRL_E_EXEC_STATE: Operation is illegal in current execution state.
    ERROR: .
    apid.c[6943]: org_code: -33 new_code: 0xc0049007; RobRapidModuleImpl.cpp[502];  7/10/2008 12:24:11 PM 

    I can't understand this. Is it something that has to do with RAPID side?

    Thank you,

    Sam

  • This is probably due to that the VirtualController is executing the rapid program. Try to update the workobject without starting the simulation just to see if that's the case.
    Per Svensson
    Robotics and Vision Specialist
    Consat Engineering
  • Hi
    Tested this and the reason for the message is that you can't syncronize when the controller is running which make sense. To be able to change the data in a workobject(while running) you need to use PC SDK(part of Robot Application Builder) to write data to the controller.
    Per Svensson
    Robotics and Vision Specialist
    Consat Engineering
  • Hi Per:

    Right now I am using only Robot Studio and Visual Studio Add-ins. And I want to update the work object during the simulation. As I understand your opinion, SyncData(...) doesn't work when the simulator is on. Could you explain where to find and how to use the PC SDK(part of Robot Application Builder)? Is it a big leap from Robot Studio? I only bought Robot Studio.

    Thank you,

    Sam

    chen2008-7-11 15:41:40
  • Hi
    I think RAB is on the RobotWare CD from version 5.10 (i'm a partner so I have access to a specific download area where it is) if not you should get in contact with your ABB sales guy (it's free, the only thing is if you want to run against a real controller then you need some options on the controller).
    But when you are running  on a virtual controller it's just a matter of choose the right option when you create the controller.

    1. PC Interface -  if you want to be able to communicate between a PC and the controller.
    2. FlexPendant Interface - if you want to be able to run Applications on the FlexPendant.

    There are some examples in the documentation of RAB that is quite usefull and there is also a thread (Robot Application Builder) in this forum about it.

    Per Svensson
    Robotics and Vision Specialist
    Consat Engineering
  • Hi all:

     

    I think I can summarize my question as:

     

    In actual projects we constantly send new data (work object, target, etc) to the robot controller. How can we use Robot Studio or Visual Studio Add-in to simulate it?

     

    1. In actual projects we can just write to variables on the controller. But Robot Studio only allows digital signal Connection, which means we cannot write general data.

     

    2. Robot Studio provide functions like

    SyncToController

    and

    SyncData<?:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /> 

    But they do not run during the simulation because the controller is on.

    Does it mean that I can never update a work object or a target or send data through the combination of Robot Studio and Visual Studio Add-in?

    Sam

  • Hi again
    The RobotStudio object library is for RobotStudio and not the Controller it self more than that you can up/download stuff you have created in RS to the controller (and some other tasks).
    To mess with the controller there is another object library (RAB as I have talked about).

    So in your case it's just a matter of using one more object library so that you can mess with the controller as well in your addin.
    Per Svensson
    Robotics and Vision Specialist
    Consat Engineering
  • Thanks, Per.

    I'm reading the manual on RAB. It seems that it can directly access the data in the RAPID. That is what I need.

    I still have a question, how do I create a controller for the virtual controller used in Robot Studio?

    Sam

  • You have to use the systembuilder located in the controller menu to build your own virtual controller.
    You can find info regarding systembuilder in the help system for RS

    Per Svensson
    Robotics and Vision Specialist
    Consat Engineering
  • Hi
    Here are some example code for writing to a workobject, beware of that I haven't added any error handling!!!

    Code:
    image

    Per Svensson
    Robotics and Vision Specialist
    Consat Engineering
  • Hi Per,

    I tested your code by inserting it into a macro and all went well except that I get the error:

    Unable to find the specified file. 7/11/2008 4:56:23 PM 

    from the LogOn function:


    controller.Logon(
    UserInfo.DefaultUser);
    I think it might be the Robot Studio already using this User to log in the controller. I'll just create a 2nd user for my RAP.

    Thanks,

    Sam

  • Hi
    If you are using RobotStudio 2008 (preview version of 5.11) then you could comment away the login because RS has allready done that.
    Per Svensson
    Robotics and Vision Specialist
    Consat Engineering
  • Actually I'm using RS 5.10. And the problem persists. I tried logging off first, creating new users, etc. But still, as soon as I use the Logon command (controller.Logon(UserInfo.DefaultUser);), I get the same error:

    Unable to find the specified file.

    chen2008-7-14 16:39:30