Skip to content
brindza edited this page Oct 23, 2011 · 3 revisions

Calling standard Lua print functions from within Debug

The Debug module provides a cleaner way of printing debug statements. The Debug module overwrites the standard Lua print function, but it does store a reference to the original function in a variable called `luaprint`. If you wish to call the original print function from within the Debug module, you must instead call `luaprint`.

The printf command has also been overwritten. This functions in the same manner as the original printf, except that it, like the original Debug.print function, now accepts a debug level as its first argument.

Parameters

The overwritten `print` function takes a _debug level_ as its first argument, then accepts any number of printable values as subsequent arguments. The debug level is used to determine whether or not a statement should be printed based on a _debug level_ stored within a special, Debug-dedicated section of shared memory.

If the debug level of a particular print command is less than the debug value stored in shared memory, then that print command will be displayed.

Vision Debug

There are special functions for printing debug messages pertaining to vision. These print functions take _vision debug level_ as a first argument which is similar to the _debug level_ mentioned above but specific to vision, and also take a _vision debug mode_ as a second argument. After these two arguments, the vision print functions accept an arbitrary number of printable arguments. These are the `vprint` and `vprintf` functions.

'Vision Debug Mode' values are stored in a visionmode table within the Debug module. Vision print functions will only print a value when its debug level is less than that stored in memory and when its vision debug mode matches up with that stored in shared memory.

To set debug level, vision debug level, or vision debug mode, call the Debug.set_debuglevel(val), Debug.set_visiondebuglevel(val) or Debug.set_visiondebugmode(mode) functions, respectively. These will overwrite the value in shared memory with the new value.

To add a mode to the set of vision debug modes stored in shared memory, call Debug.add_visiondebugmode(mode). To remove a mode, call Debug.remove_visiondebugmode(mode).

visionmode = {}
visionmode.none = 0
visionmode.ball = 1
visionmode.goal = 2
visionmode.line = 4
visionmode.midfieldLandmark = 8
visionmode.freespace = 16

Inside ./Player/Vision/detectBall.lua:

...
Debug.vprint(2,1,'ground check fail');
...
Debug.vprint(1,1,'BALL DETECTED');
...

Running Lua on the robot:

> dofile('init.lua')
> require('Debug')
> Debug.set_visiondebuglevel(2)
> Debug.set_visiondebugmode(1)
-- vision process now printing:
'BALL DETECTED'
> Debug.set_visiondebugmode(0)
-- vision process now printing no debug information
> Debug.set_visiondebuglevel(3)
> Debug.set_visiondebugmode(1)
-- vision process now printing 
'BALL DETECTED' 
-- and 
'ground check fail'
Clone this wiki locally