How to read global variables from robot program

Hi all,

I would like to read defined global variables from the robot program in my case I am using Kuka Sim (KRL) I want to implement a python script and pass these global variables value to it, not sure how to do it and how to call the py script passing these var from KRL. Thank you.


As of right now there is no direct way to access KRL variables with Python and vice versa. The only option right now is to convert the variable to IO signals via KRL and decode those signals in your Python code by reading the IO values.

Here are two examples that utilize this:

Robot sends value via IO to other robot:
Send_Value_Robot_To_Robot.vcmx (4.5 MB)

Conveyor reads height of parts, sends the height via IO signals to robot, robot adapts pick height:
16bit_Real_Signal_Sensor_Example.vcmx (3.2 MB)


Cool! nice workaround I will try it later, thanks Mastu.

@Matsu, would you know how to read digital outputs from robot with python? Thank you.

More or less like every other signal that is handled in the Python script of a component. You will need to connect the input behavior with the Python script (see properties of the Boolean input behavior)

Then you can utilize the OnSignal event which will trigger for every signal that is connected with the script. Therefore you will need to check in the OnSignal method which signal was triggered, e.g. by checking the name of the signal.

from vcScript import *

comp = getComponent()

def OnSignal( signal ):

if signal.Name == ‘Visibility_OnOff’:
comp.Visible = signal.Value

Toggle_Visibillity.vcmx (16.4 MB)


Thanks so much @mastu. I understood what you meant, however (maybe I did not explain myself clearly :sweat_smile:) I wanted to see if it was possible to read the status of a robot output but the output is not connected (maybe it is not possible) for example:

$OUT[1] = TRUE

I want to have a py script that reads the status of that output. At the moment I have a workaround where I set the outputs to a new component and the component map it back to robot inputs so I can read the inputs with:

rx = comp.getBehaviour(“Inputs”)
inputs = rx.input

But output can only be set, cant read its status :frowning:

All this because I need to use the py script inside the robot prg at a certain time in the code. I am new to kuka sim so it has not been easy with the custom scripts :sweat_smile:

In fact, the answer to this question is also written in the vcBooleanSignalMap help file, in fact, I have always felt that the name taken here is a bit confusing, in fact, for the output Boolean SignalMap, he is essentially a BooleanSignalMap, so in fact, he can also use input, in other words, in the In other words, in vcBooleanSignalMap, input is to read the signal value, and output is to assign the value to the signal, instead of being limited to input signals can only use input, output signals can only use output.
I hope you understand what I mean, sorry if it makes you feel strange (after all English is not my native language). :melting_face:

As far as I know it is not possible to access anything from the KUKA robot program directly from Python level.

But if you want to start certain Python code in the robot program, that’s possible. Just create a Python script behavior in the robot model and add the code that should be executed there.

Then use the Python command in the program window of the robot to call the script in the robot program


Hello mastu

Thank you for the application example! Very nice work indeed!
I am struggling with the “autoconnect” feature of the 16 bit signals, is there a way that you could explain how to get it to work?
thanks in advance

Hi @Shadow,

Just select the 16bit_Real_Signal_Sensor and activate the “Interfaces” view. You then should be able to see the “RobotInterface” on the sensor side as well as the “Connect Special Accessories” inteface on the robot side. If you connect this interface, the automatic connection of the 16 pre-defined signals should be triggered.