Another way to do this is:
Code:
motor_value = k*joystick_reading + (1-k)*motor_value
k is between 0 and 1.
Large k values make the motor very responsive, and a value of 1 means no filtering is actually happening. Small values make the output move slowly from the old value to the joystick value.
This is an
Infinite Impulse Response (IIR) low pass filter, whereas the moving average is a
Finite Impulse Response (FIR) filter. Which of these to choose (or using a rate limiter like Ether suggested) depends on what exactly you are trying to accomplish.
My experience with using any sort of filtering in the drive train (other than traction control in 2009) is that drivers usually hate it because if the effect is significant it feels "sluggish".