Manual
Sketch #4: Omni Wheel Rover – Basic Directions
/* 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
forward (leftspeed,rightspeed);
break;
case 's'://Move Backwards
reverse (leftspeed,rightspeed);
break;
case 'a'://Turn Left
left (leftspeed,rightspeed);
break;
case 'd'://Turn Right
right (leftspeed,rightspeed);
break;
case 'q'://rotate ccw
ccw (leftspeed,rightspeed);
break;
case 'e'://rotate cw
cw (leftspeed,rightspeed);
break;
case 'z'://move at 45 degrees
fortyfive (leftspeed,rightspeed);
break;
case 'x'://move at 135 degrees
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);
}
void forward(char a,char b)
{
analogWrite (E1,a);
digitalWrite(M1,LOW);
analogWrite (E2,b);