Stoppuhr in KAREL realisieren

  • Hey Leute,


    hat jemand von euch schon einmal so etwas wie eine Stoppuhr in KAREL programmiert und würde mir einen Beispielcode zur Verfügung stellen?
    Ich möchte eine Oberfläche für das iPendant erstellen und dort eine Stoppuhr starten für Taktzeitmessungen.
    Ideen und Vorschläge zur Realisierung wären auch sehr hilfreich.


    Grüße

  • ANZEIGE
  • Hier mal was aus der Karel Referenz:



    CONNECT TIMER Statement
    Purpose: Causes an INTEGER variable to start being updated as a millisecond clock
    Syntax : CONNECT TIMER TO clock_var
    where:
    clock_var :a static, user-defined INTEGER variable
    Details:
    • clock_var is presently incremented by the value of the system variable $SCR.$COND_TIME
    every $SCR.$COND_TIME milliseconds as long as the program is running or paused
    and continues until the program disconnects the timer, ends, or aborts. For example, if
    $SCR.$COND_TIM E=32 then clock_var will be incremented by 32 every 32 milliseconds.
    • You should initialize clock_var before using the CONNECT TIMER statement to ensure a
    proper starting value.
    • If the variable is uninitialized, it will remain so for a short period of time (up to 32 milliseconds)
    and then it will be set to a very large negative value (-2.0E31 + 32 milliseconds) and incremented
    from that value.
    • The program can reset the clock_var to any value while it is connected.
    • A clock_var initialized at zero wraps around from approximately two billion to approximately
    minus two billion after about 23 days.
    • If clock_var is a system variable or a local variable in a routine, the program cannot be translated.
    Note If two CONNECT TIMER statements using the same variable, are executed in two different
    tasks, the timer will advance twice as fast. For example, the timer will be incremented by 2 *
    $SCR.$COND_TIME every $SCR.$COND_TIME ms. However, this does not occur if two or
    more CONNECT TIMER statements using the same variable, are executed in the same Task



    DISCONNECT TIMER Statement
    Purpose: Stops updating a clock variable previously connected as a timer
    Syntax : DISCONNECT TIMER timer_var
    where:
    timer_var :a static, user-defined INTEGER variable
    Details:
    A–111
    A. KAREL LANGUAGE ALPHABETICAL DESCRIPTION MARRC75KR07091E Rev D
    • If timer_var is not currently connected as a timer, the DISCONNECT TIMER statement has
    no effect.
    • If timer_var is a system or local variable, the program will not be translated.
    See Also: Appendix E , ‘‘Syntax Diagrams,’’ for additional syntax information, CONNECT TIMER
    Statement
    Example: The following example moves the TCP to the initial position in PR[1], sets the INTEGER
    variable timevar to 0 and connects the timer. After moving to the destination position in PR[2], the
    timer is disconnected.
    DISCONNECT TIMER Statement
    move_to_pr1 – Call TP program to move to PR[1]
    timevar = 0
    CONNECT TIMER TO timevar
    move_to_pr2 – Call TP program to move to PR[2]
    DISCONNECT TIMER timevar

    Einmal editiert, zuletzt von rob76 ()

  • Hey,


    danke für die Antwort. ;)


    Ich habe mich jetzt für eine Variante ohne KAREL und mit einem TP-Programm entschieden.
    TIMER[1]=RESET;
    TIMER[1]=START;
    .
    .
    .
    TIMER[1]=STOP;


    Wenn der Timer in unterschiedlichen Programmen gestartet und gestoppt wird, muss der Timer auf "Global" gestellt werden.

Erstelle ein Benutzerkonto oder melde dich an um zu kommentieren

Du musst ein Benutzerkonto haben um einen Kommentar hinterlassen zu können

Benutzerkonto erstellen
Neues Benutzerkonto für unsere Community erstellen. Geht einfach!
Neues Benutzerkonto erstellen
Anmelden
Du hast bereits ein Benutzerkonto? Melde dich hier an.
Jetzt anmelden