Could be low on Freon or have a bad low pressure cut-out switch, maybe even a bad/clogged Expansion valve. The compressor probably is okay. If you don't understand any of this take it to a professional!
I believe the problem is a loose connection somewhere between the battery and air compressor. The wiring may be loose and disconnect whenever you hit a bump or something. If that isn't the problem, the air compressor could need a replacement from wear and age.