Most of the programs in the system, after being initialized, run in a cyclic steady state simulation loop. For this case the programs code may be split into two logical functions (subroutines or methods), "initialization" and "cyclic advance". In the case of a C++ implementation a class constructor may be used for initialization. A possible third function can be "closure" for the removal of shared computational resources that may have been allocated when the program runs, so that the program may call this function before exiting. We refer to the code of theses functions as "task functions". The writing of the task functions does not require the use of the DTK API. For programs that must run in real-time, the real-time synchronizing code is not included in these task functions, but is introduced outside of these task functions, so that the code of these task functions may be used on other platforms, in other applications and testing the code is easier. The task functions provide enough output variables so that any needed changing system state information, like for example position, angular acceleration, and time can be gotten from the output variables. The task functions provide enough input variables so that all changing inputs are passed to the task functions. The code of these task functions may preserve the dynamical state of its task or the dynamical state of its task may be passed to the task functions as a combination of input/output variables. The later case may be more resource (CPU and memory usage) efficient in some cases. When possible the cyclic advance task function should allow the user to specify the time to advance to. Configuration files may be read by the initialization task function.
Simple test programs that use these task functions are an important part of the development of the simulator system. Simple test programs just print variables to standard output. Inputs to simple test programs are computed in the simple test program, like for example from a sine function with a reasonable scaling period. Simple test programs are written in C or C++. Simple test programs are written in one source file that does not include any of the source code of the task functions.
/* Test pseudo code for the wombat dynamics module * The two task functions being tested are: * wombat_init() and wombat_advance(). * This particular example passes the wombat state * variables in and out and does not keep a copy * of the state variables in the code of the task * functions. This saves having to copy variables in * the task functions, but assumes that the user will * not change them between wombat_advance() calls. */ big float time = 0.00 state data type x input data type i set_state_to_initial_value(x) wombat_init(time, x) while 1 { /* setup next input value i. */ i = sin(0.07 * time) /* advance the requested time */ time = time + 0.01 /* This advances the wombat dynamics to time "time" and * does so with input i. The state input/output is x. */ wombat_advance(time, i, x) print(time, i, x) } /* end test pseudo code for the wombat dynamics module */