[Beremiz-devel] SFC issue : FBD transition not working if first transition is '1'

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[Beremiz-devel] SFC issue : FBD transition not working if first transition is '1'

Paul ROUVIERE

Hi,

 

I found an issue with the following SFC starting with a '1' transition from Step0 to Step1. In that case the following transition made with FBD does not working.

If I set the '1' transition after Step1 (to Step0) and FBD from Step0 to Step1 everything is OK.

 

Below the SFC graph you can find the generated 'C' code.

 

My understanding is that the action associated to Step0 are never executed because the first time the function is called the transition to Step1 is active so it immediately activate Step1 and deactivate Step0. FBD is compute only if the following is executed and this is done in Step0 state:

if (active)       {data__->__action_list[__SFC_COMPUTE_FUNCTION_BLOCKS].set = 1;}

 

 

 

  if(__GET_VAR(data__->__action_list[__SFC_COMPUTE_FUNCTION_BLOCKS].state)) {

    __SET_VAR(data__->,LE8_OUT,,LE__BOOL__DINT(

      (BOOL)__BOOL_LITERAL(TRUE),

      NULL,

      (UINT)2,

      (DINT)__GET_EXTERNAL(data__->DOOR_CURRENT_POSITION,),

      (DINT)__GET_EXTERNAL(data__->DOOR_UP_TARGET_POSITION,)));

  }

 

I'm also wondering why "set" field is used in Step0 and test is done on "state"?

Is it a known behavior?

I can do a workaround by not using a '1' transition for the first step.

 

 

 

 

 

 

void TEST_PROGRAMM_init__(TEST_PROGRAMM *data__, BOOL retain) {

  __INIT_EXTERNAL(DINT,DOOR_CURRENT_POSITION,data__->DOOR_CURRENT_POSITION,retain)

  __INIT_EXTERNAL(DINT,DOOR_UP_TARGET_POSITION,data__->DOOR_UP_TARGET_POSITION,retain)

  __INIT_EXTERNAL(BOOL,RELAIS_OUT_0,data__->RELAIS_OUT_0,retain)

  __INIT_VAR(data__->LE8_OUT,__BOOL_LITERAL(FALSE),retain)

  UINT i;

  data__->__nb_steps = 2;

  static const STEP temp_step = {{0, 0}, 0, {{0, 0}, 0}};

  for(i = 0; i < data__->__nb_steps; i++) {

    data__->__step_list[i] = temp_step;

  }

  __SET_VAR(data__->,__step_list[0].X,,1);

  data__->__nb_actions = 2;

  static const ACTION temp_action = {0, {0, 0}, 0, 0, {0, 0}, {0, 0}};

  for(i = 0; i < data__->__nb_actions; i++) {

    data__->__action_list[i] = temp_action;

  }

  data__->__nb_transitions = 2;

  data__->__lasttick_time = __CURRENT_TIME;

}

 

// Steps definitions

#define STEP0 __step_list[0]

#define __SFC_STEP0 0

#define STEP1 __step_list[1]

#define __SFC_STEP1 1

 

// Actions definitions

#define __SFC_COMPUTE_FUNCTION_BLOCKS 0

#define __SFC_RELAIS_OUT_0 1

 

// Code part

