RobotStudio event

write robtarget

Hi all

I'm trying to change a position of a robtarget from PC SDK

for starters, I followed some code I found in the forum for writing a robtarget with the values of the current position. It is as follows:


 Dim CurrPos As RobTarget
        CurrPos = Controller.MotionSystem.ActiveMechanicalUnit.GetPosition(CoordinateSystemType.World)
        Dim MiRobtarget As New RobTarget
        Dim MiRapidData As RapidData = Controller.Rapid.GetRapidData("T_ROB1", "modRobotStudio", "pTest")

        MiRobtarget = DirectCast(MiRapidData.Value, RobTarget)
        MiRobtarget = CurrPos

        Using master = Mastership.Request(Controller.Rapid)

            Try
                MiRapidData.Value = MiRobtarget  'Here I get the error
            Catch ex As Exception
                MessageBox.Show(ex.Message)

            Finally


            End Try

        End Using

When trying to write the rapiddata.value, it gives me an error:
 "An argument specified by the client is not valid for this type of operation."

Could anyone help me? What I'm doing wrong?

thank you


Comments



  • Hi londoneye,
     
    Your using master looks a bit funny since I see no "as Mastership" in it. But that is not your issue.
     
    Instead if you look in the PC SDK application manual, [Using the PC SDK - Rapid domain - Working with RAPID data] you can see this:
    [quote]TheRapidData object stores the path to the RAPID data. But this is not enough if you want to access its value (at least not if you want to modify it). To do that you need to create another object, which represents the value of the RAPID data.
    In the RapidDomain namespace there are types representing the different RAPID data types. To create the object needed to represent the RAPID data value you use the RapidData property Value and cast it to the corresponding type, for example Num, Boolor Tooldata. [/quote]
    Your MiRapidData is still just a generic cast of rapiddata, which can not really be modified in the way you do. (Two different types).
     
    So you need to set your miRobTarget to your miRapidData and then change the miRobTarget.
    But note that this only changes the value in the controller memory, it does not change the text in the progrom module.
    Here is a code snippet that I ran in RobotStudio (hence the logger stuff, change it to something that works  in the environment you use).
     

    ctrl.Logon(UserInfo.DefaultUser)
    Logger.AddMessage(

    New LogMessage("log on"))


    Using m As Mastership = Mastership.Request(ctrl.Rapid) 'changed as mastership


    'directcast the rapid data - should have a detection+try catch if its not there


    Dim rd As ABB.Robotics.Controllers.RapidDomain.RapidData = ctrl.Rapid.GetRapidData("T_ROB1", "Module1", "Target_10")


    'declare a variable of the data type


    Dim rapidRobTarget As ABB.Robotics.Controllers.RapidDomain.RobTarget


    'test that the data type is correct before cast


    If TypeOf rd.Value Is ABB.Robotics.Controllers.RapidDomain.RobTarget Then


    Try


    rapidRobTarget =

    DirectCast(rd.Value, ABB.Robotics.Controllers.RapidDomain.RobTarget)


    'change stuff


    Logger.AddMessage(

    New LogMessage("before - " + rapidRobTarget.ToString()))


    rapidRobTarget.FillFromString2(ctrl.MotionSystem.ActiveMechanicalUnit.GetPosition(CoordinateSystemType.World).ToString)
    Logger.AddMessage(

    New LogMessage("after - " + rapidRobTarget.ToString()))


    Catch ex As Exception


    Logger.AddMessage(

    New LogMessage(ex.Message))


    End Try


    End If


    End Using


    ctrl.Logoff()