Dynamic variable access in Program Error

I am a student at schmalkalden university, working on the Delta Robot Project, which was built by B&R PLC. I am trying to build modbus communication between B&R plc and Raspberry_Pi to get x,y value and use in the program(PlotBotPrg).

I wrote program 3, which gets value manually for testing the data type , which worked without any error,

VAR CONSTANT
  Pos1 : McPointType := (Pos := (X := 0, Y := 0, Z := -431));
  Pos2Base : McPointType := (Pos := (X := 10, Y := 10, Z := -370));
END_VAR

VAR
  Pos2 : McPointType;
  TestX : UINT := 30;
  TestY : UINT := 30;
END_VAR

PROGRAM _MAIN
  
  Pos2 := Pos2Base;
  Pos2.Pos.X := UINT_TO_REAL(TestX);
  Pos2.Pos.Y := UINT_TO_REAL(TestY);
  
  Feedrate(21000);
  
  MoveL(Pos1);
  WaitTime(1.0);
  
  MoveL(Pos2);
  WaitTime(1.0);
  
  MoveL(Pos1);
  WaitTime(1.0);

END_PROGRAM

But when I wrote Program 4, using the variable from the communication value,i could build and transfer without error. The logic for pos2 is moving to 0,0,-370, but it should move to 10,10,-370. But in program watch window i see the variable are having the value of X as 10 and Y as 10, no idea why these value are not read in program running

VAR CONSTANT
  Pos1 : McPointType := (Pos := (X := 0, Y := 0, Z := -431));
  Pos2Base : McPointType := (Pos := (X := 10, Y := 10, Z := -370));
END_VAR

VAR
  Pos2 : McPointType;
  X_Register : UINT;
  Y_Register : UINT;
END_VAR

PROGRAM _MAIN
  
  Pos2 := Pos2Base;
  Pos2.Pos.X := UINT_TO_REAL(X_Register);
  Pos2.Pos.Y := UINT_TO_REAL(Y_Register);
  
  Feedrate(21000);
  
  MoveL(Pos1);
  WaitTime(1.0);
  
  MoveL(Pos2);
  WaitTime(1.0);
  
  MoveL(Pos1);
  WaitTime(1.0);

END_PROGRAM

image.png

now with program 5-it shows syntax error(0) in Visu- i have tried to trigger after reaching Pos1

image.png

Hello,

Your Variable Declaration is only defining Variables localy inside the ST-Motion Movement Programm. This Programm is running in a separate Interpreter Context and does have its own Memory Context. If you want to Access data from the PLC you can use the Declaration in the Program, with special Key words or the Configuration of the AxesGroup-Feature Program.

Declaration in the Program
AS-Help - ST-Motion Programm , Usage of PLC Variables in Motion Program

Declaration in the AxesGroup-Feature Program
AS-Help - AxesGroup Feature Program

For the Syntax Error i am not yet sure where the difference of the 2 Programs are, but you can go back to first variant and start from there.
There are some issues with the last 2 pictures, i think its the Limit for your user level, you can post the pictures on an second post again.

Greetings
Michael

1 Like

Hello,

You have used the Variable Initialisation in one of the Programs for local Variables.
Please be aware that this Initialisation might be confusing, as it is only executed at the load of a program. The program stays in memory and at the second run this inizialisation will be not executed again.
If there are Start Values for not Constant Variables i recomment to do the inizialisation in the Program.

AS-Help - ST-Motion Program Variable Inizialisation

This Inizialisation is only executed once at the first load of the Program.

VAR
  TestX : UINT := 30;
  TestY : UINT := 30;
END_VAR

In this way the Variables get the start Value on each Program Start.

VAR
  TestX : UINT;
  TestY : UINT;
END_VAR
PROGRAM _MAIN

TestX := 30;
TestY := 30;

END_PROGRAM 

Greetings
Michael

1 Like

Hi @Sanjana_Jaishankara what is the status of your topic?