# API - get current Instruction

**URL:** <https://tech-community.robotics.abb.com/t/api-get-current-instruction/1550>\
**Category:** RobotStudio\
**Created:** [November 26, 2007, 11:11am UTC](https://tech-community.robotics.abb.com/t/api-get-current-instruction/1550 "2007-11-26T11:11:49Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Grrzzz](https://avatars.discourse-cdn.com/v4/letter/g/839c29/32.png) [@Grrzzz](https://tech-community.robotics.abb.com/u/Grrzzz)\
**Post date:** [November 26, 2007, 11:11am UTC](https://tech-community.robotics.abb.com/t/api-get-current-instruction/1550/1 "2007-11-26T11:11:49Z")

</div>

Hi there,

I am trying to implement a “remote Control” Interface (based on UDP network messages) for RobotStudio. I am using C# for this.

At the moment I am stuck. All I want is the following:  
I created some simple instructions using the virtual flexpendant (like movej, movel, etc.).  
Now I am running this code and during this execution I want to send the current executed command to my remote Control.

Also, can I somehow access the program counter (for getting the current line number in code which is executed).

And, last but not least: Can I send “pre-written” programs to RobotStudio with my remote Control?

---

<div class="post-metadata">

**Author:** ![Johannes\_Weiman\_old\_account](https://dub1.discourse-cdn.com/flex005/user_avatar/tech-community.robotics.abb.com/johannes_weiman_old_account/32/3345_2.png) [@Johannes\_Weiman\_old\_account](https://tech-community.robotics.abb.com/u/Johannes_Weiman_old_account)\
**Post date:** [November 26, 2007, 1:34pm UTC](https://tech-community.robotics.abb.com/t/api-get-current-instruction/1550/2 "2007-11-26T13:34:41Z")

</div>

Hi,

The RobotStudio API doesn’t contain functionality for communicating directly with the controller/VC. For that purpose you should use the PC SDK which is part of the Robot Application Builder product. With it you can upload programs, retrieve the program pointer and much more.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/flex005/user_avatar/tech-community.robotics.abb.com/system/32/6_2.png) [@system](https://tech-community.robotics.abb.com/u/system)\
**Post date:** [November 26, 2007, 11:52pm UTC](https://tech-community.robotics.abb.com/t/api-get-current-instruction/1550/3 "2007-11-26T23:52:01Z")

</div>

Hi!

I guess I need a function very similar to this.  
I have built a scene with the API and then I simulate a path.  
When there is a collision between the robot and the objects in the scene I need to know between which points of the path the collision took place.  
Therefore I want to write a new CollisionEventHandler.  
Is there a function which tells me which moveInstruction is currently active?

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/flex005/user_avatar/tech-community.robotics.abb.com/system/32/6_2.png) [@system](https://tech-community.robotics.abb.com/u/system)\
**Post date:** [November 28, 2007, 4:58pm UTC](https://tech-community.robotics.abb.com/t/api-get-current-instruction/1550/4 "2007-11-28T16:58:18Z")

</div>

Hi again!

Isn’t there any possibility to get the current Instruction or at least the current position of the TCP during simulation?

best regards, Matthias

---

<div class="post-metadata">

**Author:** ![apox](https://dub1.discourse-cdn.com/flex005/user_avatar/tech-community.robotics.abb.com/apox/32/2392_2.png) [@apox](https://tech-community.robotics.abb.com/u/apox)\
**Post date:** [November 29, 2007, 9:25am UTC](https://tech-community.robotics.abb.com/t/api-get-current-instruction/1550/5 "2007-11-29T09:25:56Z")

</div>

Hi,

you have to register an EventHandler for a mechanism. Here is a litle snippet:

//Register Event Handler for each mechanism  
Station station = Project.ActiveProject as Station;

foreach (RsIrc5Controller \_ctrl in station.Irc5Controllers)  
{  
foreach (RsTask \_task in \_ctrl.Tasks)  
{  
\_task.Mechanism.JointValuesChanged += new EventHandler(MyJointListener);  
}  
}

Every time a joint value changes (-\>JointValuesChanged), the method “MyJointListener” is called:

private void MyJointListener(object sender, EventArgs e)  
{  
Station station = Project.ActiveProject as Station;  
if (station == null) return;

double deg = new double[6];  
double conf = new double[6];

foreach (RsIrc5Controller \_ctrl in station.Irc5Controllers)  
{  
int currentRobot = 0;  
foreach (RsTask \_task in \_ctrl.Tasks)  
{  
Mechanism mechanism = \_task.Mechanism;

double actualJointValues = mechanism.GetJointValues();  
deg[0] = RADtoDEG(actualJointValues[0]);  
deg[1] = RADtoDEG(actualJointValues[1]);  
deg[2] = RADtoDEG(actualJointValues[2]);  
deg[3] = RADtoDEG(actualJointValues[3]);  
deg[4] = RADtoDEG(actualJointValues[4]);  
deg[5] = RADtoDEG(actualJointValues[5]);

// get current Configurations  
ConfigurationData confData = mechanism.GetConfiguration();

// get current TCP coords  
RsToolData tool = \_task.ActiveTool;  
if (tool != null)  
{  
// Get the TCP position  
Vector4 trans = tool.Frame.GlobalMatrix.t;  
trans.x \*= 1000.0;  
trans.y \*= 1000.0;  
trans.z \*= 1000.0;

String xStr = trans.x.ToString();  
String yStr = trans.y.ToString();  
String zStr = trans.z.ToString();

}//if tool  
}// task  
}// controller  
}

with

public double RADtoDEG(double d)  
{  
return d \* 180.0 / Math.PI;  
}

Hope it helps.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/flex005/user_avatar/tech-community.robotics.abb.com/system/32/6_2.png) [@system](https://tech-community.robotics.abb.com/u/system)\
**Post date:** [November 29, 2007, 10:39pm UTC](https://tech-community.robotics.abb.com/t/api-get-current-instruction/1550/6 "2007-11-29T22:39:52Z")

</div>

Thank you! Your code snippet was really helpful.

Best regards, Matthias

---

<div class="post-metadata">

**Author:** ![MaWi81](https://avatars.discourse-cdn.com/v4/letter/m/53a042/32.png) [@MaWi81](https://tech-community.robotics.abb.com/u/MaWi81)\
**Post date:** [April 11, 2008, 1:40pm UTC](https://tech-community.robotics.abb.com/t/api-get-current-instruction/1550/7 "2008-04-11T13:40:49Z")

</div>

[QUOTE=Johannes Weiman]The RobotStudio API doesn’t contain functionality for communicating directly with the controller/VC. For that purpose you should use the PC SDK which is part of the Robot Application Builder product. With it you can upload programs, retrieve the program pointer and much more.  
[/QUOTE]  
Is it possible to combine both? Use PC SDK and connect to the RS-API?

On the one hand I need the collisionReport-Feature of RS and on the other hand possibilities to retrieve the program pointer and to change a path if it causes collisions.

---

<div class="post-metadata">

**Author:** ![Niklas\_Skoglund](https://avatars.discourse-cdn.com/v4/letter/n/5fc32e/32.png) [@Niklas\_Skoglund](https://tech-community.robotics.abb.com/u/Niklas_Skoglund)\
**Post date:** [April 14, 2008, 10:44am UTC](https://tech-community.robotics.abb.com/t/api-get-current-instruction/1550/8 "2008-04-14T10:44:24Z")

</div>

It is possible to combine PC-SDK and RobotStudio API.

Under [Robot Application Builder](http://forums.robotstudio.com/forum_topics.asp?FID=9&PN=1) you will find more information about PC-SDK and a download link.

From your RobotStudio Add-In project, add references to the assemblies needed from the PC-SDK.

---

<div class="post-metadata">

**Author:** ![MaWi81](https://avatars.discourse-cdn.com/v4/letter/m/53a042/32.png) [@MaWi81](https://tech-community.robotics.abb.com/u/MaWi81)\
**Post date:** [April 14, 2008, 6:28pm UTC](https://tech-community.robotics.abb.com/t/api-get-current-instruction/1550/9 "2008-04-14T18:28:31Z")

</div>

Okay, that works generally, but one additional question: is it possible to directly include RobotStudio’s Controllers in PC-SDK-classes? Explicit or implicit casting is not possible:

```auto
ABB.Robotics.Controllers.Controller controller = (ABB.Robotics.Controllers.Controller) station.Irc5Controllers[0];
```

Background is still to either use RS for collision-detection and simultaneously to get the program pointer (or anything else) for automatically getting (and changing) the instructions that cause collisions. At the moment I try to use the NetworkScanner inside the AddIn but that seems to be a little bit long winded.

---

<div class="post-metadata">

**Author:** ![Niklas\_Skoglund](https://avatars.discourse-cdn.com/v4/letter/n/5fc32e/32.png) [@Niklas\_Skoglund](https://tech-community.robotics.abb.com/u/Niklas_Skoglund)\
**Post date:** [April 14, 2008, 10:59pm UTC](https://tech-community.robotics.abb.com/t/api-get-current-instruction/1550/10 "2008-04-14T22:59:09Z")

</div>

Try this. (namespaces omitted)

[code]RsIrc5Controller stationCtrl = …

Controller pcSdkCtrl = new Controller(stationCtrl.SystemId)[/code]

Those two classes has nothing in common when it comes to inheritance, but they both represents a controller, in different ways.

Some background if you want…

The ABB.Robotics.RobotStudio.Stations.RsIrc5Controller represents the model of the controller in the Station Object Model. An important role for this object is to keep the task collection which in turns keeps information about targets, workobjects, tools etc.

Lets take the RsRobtarget as an example. Its counterpart in RAPID is the robtarget datatype. But there is not a 1:1 relation between a RsRobtarget and a robtarget data declaration in RAPID. If you change the name of an RsRobtarget in a RobotStudio station, nothing will happen in the controller, because you are just modifying the station model.

The ABB.Robotics.Controllers.Controller provides an API to a real or virtual controller. This class can be used to load/save RAPID modules, take mastership etc. If you make a modification to a RAPID data declaration using the Controller class, the real data in RAPID will be modified.

---

<div class="post-metadata">

**Author:** ![MaWi81](https://avatars.discourse-cdn.com/v4/letter/m/53a042/32.png) [@MaWi81](https://tech-community.robotics.abb.com/u/MaWi81)\
**Post date:** [April 16, 2008, 3:28pm UTC](https://tech-community.robotics.abb.com/t/api-get-current-instruction/1550/11 "2008-04-16T15:28:19Z")

</div>

Hm, this code-fragment did not work. ☹

But the SystemId-hint is also usable with my former workaround:

```auto
RsIrc5Controller stationCtrl = ....

ControllerInfo controllerInfo = null;
if ((new NetworkScanner()).TryFind(new Guid(stationCtrl.SystemId), out controllerInfo))
pcSdkController = ControllerFactory.CreateFrom(controllerInfo);
```

Thank you for your extensive explanations!
