#NEWLINE# def update( self , v_d , v_m , dt ) : #NEWLINE# #INDENT# ' Calculate the plant signal based on variables (desired vs measured) for given update time (dt). ' #NEWLINE# if ( v_d != self . last_var_desired ) : #NEWLINE# #INDENT# self . reset ( ) #NEWLINE# self . last_var_desired = v_d #NEWLINE# #UNINDENT# error = ( v_d - v_m ) #NEWLINE# p = ( self . gain_p * error ) #NEWLINE# self . integrated_error += ( error * dt ) #NEWLINE# i = ( self . gain_i * self . integrated_error ) #NEWLINE# d_error = ( ( error - self . last_error ) / dt ) #NEWLINE# d = ( self . gain_d * d_error ) #NEWLINE# self . last_error = error #NEWLINE# response = ( ( p + i ) + d ) #NEWLINE# if self . dead_zone : #NEWLINE# #INDENT# dz = self . dead_zone #NEWLINE# if ( abs ( response ) < dz ) : #NEWLINE# #INDENT# return 0.0 #NEWLINE# #UNINDENT# #UNINDENT# if self . max_response : #NEWLINE# #INDENT# max_r = self . max_response #NEWLINE# if ( abs ( response ) > max_r ) : #NEWLINE# #INDENT# return math . copysign ( max_r , response ) #NEWLINE# #UNINDENT# #UNINDENT# return response