WebbotLib AVR library
WebbotLib It just does it
  C++ documentation  C documentation

errors.h

"All programs run properly and never come across an unexpected situation" - said the inexperienced programmer!
The problem with microcontrollers is that you cannot assume that they have a screen. So how can they tell you that something has gone wrong? A computer can give you the 'blue screen of death' or a 'This program has terminated unexpectedly' message so at least you know something has gone wrong. But how do we do that on something without a screen? Luckily most boards come with at least one LED that the program can control.
So this library uses one of these LEDs to indicate when there is a problem. If the board has no LEDs then we can't help! Each system file will register the LED to be used for errors - assuming that one is present on the board. Once an error is reported via 'setError' then this LED will start flashing.
Once an error has been reported and the LED starts blinking then any future calls to setError will be ignored - ie the LED only reports the first error. Fix it and then you may find others.
Each error has its own unique number. This library only uses negative error numbers - but your code should only use positive error numbers but obviously you can re-use a given error number from one project to the next.
Library errors make the LED blink at twice the speed as your own errors but they both have a 2 second gap to signal the start of the count. Counting the blinks will give you the error number.
This file defines each of the error numbers used by the library itself. The file gives details on each of the errors and, once you get an error, you should read the entry as it doesn't always mean that the problem is in my code - it may be that your code has called mine with incorrect parameters.

 

Function

 


setError(ERROR_CODE err)

Indicate that an error has happened.
The parameter specifies the error number.

ERROR_CODE getError()

Returns the current error code or 0 if there is no error.
You may decide that if there is an error that you want your robot to stop and shutdown once an error situation has been met. You could achieve this in your main appControl loop as follows:-
#include "errors.h"
void appControl(LOOP_COUNT loopCount, TICK_COUNT loopStart){
    if(getError()!=0){
        // We've got an error. So stop all motors.
    }else{
        // There are no errors - so perform one iteration of the main loop
    }
}

setErrorLog(Writer log)

Specify an alternative location to send error messages to.
The status led can be used to flash error messages but sometimes the micro-controller board either has no on board LED or the board is buried in a shell and so the LED cannot be seen.

This function allows you to specify an alternative routine to display the error message.
This could be a UART (which has previously been initialised to the required baud rate) using:-
setErrorLog(uart1SendByte);

Valid XHTML 1.0 Transitional