Do you have a battery plugged into the robot, or are you just using USB? Although you can power the microcontroller and electronics from USB, you will need to also use a battery to power the motors.
If you are already using a battery, and the power switch is on, then we would recommend trying the following code. It is the same as the OMNI example, but includes some Serial.println(…) statements that will allow you to use the Arduino Serial Monitor at 115,200 to check for the debug messages.
/* To control the Rover, copy and paste the code below into the Arduino
software. Ensure the motors are connected to the correct pins. The
code does not factor in encoders at this time*/
//Front motors
int E1 = 10 ; //M1 Speed Control
int E2 = 11; //M2 Speed Control
int M1 = 12; //M1 Direction Control
int M2 = 13; //M2 Direction Control
//Rear motors
int E3 = 6; //M1 Speed Control
int E4 = 5; //M2 Speed Control
int M3 = 8; //M1 Direction Control
int M4 = 7; //M2 Direction Control
void setup(void)
{
int i;
for(i=3;i<=13;i++)
pinMode(i, OUTPUT);
Serial.begin(115200);
}
void loop(void)
{
while (Serial.available() < 1) {} // Wait until a character is received
char val = Serial.read();
int leftspeed = 255; //255 is maximum speed
int rightspeed = 255;
switch(val) // Perform an action depending on the command
{
case 'w'://Move Forward
case 'W':
forward (leftspeed,rightspeed);
break;
case 's'://Move Backwards
case 'S':
reverse (leftspeed,rightspeed);
break;
case 'a'://Turn Left
case 'A':
left (leftspeed,rightspeed);
break;
case 'd'://Turn Right
case 'D':
right (leftspeed,rightspeed);
break;
case 'q'://rotate ccw
case 'Q':
ccw (leftspeed,rightspeed);
break;
case 'e'://rotate cw
case 'E':
cw (leftspeed,rightspeed);
break;
case 'z'://move at 45 degrees
case 'Z':
fortyfive (leftspeed,rightspeed);
break;
case 'x'://move at 135 degrees
case 'X':
onethirtyfive (leftspeed,rightspeed);
break;
// to move at 225 and 315, use the 45 degree and 135 degree
// code but reverse motor direction.
default:
stop();
break;
}
}
void stop(void) //Stop
{
digitalWrite(E1,LOW);
digitalWrite(E2,LOW);
digitalWrite(E3,LOW);
digitalWrite(E4,LOW);
Serial.println("Stop");
}
void forward(char a,char b)
{
analogWrite (E1,a);
digitalWrite(M1,LOW);
analogWrite (E2,b);
digitalWrite(M2,HIGH);
analogWrite (E3,a);
digitalWrite(M3,LOW);
analogWrite (E4,b);
digitalWrite(M4,HIGH);
Serial.println("Move Forward");
}
void reverse (char a,char b)
{
analogWrite (E1,a);
digitalWrite(M1,HIGH);
analogWrite (E2,b);
digitalWrite(M2,LOW);
analogWrite (E3,a);
digitalWrite(M3,HIGH);
analogWrite (E4,b);
digitalWrite(M4,LOW);
Serial.println("Move Reverse");
}
void ccw (char a,char b)
{
analogWrite (E1,a);
digitalWrite(M1,HIGH);
analogWrite (E2,b);
digitalWrite(M2,HIGH);
analogWrite (E3,a);
digitalWrite(M3,HIGH);
analogWrite (E4,b);
digitalWrite(M4,LOW);
Serial.println("Rotate CCW");
}
void cw (char a,char b)
{
analogWrite (E1,a);
digitalWrite(M1,LOW);
analogWrite (E2,b);
digitalWrite(M2,LOW);
analogWrite (E3,a);
digitalWrite(M3,LOW);
analogWrite (E4,b);
digitalWrite(M4,HIGH);
Serial.println("Rotate CW");
}
void left (char a,char b)
{
analogWrite (E1,a);
digitalWrite(M1,HIGH);
analogWrite (E2,b);
digitalWrite(M2,HIGH);
analogWrite (E3,a);
digitalWrite(M3,LOW);
analogWrite (E4,b);
digitalWrite(M4,LOW);
Serial.println("Move Left");
}
void right (char a,char b)
{
analogWrite (E1,a);
digitalWrite(M1,LOW);
analogWrite (E2,b);
digitalWrite(M2,LOW);
analogWrite (E3,a);
digitalWrite(M3,HIGH);
analogWrite (E4,b);
digitalWrite(M4,HIGH);
Serial.println("Move Right");
}
void fortyfive (char a,char b)
{
analogWrite (E1,a);
digitalWrite(M1,LOW);
analogWrite (E3,a);
digitalWrite(M3,LOW);
Serial.println("Move at 45 degrees");
}
void onethirtyfive (char a,char b)
{
analogWrite (E2,b);
digitalWrite(M2,HIGH);
analogWrite (E4,b);
digitalWrite(M4,HIGH);
Serial.println("Move at 135 degrees");
}