void TEST_PROGRAMM_body__(TEST_PROGRAMM *data__) {

  // Initialise TEMP variables

 

  INT i;

  TIME elapsed_time, current_time;

 

  // Calculate elapsed_time

  current_time = __CURRENT_TIME;

  elapsed_time = __time_sub(current_time, data__->__lasttick_time);

  data__->__lasttick_time = current_time;

  // Transitions initialization

  if (__DEBUG) {

    for (i = 0; i < data__->__nb_transitions; i++) {

      data__->__transition_list[i] = data__->__debug_transition_list[i];

    }

  }

  // Steps initialization

  for (i = 0; i < data__->__nb_steps; i++) {

    data__->__step_list[i].prev_state = __GET_VAR(data__->__step_list[i].X);

    if (__GET_VAR(data__->__step_list[i].X)) {

      data__->__step_list[i].T.value = __time_add(data__->__step_list[i].T.value, elapsed_time);

    }

  }

  // Actions initialization

  for (i = 0; i < data__->__nb_actions; i++) {

    __SET_VAR(data__->,__action_list[i].state,,0);

    data__->__action_list[i].set = 0;

    data__->__action_list[i].reset = 0;

    if (__time_cmp(data__->__action_list[i].set_remaining_time, __time_to_timespec(1, 0, 0, 0, 0, 0)) > 0) {

      data__->__action_list[i].set_remaining_time = __time_sub(data__->__action_list[i].set_remaining_time, elapsed_time);

      if (__time_cmp(data__->__action_list[i].set_remaining_time, __time_to_timespec(1, 0, 0, 0, 0, 0)) <= 0) {

        data__->__action_list[i].set_remaining_time = __time_to_timespec(1, 0, 0, 0, 0, 0);

        data__->__action_list[i].set = 1;

      }

    }

    if (__time_cmp(data__->__action_list[i].reset_remaining_time, __time_to_timespec(1, 0, 0, 0, 0, 0)) > 0) {

      data__->__action_list[i].reset_remaining_time = __time_sub(data__->__action_list[i].reset_remaining_time, elapsed_time);

      if (__time_cmp(data__->__action_list[i].reset_remaining_time, __time_to_timespec(1, 0, 0, 0, 0, 0)) <= 0) {

        data__->__action_list[i].reset_remaining_time = __time_to_timespec(1, 0, 0, 0, 0, 0);

        data__->__action_list[i].reset = 1;

      }

    }

  }

 

  // Transitions fire test

  if (__GET_VAR(data__->STEP0.X)) {

    __SET_VAR(data__->,__transition_list[0],,1);

    if (__DEBUG) {

      __SET_VAR(data__->,__debug_transition_list[0],,__GET_VAR(data__->__transition_list[0]));

    }

  }

  else {

    if (__DEBUG) {

      __SET_VAR(data__->,__debug_transition_list[0],,1);

    }

    __SET_VAR(data__->,__transition_list[0],,0);

  }

  if (__GET_VAR(data__->STEP1.X)) {

    __SET_VAR(data__->,__transition_list[1],,__GET_VAR(data__->LE8_OUT,));

    if (__DEBUG) {

      __SET_VAR(data__->,__debug_transition_list[1],,__GET_VAR(data__->__transition_list[1]));

    }

  }

  else {

    if (__DEBUG) {

      __SET_VAR(data__->,__debug_transition_list[1],,__GET_VAR(data__->LE8_OUT,));

    }

    __SET_VAR(data__->,__transition_list[1],,0);

  }

 

  // Transitions reset steps

  if (__GET_VAR(data__->__transition_list[0])) {

    __SET_VAR(data__->,STEP0.X,,0);

  }

  if (__GET_VAR(data__->__transition_list[1])) {

    __SET_VAR(data__->,STEP1.X,,0);

  }

 

  // Transitions set steps

  if (__GET_VAR(data__->__transition_list[0])) {

    __SET_VAR(data__->,STEP1.X,,1);

    data__->STEP1.T.value = __time_to_timespec(1, 0, 0, 0, 0, 0);

  }

  if (__GET_VAR(data__->__transition_list[1])) {

    __SET_VAR(data__->,STEP0.X,,1);

    data__->STEP0.T.value = __time_to_timespec(1, 0, 0, 0, 0, 0);

  }

 

  // Steps association

  // STEP0 action associations

  {

    char active = __GET_VAR(data__->STEP0.X);

    char activated = active && !data__->STEP0.prev_state;

    char desactivated = !active && data__->STEP0.prev_state;

 

    if (active)       {data__->__action_list[__SFC_RELAIS_OUT_0].reset = 1;}

 

    if (active)       {data__->__action_list[__SFC_COMPUTE_FUNCTION_BLOCKS].set = 1;}

 

  }

 

  // STEP1 action associations

  {

    char active = __GET_VAR(data__->STEP1.X);

    char activated = active && !data__->STEP1.prev_state;

    char desactivated = !active && data__->STEP1.prev_state;

 

    if (active)       {data__->__action_list[__SFC_RELAIS_OUT_0].set = 1;}

 

  }

 

 

  // Actions state evaluation

  for (i = 0; i < data__->__nb_actions; i++) {

    if (data__->__action_list[i].set) {

      data__->__action_list[i].set_remaining_time = __time_to_timespec(1, 0, 0, 0, 0, 0);

      data__->__action_list[i].stored = 1;

    }

    if (data__->__action_list[i].reset) {

      data__->__action_list[i].reset_remaining_time = __time_to_timespec(1, 0, 0, 0, 0, 0);

      data__->__action_list[i].stored = 0;

    }

    __SET_VAR(data__->,__action_list[i].state,,__GET_VAR(data__->__action_list[i].state) | data__->__action_list[i].stored);

  }

 

  // Actions execution

  if (data__->__action_list[__SFC_RELAIS_OUT_0].reset) {

    __SET_EXTERNAL(data__->,RELAIS_OUT_0,,0);

  }

  else if (data__->__action_list[__SFC_RELAIS_OUT_0].set) {

    __SET_EXTERNAL(data__->,RELAIS_OUT_0,,1);

  }

  if(__GET_VAR(data__->__action_list[__SFC_COMPUTE_FUNCTION_BLOCKS].state)) {

    __SET_VAR(data__->,LE8_OUT,,LE__BOOL__DINT(

      (BOOL)__BOOL_LITERAL(TRUE),

      NULL,

      (UINT)2,

      (DINT)__GET_EXTERNAL(data__->DOOR_CURRENT_POSITION,),

      (DINT)__GET_EXTERNAL(data__->DOOR_UP_TARGET_POSITION,)));

  }

 

 

 

  goto __end;

 

__end:

  return;

} // TEST_PROGRAMM_body__()

 

 

Best regards,

Paul Rouviere


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Beremiz-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beremiz-devel