Example 3 - Vehicle doors
Example 3 - Vehicle doors:
Task:
The aim is to count how often a vehicle door is opened. It is also important to know how long the door takes to open and close in order to detect possible wear on the drive. The signals 'OPEN' and 'CLOSED' are available, each of which goes to true in the end position of the door.
Solution:
TIME_OPEN = stopwatch(!CLOSED, OPEN, {hold: true});
TIME_CLOSE = stopwatch(!OPEN, CLOSED, {hold: true});
COUNT_OFFEN = counter(OPEN, {storage: 'sto_COUNT'});
Functions used
Explanation:
-
TIME_OPEN
:stopwatch()
is called with two arguments in start-stop mode. The clock starts when the door is no longer closed and stops when it has reached the open end position. With thehold: true
option, the measured value is held until a new measurement is completed. -
TIME_CLOSE
: Similar to the previous one, here for the opposite direction. -
COUNT_OFFEN
: The counter counter() counts how often a positive edge appears on the OPEN signal, i.e. the door has been opened. A persistent memory is also specified here so that the counter value is not lost when the software is restarted.