After you write your boundary checking code, you'll also wish your algorithm to behave nicely even if the input is bad. Let's say you have a model that tries to follow an input reference (desired) signal. The reference signal is supposed to be a sinus with amplitude 1. This means that your expected range is [-1, 1]. Under normal conditions the output will be like this:
If for some reason you get an unexpected value (a division by zero here, a faulty sensor reading there) and you have no safety net in place, your output will become erratic:
As you see, the sudden jump takes time to die out and distorts the system even after the signal stabilizes. The simplest way to take care of unexpected jumps is to go back to the last good (i.e. inside boundary) signal and use that until the signal is valid again:
This simple strategy made sure that there was not too much distortion after the signal resumed to a valid state.
Moral of the story: Always specify the boundaries of inputs and outputs (for large systems in an interface control document). Check them and make sure you have the necessary code guarding against cases where something unexpected happens. Ignore this and you will waste away your life chasing elusive bugs (as has this poor soul countless times at his own peril).
No comments:
Post a Comment