Search code examples
codesys

PLC_OPEN MC_MoveAbsolute with same position


sometimes it may happen that MC_MoveAbsolute is called with the same current position of the axis, in this case the "done" or "busy" states cannot be used to manage the end of the function because the function must not perform any movement. I'm a newbie to these types of controls, the examples I've studied always use a state machine like this:

1: MC_MoveAbsolute .exec: = true;
  if MC_MoveAbsolute .busy then // never goes high if AxisActPos = MC_MoveAbsolute.position;
   MC_MoveAbsolute .exec: = false;
   nextStep: = 2;
end_if
2:
    if MC_MoveAbsolute.done then
          // do something

what is the best way to handle these situations?


Solution

  • I normally don't use the busy bit.

    1: MC_MoveAbsolute .exec: = true;
       nextStep: = 2;
    
    2: if MC_MoveAbsolute.done then
           MC_MoveAbsolute .exec: = false;
           // do something
       end_if
    

    The nature of the case structure is that when the step is incremented, the new code won't be executed until the next program scan. So, presuming that you are executing your MC_MoveAbsolute function block on every scan outside of the case, the done bit will be set appropriately (depending on whether motion was needed or not) before it is checked in step 2 of the case.