RobotStudio event

exporting a vector from C# to ABB robot studio [moved from RobotStudio]

saharqaadan
edited October 2013 in Developer Tools

Hello

Could  you please help me with an example, how to make some function for exporting a vector to RobotStudio?

i am doing my own add-in , using API Documentation i can use the DataDeclerationInstruction example to declare my force vector, but i could not export the vector itself

I will be grateful for any information.

Best regards,
Post edited by Jonathan Karlsson on

Comments

  • Hello,

    Could you be more specific in what you mean by "exporting to RobotStudio"? Do you want to get the vector into a RAPID program you have on a virtual controller?
  • Hello Joman,
    yes , i create a class '' MatrixCalculation '' , in this class finally i have two force vector in the x and y directions .
    i need to export these two vector to rapid program in ABB RS .
    Note: these two vector are varying according to an excel sheet that have the coordinates of the original workpiece ( so everytime i might use different data ) 



  • Ok, then I understand. There have been several discussions about similiar objectives before, and if you wish to read more broadly about it check out http://developercenter.robotstudio.com/Index.aspx?DevCenter=RobotCommunication&OpenDocument&Url=../RobotCommunicationAppManual/doc30.html . 

    For your problem I can provide the following example, given you have a RAPID module which has the variable you wish to manipulate. As far as I know there is no data type called "vector" in RAPID, but I could be wrong. This example manipulates a robot target variable, you can change the data type to fit with your application.

    // Get a reference to the controller. This example simply picks the first controller available, you probably want to swap this for something more elegant
     robotCont = new Controller(ABB.Robotics.RobotStudio.Controllers.ControllerManager.ControllerReferences[0].SystemId);

                    //find the task the vector variable is in
                    ABB.Robotics.Controllers.RapidDomain.Task tRob1 = robotCont.Rapid.GetTask("T_ROB1");

                    //get the data of the variable, NOTE: change "theMod" to your module and "myVar" to the name of your variable
                    ABB.Robotics.Controllers.RapidDomain.RapidData rd = tRob1.GetRapidData("theMod", "myVar");

                    //This example modifes a robot target, not a vector
                    ABB.Robotics.Controllers.RapidDomain.RobTarget newTarget = new ABB.Robotics.Controllers.RapidDomain.RobTarget();
                    if (rd.Value is ABB.Robotics.Controllers.RapidDomain.RobTarget)
                    {

                        //Request mastership of Rapid before writing to the controller               
                        using (Mastership.Request(robotCont.Rapid))
                        {     
                                newTarget.FillFromString2("[ [1800, 1000, 1600"], [1, 0, 0, 0], [1, 1, 0, 0], [ 9E9, 9E9, 9E9, 9E9, 9E9, 9E9] ]");
                                rd.Value = newTarget;
                        
                        }
                    }

    Hope this helps.
  • thank you so much , i will change to use pc sdk instead of using API alone, i hope it works,  i will get back to you when i am done
    i am looking forward to make it working well
  • Hello Joman,
    i did it correctly using API , but i have small question :  the code in C#  which have the vector and i declare it successfully to rapid is below:
    // ***This example requires a running VC***
                    Station station = Project.ActiveProject as Station;
    // this defines the name of my vector '' myMatrix1'' and it is datatype is '' num'' , and dimension is an array called '' valuesxValues'' ,now here is my question ( please see 
    //the question by the end of the code )
                    RsGenericDataDeclaration myGenDDString1 = new RsGenericDataDeclaration("myMatrix1", "num", CalMat.valuesxValues);
                    // Set the InitialExpression of the DataDeclaration.
                    myGenDDString1.InitialExpression        = "\"xValues\"";
                    // Set the module name the DataDeclaration should be syncronized to.
                    myGenDDString1.ModuleName               = "myModule_xValue";
                    // Define the DataDeclaration as variable.
                    myGenDDString1.StorageType              = RapidStorageType.Variable;
                    // Make sure the DataDeclaration is synchroinized when the task is.
                    myGenDDString1.Synchronize              = true;
                    // Add the DataDeclaration to the ActiveTask.
                    station.ActiveTask.DataDeclarations.Add(myGenDDString1);
                    // Syncronize the DataDeclarations to the VC.
                    System.Collections.Generic.List<SyncLogMessage> syncLog_2 = new System.Collections.Generic.List<SyncLogMessage>();
                    station.ActiveTask.SyncData(myGenDDString1.ModuleName + "/" + myGenDDString1.Name, SyncDirection.ToController, syncLog_2);


    Question: how to see the elements of this array in rapid?
                    
                  
  • Do you mean how to look at the value of this newly created RAPID VAR (myMatrix1) using c#? In that case that line in my example

    ABB.Robotics.Controllers.RapidDomain.RapidData rd = tRob1.GetRapidData("theMod", "myVar");

    Is what reads variables in RAPID modules, and as in the example you should make sure that what you're getting back is the correct type.

    Sorry if I misunderstood.
  • Hello, 
    i am reading from C# to rapid . 
    and i dont use ABB.Robotics.Controllers ( i think this is for SDK) , if i switch from API to use SDK i think also i can not read my vector because as in your example 
      using (Mastership.Request(robotCont.Rapid))
                        {     
                                newTarget.FillFromString2("[ [1800, 1000, 1600"], [1, 0, 0, 0], [1, 1, 0, 0], [ 9E9, 9E9, 9E9, 9E9, 9E9, 9E9] ]");
                                rd.Value = newTarget;
                        
                        }
    you have a constant values of newTarget, but in my case i dont know it ,  i just have the name of the vector.

    regards,



  • It's possible to include both ABB.Robotics.Controllers and ABB.Robotics.RobotStudio.Controllers at the same time. You just have to write out or use "using" to specify which one you mean at each instance. 

    But what I meant was that after using 

    ABB.Robotics.Controllers.RapidDomain.RapidData rd = tRob1.GetRapidData("theMod", "myVar");

    With "theMod" as myModule_xValue" and "myVar" as "myMatrix1" you would then get the value in the "rd" variable.

  • Hey Joman,
    i am trying to apply your code but i have an error :'' that robotCont is not used in the contest!! ''
    // Get a reference to the controller. This example simply picks the first controller available, you probably want to swap this for something more elegant
     robotCont = new Controller(ABB.Robotics.RobotStudio.Controllers.ControllerManager.ControllerReferences[0].SystemId);

  • Are you sure you have declared robotCont somewhere before that line? ( Controller robotCont; )