Why Capacitors used with D.C Motor?

Dc motor control is very easy.you can easily control any using L293D chip.But if you look at exact circuit of that motor driver you seen that some capacitors are used.but some times beginners doesn't know the purpose of that capacitors are used with motor driver.Here i'm going to explain what i learnt about dc motor driver from internet.

This must be the case of a DC motor otherwise the capacitor would act as a partial short circuit, (never plug a capacitor into an electrical outlet!).
The typical small DC motor consists of coils and brushes and permanent magnets. (Called a PM DC motor.) The current through the coils pushes therm from one magnet to the other and this turns the commutator which switches the current around to continue this process in a cycle. Since you are switching the coils on and off the current drain on the battery jumps up and down. When it is high it will waste energy heating the battery due to internal resistance.
The capacitor acts as a reservoir and buffer so that when the motor draws little current the cap recharges and when the motor needs high current the capacitor discharges through the motor.
Also are there any motors that would rotate in only one direction and resist the motion in the other direction(keeping the direction of the current same)?
Most PM DC motors are bidirectional i.e. reverse the current you reverse the motion.
You could add circuitry which will achieve what you desire. Put a diode in series with the motor and current will only flow in one direction. Also if you put another diode (high current rated) an low value resistor in parallel to the motor what will happen is that when it tries to reverse motion it will act as a generator putting a load on the resistor. This will not stop reverse motion but will dampen it. This is in theory. I have no practical experience as to how well this will work or what values to use. I've attached a rough circuit diagram to show you what I mean.
If the parallel diode has a high enough rating then you can dispense with the resistor all together. This is very similar to the circuit you would use to "debounce" a relay.

Capacitors are used with motors in two different ways. Sometimes the same motor will have both techniques applied, and be associated with two significantly different-looking capacitors.

When motors with brushes are running normally, the motor brushes produce sparks, which cause noise "from DC to daylight". This has nothing to do with PWM -- it happens even when these motors are connected directly across a battery, without any PWM. If we did nothing, the cable running from the electronics board (or directly from the battery) to the motor would act like an antenna, radiating TV and other radio interference. One way people fix that problem is to attach small ceramic capacitors directly to the motor to absorb much of that noise.

When using PWM to drive the motor, when the transistors turn "on", the motor may pull a current spike / surge current -- the above noise-filtering capacitors make that current spike worse. When the transistors turn "off", the motor inductance may cause voltage spikes from the motor inductance -- the above noise-filtering capacitors help a little. More complex filters attached directly to the motor can help these two problems.

When a motor -- even a motor that doesn't have brushes -- is first turned on at a dead stop, and also when the robot hits an obstruction and stalls the motor, the motor pulls much higher currents than it does in normal operation -- currents that may last for several seconds. This high current may pull down the battery power rail enough to reset all the digital electronics in the system (or perhaps reset just some of the digital electronics, causing half-brain syndrome).

One work-around has 2 parts:
add large electrolytic capacitors directly across the battery (or across the battery input to the PWM motor driver, or across the battery input to the digital electronics, or often capacitors in all three locations) -- these capacitors work better at supplying high currents for a few milliseconds than the battery does.
In the few milliseconds we have before the stalled motor pulls all the energy from those big capacitors and then pulls the power rails low enough to start resetting things, program the digital system to somehow recognize that the motor has stalled and kill the power to that motor. Then that motor no longer drags down the power rail, and the digital electronics and all the other motors continue to operate normally. ("soft-start", "current-limiting", "torque-limiting", etc. are more sophisticated forms of this idea). (Those big capacitors, also absorb some of the energy that comes out of the motor when the PWM turns "off", and later put that energy back into the motor when the PWM turns "on").

The above capacitors protect other things from the motor's electrical interference. I suppose one could argue that step (2) above prevents a stalled motor from eventually, after many seconds, overheating and failing -- but
that's not really its primary purpose.