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”)
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:
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