Hi,
I encounter some problem when trying to get my 3 wheel drive omni robot working. All seems to be fine until I am trying to make the robot to turn on the spot. Motor 1 and 2 are connected directly to the controller board and motor 3 to the motor shield.
When I key in input P, motor 3 is able to turn counter clockwise independently. But when I change the command to input S, motor 3 doesn't seems to change it's direction and keep on turning counter clockwise. It can be seen that when this happen, motor 3 is not turning as smooth as before and it is jerking.
My motor shield expansion comes with a pre allocated pin for PWM and DIR for pin 6 and 7 respectively. I have already cut the pin off and connect it to pin 10 and 11 instead.
What can be the problem?
//Standard PWM DC control
int E1 = 5; //M1 Speed Control
int E2 = 6; //M2 Speed Control
int E3 = 10;
int M1 = 4; //M1 Direction Control
int M2 = 7; //M2 Direction Control
int M3 = 11;
///For previous Romeo, please use these pins.
//int E1 = 6; //M1 Speed Control
//int E2 = 9; //M2 Speed Control
//int M1 = 7; //M1 Direction Control
//int M2 = 8; //M2 Direction Control
void setup(void)
{
int i;
//pinMode(i, OUTPUT);
Serial.begin(9600); //Set Baud Rate
while (!Serial)
{
// do nothing
} ;
Serial.println("Run keyboard control");
}
void stop() //Stop
{
digitalWrite(E1,LOW);
digitalWrite(E2,LOW);
digitalWrite(E3,LOW);
}
void advance(char a,char b,char c) //Move forward
{
analogWrite (E1,a); //PWM Speed Control
digitalWrite(M1,LOW);
analogWrite (E2,b);
digitalWrite(M2,LOW);
analogWrite (E3,c);
digitalWrite(M3,LOW);
}
void back_off (char a,char b,char c) //Move backward
{
analogWrite (E1,a);
digitalWrite(M1,HIGH);
analogWrite (E2,b);
digitalWrite(M2,HIGH);
analogWrite (E3,c);
digitalWrite(M3,HIGH);
}
void turn_L (char a,char b,char c) //Turn Left
{
analogWrite (E1,a);
digitalWrite(M1,LOW);
analogWrite (E2,b);
digitalWrite(M2,HIGH);
analogWrite (E3,c);
digitalWrite(M3,HIGH);
}
void turn_R (char a,char b,char c) //Turn Right
{
analogWrite (E1,a);
digitalWrite(M1,HIGH);
analogWrite (E2,b);
digitalWrite(M2,LOW);
analogWrite (E3,c);
digitalWrite(M3,LOW);
}
void test (char a) //Turn Right
{
analogWrite (E3,a);
digitalWrite(M3,LOW);
}
void loop()
{
if(Serial.available() > 0){
char val = Serial.read();
switch(val)
{
case 'p'://Move Forward
test (255); //move forward in max speed
break;
case 'w'://Move Forward
advance (50,50,0); //move forward in max speed
break;
case 's'://Move Backward
back_off (50,50,0); //move back in max speed
break;
case 'a'://Turn Left
turn_L (100,100,100);
break;
case 'd'://Turn Right
turn_R (50,50,50);
break;
case 'z':
Serial.println("Hello");
break;
case 'x':
stop();
break;
}
}
}
Nexus_Trail.ino (2.34 KB)
