KAREL WAIT FOR conditions

  • I am trying to create a more robust WAIT FOR in a KAREL program by implementing a simple timeout condition;


    let's suppose my old code was

    Code
    WAIT FOR condition

    where condition usually is a simple boolean expression (e.g. DIN[1] AND DIN[2])


    What I want to do is

    Code
    WAIT FOR condition OR timeout_expired


    problem is the compiler doesn't like when you put mixed AND or OR in the same expression and gives me this error

    Quote

    "AND" and "OR" cannot both be specified in a condition.


    Has anyone encountered this issue? How do you solve it in an elegant way that doesn't involve a brutal 'put the condition test inside a REPEAT UNTIL loop' ?

  • Place your Ad here!
  • I have no issues when trying to WAIT FOR a simple condition like a single AND or OR, the issue arise when I try to mix ANDs and ORs

  • I'm sorry, I completely missed the last part.
    You're correct, the compiler does not allow mixing ANDs and ORs in any way.
    It works the same way as the WAIT instruction in TP programs.


    Assuming you only need to apply ands and ors to IO, you could define your condition in a marker.


    The marker cannot be written from KAREL, you'll need a TP program to define it:

    Code
    :M[1] = (DI[1] AND !DI[2]);


    Then you can wait on it:

    Code
    WAIT FOR MRK[1] = ON OR timeout = TRUE
  • Actually I didn't know about Markers and it could be a great workaround if you have few conditions that needs to be scanned many times;
    sadly I need a more general method since I have a lot (and variable number) of WAIT FOR, that would mean I need to define an 'initializing' TP program for all those conditions.
    Thanks anyway, appreciated!


    P.S. I ended up using the brutal REPEAT UNTIL loop with a couple of functions to wrap the TIMER instructions

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account
Sign up for a new account in our community. It's easy!
Register a new account
Sign in
Already have an account? Sign in here.
Sign in Now

Advertising from our partners