Moving robot bases using Python script

Hello I have created a Python script to move a robot base when the script is called.
The script works fine when I give afixed numbers for the position matrix of the base.
But I want to move the base using variables (real signals) added in robot behavior and receive the values through OPC-UA connection. When I put variables instead of fixed numbers the script does not work.

Here is the script:
from vcScript import *
from vcHelpers.Robot2 import *
from vcMatrix import *

robot = getRobot()
base = robot.Bases[31]
comp = getComponent()
move_base_signal = comp.findBehaviour(“MoveBaseBooleanSignal”)
comp_move_signal = comp.findBehaviour(“CompMoveSignal”)
x_signal = comp.findBehaviour(“XRealSignal”) #signals received from opc-ua server
y_signal = comp.findBehaviour(“YRealSignal”)
z_signal = comp.findBehaviour(“ZRealSignal”)

def OnSignal( signal ):
if signal == move_base_signal:
if signal.Value == True:

def movebase():

mtx = base.PositionMatrix

vec = mtx.P
vec.X = x_signal
#when I put a number it works fine (example: vec.X = 300) but as a variable it gives error
vec.Y = y_signal
vec.Z = z_signal
mtx.P = vec
base.PositionMatrix = mtx

Your comp.findBehaviour(“XRealSignal”) returns a vcSignal object, not a value of the signal.
You need to get the latest value of the signal e.g. vec.X = x_signal.Value

1 Like

Thanks a lot. It is working.
I want this script also to set a boolean signal so I could activate another script.
I mean something like:
in script 1: bool_signal1 = comp.findBehavior(“”)
bool_signal1.Value = true

in script2: bool_signal2 = comp.findBehavior(“”)
def OnSignal (signal):

then I connect the signals in the simulator.
But when I tried to do that the signal does not become true, or becomes true but the other script is not executed. I tested both of the scripts alone and they work.

This is some very basics of using signals which you can probably find out from the API documentation or the academy.

The issues there are that you need to use vcSignal.signal(value), and that the signal behavior needs to be connected to the script behavior for the OnSignal method to be called.

1 Like