Servo + Dc motors = ARRGH

I am using the arduino rover chassis kit from RobotShop (only the frame and motors and treads, no extra stuff).
I am driving the dc motors with an H bridge and a 6 volt power supply. Also, I have an ultrsonic sensor mounted on a small servo, a Hitec HS-55. I have the servo moving between 3 different positions while the motors are running. But when I apply any torque to the wheels, the servo goes wacky.

Here's the code:

#include <Servo.h>

int en1 = 5;
int en2 = 9;
int s1log1 = 3;
int s1log2 = 4;
int s2log1 = 7;
int s2log2 = 8;
int piezo = 6;
int sonar = 1;

int reading1;
int reading2;
int reading3;


void gofwd()  {
  digitalWrite(s1log2, LOW);
  digitalWrite(s1log1,HIGH);
  digitalWrite(s2log2, LOW);
  digitalWrite(s2log1,HIGH);
  digitalWrite(en1, HIGH);
  digitalWrite(en2, HIGH);
}

void stop()  {
  digitalWrite(en1, LOW);
  digitalWrite(en2, LOW);
}

void turnleft(int ratio)  {
  digitalWrite(s1log2, LOW);
  digitalWrite(s1log1,HIGH);
  digitalWrite(s2log1, LOW);
  digitalWrite(s2log2,HIGH);
  digitalWrite(en2, HIGH);
  analogWrite(en1, ratio);
}

void turnright(int ratio)  {
  digitalWrite(s1log1, LOW);
  digitalWrite(s1log2,HIGH);
  digitalWrite(s2log2, LOW);
  digitalWrite(s2log1,HIGH);
  digitalWrite(en1, HIGH);
  digitalWrite(en2, ratio);
}

void goback()  {
  digitalWrite(s1log1, LOW);
  digitalWrite(s1log2,HIGH);
  digitalWrite(s2log1, LOW);
  digitalWrite(s2log2,HIGH);
  digitalWrite(en1, HIGH);
  analogWrite(en2, HIGH);
}


Servo neck;

void setup()  {
  pinMode(en1, OUTPUT);
  pinMode(en2, OUTPUT);
  pinMode(s1log1, OUTPUT);
  pinMode(s1log2, OUTPUT);
  pinMode(s2log1, OUTPUT);
  pinMode(s2log2, OUTPUT);
  pinMode(piezo, OUTPUT);
  neck.attach(10);
}

void loop()  {
  gofwd();
  neck.write(10);
  delay(1000);
  reading1 = analogRead(sonar);
  neck.write(100);
  delay(1000);
  reading2 = analogRead(sonar);
  neck.write(180);
  delay(1000);
  reading3 = analogRead(sonar);
}

I am using 0017 so I have the newer servo library.

But when I apply any torque to the wheels, the servo goes wacky.

That sounds like a decoupling problem - unlikely to be software.

What is "decoupling" and how do I solve it?

Decoupling is how you get the spikes and dips out of a supply, so they don't affect other parts of the circuit, by the judicious use and placement of capacitors.
"Suppression" is another useful search term.
I think Grumpy Mike has a tutorial - I'll see if I can find his link - if your lucky, he'll supply one.

This is odd:
It works well now. I put in some 0.1uf capacitors, and it didn't help. I took them out, and voila, it works. The servo only spazzes when the motors are close to completely stalling.

[edit] I took them out, and voila, it works[/edit]
It sounds like you had some poor connections.

That might have been the problem.

The servo only spazzes when

I don't know if you are aware of this but this is a politically incorrect thing to say and it could cause offense.

If you have not found it my link is:-
http://www.thebox.myzen.co.uk/Tutorial/De-coupling.html

Sorry, I wasn't aware of that. Sorry to anyone I might have offended.

it sounds like your problem could also be you are drawing more current than your battery can supply. When the motors stall they use a lot more current. Then your servo control board doesn't get enough power and your board spazzes out. the .1uF cap was probably bad or shorting out because it shouldn't have hurt anything.

If you plan on having the motors stalled a lot you would need a battery capable of delivering more current.

if the motors are just stalled temporarily and it messes with the servo a 470 uF capacitor can help for momentary current drops

don't worry about being too PC on global forums. Spazz is offensive in the UK but not the US kind of like fag is common there.
you can't please everyone and if you try you'll waste a lot of time.

FYI the motors are driven off of an h bridge connected to 4 AA batteries. The servo is powered off of arduino 5v. They both work fine separately, but they move erratically* when put together, hence, the topic title.

*There, I didn't use the apparently offensive term.