Go Down

Topic: How to control a 4wd robot to move by arduino? (Read 9 times) previous topic - next topic

Pauly

To get started all you really need are four things.
1. An Arduino
2. The robot body/kit
3. Motor controller (I used one from Adafruit)
4. Batteries

Check out how I built the 2 wheeled robot.  It is almost the same for building the for wheeled robot.  http://www.robotliving.com/building-robots/two-wheeled-robot-2/

zoomkat

Below is a link to a kit 4wd robot assembly instructions. You should be able to learn a lot by studying their assembly instructions.

http://www.lynxmotion.com/driver.aspx?Topic=assem05
Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   8)

yss31610165

Hi everyone,
Thank you all for your kindly replies. Yesterday I finally get my first step, use the code involved here:http://www.dfrobot.com/wiki/index.php?title=DFRduino_RoMeo and finally the motor moves,(although only one moves, I'm still learning and fixing it).
The code involved in that link is as follows:
Code: [Select]
Sample Code?

int E1 = 5;     //M1 Speed Control
int E2 = 6;     //M2 Speed Control
int M1 = 4;    //M1 Direction Control
int M2 = 7;    //M1 Direction Control

///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;    //M1 Direction Control


void stop(void)                    //Stop
        {
          digitalWrite(E1,LOW);   
          digitalWrite(E2,LOW);     
        }   
void advance(char a,char b)          //Move forward
        {
          analogWrite (E1,a);      //PWM Speed Control
          digitalWrite(M1,HIGH);   
          analogWrite (E2,b);   
          digitalWrite(M2,HIGH);
        } 
void back_off (char a,char b)          //Move backward
        {
          analogWrite (E1,a);
          digitalWrite(M1,LOW);   
          analogWrite (E2,b);   
          digitalWrite(M2,LOW);
}
void turn_L (char a,char b)             //Turn Left
        {
          analogWrite (E1,a);
          digitalWrite(M1,LOW);   
          analogWrite (E2,b);   
          digitalWrite(M2,HIGH);
        }
void turn_R (char a,char b)             //Turn Right
        {
          analogWrite (E1,a);
          digitalWrite(M1,HIGH);   
          analogWrite (E2,b);   
          digitalWrite(M2,LOW);
        }
void setup(void)
{
    int i;
    for(i=6;i<=9;i++)
    pinMode(i, OUTPUT); 
    Serial.begin(19200);      //Set Baud Rate
}
void loop(void)
{
     char val = Serial.read();
     if(val!=-1)
       {
          switch(val)
           {
             case 'w'://Move Forward
                     advance (100,100);   //PWM Speed Control
                     break;
             case 's'://Move Backward
                     back_off (100,100);
                     break;
             case 'a'://Turn Left
                     turn_L (100,100);
                     break;       
             case 'd'://Turn Right
                     turn_R (100,100);
                     break;         
            }     
          delay(40);
       }
      else stop(); 
}


What I used are a Duemilanove Arduino, a Romeo, a 4wd robot and of course batteries. But the problem is :
1.The code above controls only two motors, when I control four motors, where should I change?

2.As you can see, there are many switch-case in the loop method, but I never used that before,what does that mean?
For example, can I enter the word "w" to control the robot move forward? Where to enter? How can I write a java interface or web interface to control?

Thank you again for everyone's help, in this place I really learned a lot. :*

jraskell

Quote
1.The code above controls only two motors, when I control four motors, where should I change?


When dealing with fixed orientation motors/wheels, controlling four motors is the same as controlling two motors, because you should be controlling the motors in pairs.  There's no reason for the two motors on the left side to be driven separately (same for the right side).  Ideally, just wire the two left motors in parallel to the motor controller (making sure the motor controller can handle the current of two motors), and then wire the two right motors in parallel to the motor controller.

Pauly

I would just double up your motor code.
Here are some examples from my code. I used the Adafruit motor shield.
RF = Right Front LF = Left Front, etc..

Code: [Select]
// defining motors

AF_DCMotor motorRF(1, MOTOR12_1KHZ);
AF_DCMotor motorLF(2, MOTOR12_1KHZ);
AF_DCMotor motorRR(3, MOTOR12_1KHZ);
AF_DCMotor motorLR(4, MOTOR12_1KHZ);


Code: [Select]
//Going forward
  motorRF.run(FORWARD);
  motorLF.run(FORWARD);
  motorRR.run(FORWARD);
  motorLR.run(FORWARD);

Go Up