Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

Rotating object and closing door (change value to 0)

HPster
2015-10-18
2015-10-21
  • HPster - 2015-10-18

    Hi Expert,

    I got some problem on my code.

    First will be on rotating object, what code to use to rotate object in the program.

    Second will be after opening door on my program (value to 30) and try to close back the door (change value to 0).
    Below is my code for open and close door.

    TON1(IN := train1, PT:= T#18s);
    OUT1:=TON1.Q;
       IF OUT1 AND door1<=30 THEN
          door1:=door1+1;
       END_IF
       IF door1>=30 THEN
          train2:=1;
       END_IF
    TON2(IN := train2, PT:= T#5s);
     OUT2:=TON2.Q;
          IF OUT2 AND counter <=30 THEN
          counter:=counter+1;
          END_IF
          IF OUT2 AND door1 >=0 THEN
             door1:=door1+-counter;
          END_IF
    

    Thanks in advance for helping.

     
  • HPster - 2015-10-19

    Hi, any expert can help me?

    I'm totally new to Codesys and need help for my problems.

    Thanks in advance.

     
  • Anonymous - 2015-10-19

    Originally created by: scott_cunningham

    Not sure what you mean by , but looking at your code, I think you are using the timer functions incorrectly. Maybe this information helps you:

    The way TON() works, is when setting IN = TRUE, the timer starts and Q will go TRUE after PT is reached. Q stays TRUE until you disable (IN = FALSE) one time for TON().

    For example, if you want a every 10 seconds, you would need to do:

    TON1(IN:=TRUE, PT:=T#10S);
    IF TON1.Q THEN
       TON1(IN:=FALSE);
       count := count + 1;
    END_IF
    

    I often do:

    TON1(IN:=NOT(TON1.Q), PT:=T#10S);
    IF TON1.Q THEN
       count := count + 1;
    END_IF
    

    NOTE: Even if you have an exact PLC scan, this timer is not exactly 10 seconds - it is a little longer - you loose at least one scan inside the TON() function as it is starting (this means, if you want a tick exactly every 10 seconds, you need to check the realtime clock and work that way).

    Hopefully, this helps you work forward.

    Also, remember you can set a break and step through your code in a debug way to see what is happening.

     
  • shooter - 2015-10-19

    on some objects you can change the angle like a polygone and others, a line and rectangle is not having the angle.
    a way to do this by making a subvis from single line.
    for the change use a counter for each door apart, and a global pulsemaker.

     
  • HPster - 2015-10-21

    Thanks guys for your inputs. I will work on my program and see how it goes.

     
  • shooter - 2015-10-21

    after 18 seconds the door will close fast, as you count then rapid up.

     

Log in to post a comment.