0

I'm currently working on a demo project from LinMot. The problem I ran into is that I'm unable to write the values I get of the fieldbus to the variables I have to work with.

enter image description here

As you can see in the image I'm able to grab the correct values of the fieldbus. Ie line 30: StateVar is the value I expected. However after the bitshift uistate should be 8. You can see the same behaviour in line 32 and 36.

At first I thought that I might be overwriting uistate in a different line but it's the only time I try to write to the variable. Also I can't make changes to the code itself.

Does someone have a clue what's happening here?

Edit:

This is the main:

// **************************************************************************
// Init axis parameters on program first run
// **************************************************************************
IF NOT bFirstRun THEN
    LM_Init_Axis_1();   // Init LMAxis_1 parameters
    
    bFirstRun := TRUE;
END_IF

// **************************************************************************
// Read inputs of a LinMot EtherCAT (-EC) drive
// **************************************************************************
LMAxis_1_Axis.DrvToPlc := FC_LM_ReadEC(LMAxis_1_AdrIN);


// **************************************************************************
// General Code
// **************************************************************************

LMAxis_1_Power(Axis:=LMAxis_1_Axis);    // This function block must run cyclically as it updates the data in the axis struct (tstLM_Axis)
LMAxis_1_Reset(Axis:=LMAxis_1_Axis);
LMAxis_1_Home(Axis:=LMAxis_1_Axis);

LMAxis_1_TorqueLimiting(Axis:=LMAxis_1_Axis);

LMAxis_1_ParaAccess(Axis:=LMAxis_1_Axis);

LM_Example_Axis_1(); // Call example program for init and cyclic positioning


// **************************************************************************
// Write outputs of a LinMot EtherCAT (-EC) drive
// **************************************************************************
FC_LM_WriteEC(LMAxis_1_AdrOUT, LMAxis_1_Axis.PlcToDrv);

In main LM_Example_Axis_1 is called. LM_Example_Axis_1 consists of three parts. Initilisation, error handling and controling a servo drive.

This is the initilisation part of LM_Example_Axis_1:

(* Init *)
InitTrig(CLK:=Init);
IF InitTrig.Q AND NOT LMAxis_1_Axis.Status.Error THEN
    InitState:=1;
    InitDone := FALSE;
END_IF

CASE InitState OF
    0:  InitState := InitState;

    1:  IF NOT LMAxis_1_Power.Status THEN
            LMAxis_1_Power.Enable := TRUE;
        ELSE
            InitState := 2;
        END_IF

    2:  IF NOT LMAxis_1_Axis.Status.Homed THEN
            LMAxis_1_Home.Execute := TRUE;
        ELSE
            LMAxis_1_Home.Execute := FALSE;
            InitState := 3;
        END_IF

    3:  IF LMAxis_1_Axis.Status.Homed AND LMAxis_1_Power.Status THEN
            InitDone := TRUE;
            InitState := 0;
            Init := FALSE;
        END_IF
END_CASE

I get stuck on InitState = 1 and the reason is that LMAxis_1_Power.Status does not return true. The screen shot in the original post is from the class LMAxis_1_Power. To make it more clear here is also the variable declaration part.

enter image description here

flyingchris
  • 316
  • 4
  • 10
  • Can you show how/where "Axis" is declared and where the code you are executing is located? – Fred Aug 02 '22 at 10:38
  • edited for better describing the problem – flyingchris Aug 02 '22 at 11:13
  • 3
    Your initial screenshot shows the left-hand side of all assignments is FALSE for all variables, while the right-hand side is not. Have you checked that this code is actually executed, for instance by setting a breakpoint? If so, are you seeing the assignment actually fail (i.e. assignment executes but the variable does not receive the value? – Fred Aug 02 '22 at 11:21
  • Sooo. It's kind of buggy but with breakpoints it works. It actually finishes the init. However without breakpoints it does not work. Unfortunatly I think thats were I have to do a bit of investigating again. Thx – flyingchris Aug 02 '22 at 11:59
  • 1
    If you see the assignments working when stepping into the code, but the values are always FALSE when you enter the code block, then it seems these variables are reset to FALSE somewhere else in the code, or that they are defined in the wrong scope so that you are actually writing to a new copy upon each invocation of the code. – Fred Aug 02 '22 at 12:29
  • As Fred pointed out, it's either being reset somewhere or you are modifying a copy instead. Try putting break points EVERYWHERE you write to those variables to see if you are overwriting, and everywhere you pass/return the object to see if it's being copyed. – Guiorgy Aug 02 '22 at 13:07
  • I think you are misunderstanding me. When I use breakpoints to skip through the code uistate does not get set back to 0. Neither are the other booleans set back to FALSE. Skipping through the code with breakpoint somehow makes it work. – flyingchris Aug 02 '22 at 15:29

1 Answers1

0

So as it turns out @Fred you where correct. After a lot of testing I found the solution.

I'm indeed overwriting the values of the fieldbus. Because as it turns out the demo project was not natively designed to run on a Raspberry Pi. On the native platform you have to make an active attempt to read of and write to the fieldbus.

However if you convert the platform to Raspberry Pi Codesys already maps your inputs from and outputs to the fieldbus. So by reading of the fieldbus you overwrite the already gained values.

tl;dr

In main remove those lines:

LMAxis_1_Axis.DrvToPlc := FC_LM_ReadEC(LMAxis_1_AdrIN);
[...]
FC_LM_WriteEC(LMAxis_1_AdrOUT, LMAxis_1_Axis.PlcToDrv);

then things work out on the Raspberry Pi.

flyingchris
  • 316
  • 4
  • 10