the preferred embodiment of the invention is described here in detail . fig1 shows a motor controller 100 connected to a low - cost dc motor 101 . observational circuit 102 generates a digital observational signal 113 of a multitude of bits comprising information on the state of the motor 101 and external state connection 103 . the external state connection 103 can comprise a multitude of bits . in one embodiment , external state connection 103 connects to a switch that outputs a digital signal indicating when it is depressed . for example , if the invention were used in a toy car , external state connection 103 could connect to the bumper of the car to signal a collision . in an alternate embodiment , external state connection 103 is connected to at least one microcontroller or at least one additional motor controller 100 to coordinate action between a plurality of motors 101 . there are many generally known methods of observing the state of a dc motor . in one embodiment , a tachometer or a wire touching the commutator of a motor generates an electric waveform with frequency inversely proportional to the angular velocity of the motor . from this signal , motor velocity can be observed by measuring the frequency of the waveform , and motor position can be determined by counting the number of periods . in an alternate embodiment , the velocity of the motor 101 is observed by measuring the magnetic field , and position is determined by integrating velocity with respect to time . the variables of the state of the motor that the observational circuit 102 samples may comprise velocity , position , or torque , or a combination of these . training circuit 104 parses the observational signal 113 into a sequence of independent commands that can be stored in memory 106 . training circuit 104 operates according to a user - generated training signal 105 . in one embodiment , training signal 105 is a one bit active high digital signal activating training circuit 104 . while training circuit 104 is activated , the output of control circuit 107 is a weak or zero - value signal , which does not drive the motor 101 , which is directly or indirectly manipulated by the user to train the motor controller 100 . the method to parse an observational signal such as observational signal 113 goes as follows . a motor state variable function is selected from a set of predetermined functions to represent a motor state variable described by observational signal 113 over the time interval beginning either at the end of the last command or at the activation of training circuit 104 if this is the first command , and continuing to the current time . the set of predetermined motor state variable functions is chosen such that the time integral of each command over an interval between two samplings is unique among the set of functions . in one embodiment of the invention , this condition is achieved by maintaining a set of motor state variable functions that are scalar multiples of a unit function . the selected motor state variable function can then be uniquely represented in a command by its scalar multiple of the unit function . this embodiment has the advantage of simple implementation that uses a small number of bits . the observed motor state variable is subtracted from the expected value of said variable according to the selected motor state variable function . the absolute value of the difference is compared against a threshold by means of a comparator circuit . the threshold is determined by a function of inputs which comprise the number of observations in the duration of the command . if all other inputs are held constant , the threshold is a monotonically decreasing function of this number . the selection of motor state variable function and subsequent comparisons are repeated according to the above until one of the following conditions is met : the absolute value of the differences between the observed and expected motor state variables exceeds the threshold , for some predetermined , finite number of observations , or the absolute value of the difference between the current observed and expected motor state variables exceeds the threshold and the signal on the external state connection 103 changes . if the signal on the external state connection 103 changes but the absolute value of the difference between the current observed and expected motor state variables does not exceed the threshold , said conditions are not met . for the particular example of the toy car mentioned previously , these conditions differentiate between possible behaviors of executing a new command when the toy car runs into a block and executing the current command , pushing the blocks out of the way . if one of said conditions is met , a command comprising the selected motor state variable function , the external state information , and a duration for execution is stored in memory . the duration comprises a multiple bit digital signal that may represent either time or angular position . in the preferred embodiment , the motor state variable is velocity , and the duration comprises the position of motor 101 or an arbitrary maximum value if said condition was met because of a change of the signal on the external state connection 103 . the training method then repeats from the beginning while training circuit 104 is activated and there is room to store additional commands in memory 106 . it will become apparent to persons skilled in the art that this method can be extended to parse a multitude of signals that are not otherwise related to motor control , but the behavior of which can be similarly represented by dependencies on external information or duration . in one embodiment of the invention , a circuit implementation of a kalman filter ( see kalman , “ a new approach to linear filtering and prediction problems ,” transactions of the asme - journal of basic engineering , 1960 p35 ) is used to generate the function that best fits the motor velocity from observational signal 113 . in said embodiment , the threshold function is determined according to the variance equations of the kalman filter . control circuit 107 is shown in detail in fig2 . the memory 106 stores the sequential commands of the current program , and it can be written to by the training circuit 104 . in one embodiment , the memory 106 can also be directly programmed electronically from outside the motor controller 100 . the nature of memory 106 may be non - volatile , such as flash memory , or random - access , such as dram or sram memories , or of another form . each command in memory comprises a representation of the motor state variable function that control circuit 107 will drive motor 101 to reproduce , expected external state information to be compared against the external state information in observational signal 113 , and a duration of execution for the command . in the preferred embodiment , the motor state variable is velocity , and the representation of the velocity function is a digital signal of a multitude of bits indicating the magnitude of a predetermined unit velocity function . the motor state variable function with magnitude according to the executing command is an input to the feedback controller 109 , which also accepts the motor state variable in observational signal 113 as an input . in one embodiment , feedback controller 109 is a proportional - integral - derivative ( often called pid ) controller . the output of feedback controller 109 is a digital signal comprising a multitude of bits representing the amount of current to drive motor 101 , independently of variations in power supply and motor loading . in the preferred embodiment , pulse width modulator 110 converts said output into a pulse train with duty cycle proportional to the digital value of the output signal . the pulse train is the output of control circuit 107 and the input to drive circuit 112 . control circuit 107 further comprises command selection logic 111 to compare information from observational signal 113 comprising either angular position or time , and external state information , against duration and external state information stored in the current command in memory 106 . the external state information from observational circuit 102 and from memory 106 are input into a predetermined conditional logic function that indicates whether the current command should be executed . in one embodiment , this function is logical xor to indicate any difference in the information . the command selection logic 111 advances the memory 106 to the next command according to the output of said function and according to whether the duration of the command has been exceeded , as determined by a comparator circuit . drive circuit 112 amplifies the power of the output waveform of control circuit 107 for delivery to the motor 101 . drive circuit 112 comprises one power amplifier for each pin of motor 101 and directional logic . according to the direction of rotation specified in the motor state variable of the current command , the directional logic determines which power amplifier is connected to the output waveform of control circuit 107 . the input of the other power amplifier is connected to ground . there are many known ways of amplifying power . in the preferred embodiment , a break - before - make inverter design and a buffer chain are used . drive circuit 112 may further comprise devices for electrical protection of the integrated transistors , such as electrostatic discharge capacitors , zener diodes , and diffusion moats for substrate isolation . although this invention has been described with reference to specific embodiments , the invention is not limited to the particular embodiments disclosed here . variations and uses not explicitly disclosed here will be apparent to persons skilled in the art , and this invention should be given the broadest possible interpretation .