Tuesday, February 26, 2013

Robot Parts!

My DFRobot Turtle came in the mail yesterday, and I decided to document the build process. I only ran into a few hiccups along the way, so I would say it worked out rather well. Along with the robot, I also got the DFRobot motor controller to use with my Arduino Uno to control the robot. I opted for this motor controller over the ones made by Arduino simply due to cost and convenience.

ROBOT PARTS!

The documentation that came with the parts was rather sparse, it left a lot up to the user (at least with regards to the wiring). So my build is particular to how I planned on running the robot. Given the position of the DC motor mounts in the frame, I decided it would probably be easier to solder the motor wires prior to mounting them.

Motors mounted in frame
Soldered the motor wires

This is where the first hiccuped occurred. I soldered the motors wires identically. However, they are placed in the frame opposite of each other. This means that the positive rotation of each motor are opposite to each other (aka if I power them, it'll spin in circles). Luckily for me I fixed this issue without having to desolder by reversing the wire input when I connected to the motor shield. It was right around this point that Lilu decided she wanted to help.

Lilu is blissfully unaware that this robot will scare the shit out of her
With that done, the wheels, sensor mount, battery pack, and top could all be attached to the frame. 

There is a ball bearing beneath the battery pack for the third wheel
The top and switch attached
This is where the second hiccup happened. This one was less of a mistake and more of a point of confusion. After a bit of reading I had determined that when using a motor shield with these systems, it is better to provide separate power sources to the motor shield and Arduino. Okay, I could build a 9V adapter to power the Arduino. One more thing, in order for the electrons to be happy, the power sources have to be hooked up to the same ground. I had to think about this for a bit, but essentially this means I had to take the negatives of the 9V battery and AA battery pack (grounds relative to the batteries), and put them on the same line. I also had a switch which I wanted to use with the motor shield. Given all that, I came up with a circuit design, soldered a Frankensteinian four-ended cable, and wired it up.

Circuit for power to the Arduino and motor shield
I'm going to claim over and over that I am far from a good electrician.  
I had to make the 9V adapter at the end of the four-pronged cable. Remember to put all the caps and heatshrink on the wires prior to soldering everything, this issue plagued me a number of times...

Making the 9V adapter for the Arduino

I also had purchased a really nifty prototyping plate for the top of the robot which would allow for easier configuration of components (for my future plans).

Nifty right?
Once all the wires were hooked up to the right power I ended with something which seemed to look like a robot.

Robot! =D
Finally, to test it, I used the following Arduino sketch. There are four pins which control the motors, two for each motor. One pin controls the speed via a PWM signal, the other is a digital signal which tells the motor controller to reverse the signal (make it spin backwards). This code will gradually ramp up the speed of the motors, while rotating the wheels in opposite directions.

//LEFT WHEEL
int E1 = 10;  
int M1 = 12; 

//RIGHT WHEEL
int E2 = 11;                      
int M2 = 13;                        


void setup() {
    //Setup pins for output
    pinMode(M1, OUTPUT);   
    pinMode(M2, OUTPUT); 
} 
 
void loop() {

  //Track Value 
  int value;
  //Increase PWM value each step
  for(value = 0 ; value <= 255; value+=5){ 
    //Spin forward on left wheel, and backwards on right
    digitalWrite(M1, LOW);   
    digitalWrite(M2, HIGH);  
     
    //Write speed
    analogWrite(E1, value);   //PWM Speed Control
    analogWrite(E2, value);   //PWM Speed Control
    delay(30); 
  }  
}


I noticed that one motor seemed to spin a little faster than the other even with the same signal. I am not sure if this is an electrical or software issue, or if it will even affect my goals. Here is a video of the little guy spinning.


There should be more fun to come with this robot!

No comments:

Post a Comment