Pages: [1]   Go Down
Author Topic: Motor Twitching - Using Motor Shield  (Read 2014 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 1
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I currently have four motors connected up to a motor shield.  When I load a demo sketch (below), the motors just twitch and move randomly.  I currently have a .1uF capacitor across each of the motor leads, and my power source is 5xAA (7.5V) with fresh batteries.  As far as I know, my Motor Shield is soldered correctly and carefully, but I will double check that once more.  One side of the motors occasionally moves at the pace that I am looking for, but other than that, they move fairly randomly.  I have the 4WD Robot Chassis, as built here: http://www.rugcommunity.org/page/dfrobot-4wd-arduino-mobile

The motors have the following specs:
Quote
Gear Ratio 1:120
* No-load speed(3V):100RPM
* No-load speed(6V):200RPM
* No-load current(3V):60mA
* No-load current(6V):71mA
* Stall current(3V):260mA
* Stall current(6V):470mA
* Torgue (3V): 1.2Kgcm
* Torque (6V): 1.92Kgcm
* Size: 55mm x 48.3mm x 23mm
* Weight:45g
and the demo sketch that I am using is as follows:
Code:
    #include <AFMotor.h>

    AF_DCMotor motor2(2, MOTOR12_64KHZ); // create motor #2, 64KHz pwm
    AF_DCMotor motor1(1, MOTOR12_64KHZ);
    AF_DCMotor motor3(3, MOTOR12_1KHZ);
    AF_DCMotor motor4(4, MOTOR12_1KHZ);

    void setup() {
      Serial.begin(9600);           // set up Serial library at 9600 bps
      Serial.println("Motor test!");
     
      motor1.setSpeed(200);     // set the speed to 200/255
      motor2.setSpeed(200);
      motor3.setSpeed(200);
      motor4.setSpeed(200);
    }

    void loop() {
      Serial.print("tick");
     
      motor1.run(FORWARD);      // turn it on going forward
      motor2.run(FORWARD);
      motor3.run(FORWARD);
      motor4.run(FORWARD);
      delay(1000);

      Serial.print("tock");
      motor1.run(BACKWARD);     // the other way
      motor2.run(BACKWARD);
      motor3.run(BACKWARD);
      motor4.run(BACKWARD);
      delay(1000);
     
      Serial.print("tack");
      motor1.run(RELEASE);
      motor2.run(RELEASE);
      motor3.run(RELEASE);
      motor4.run(RELEASE);      // stopped
      delay(1000);
    }

Any suggestions?  Thanks for your help.
Logged

Boston
Offline Offline
God Member
*****
Karma: 3
Posts: 575
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I would first try adding more time in between each action as one second is not enough. I would make that at least delay(7000); or higher.  I have built the 2 wheeled and 4 wheeled version of that platform.  http://www.robotliving.com/building-robots/two-wheeled-robot-2/

I am using Adafruit's motor shield. What motor shield are you using?
« Last Edit: February 08, 2011, 01:42:39 pm by Pauly » Logged

Offline Offline
Newbie
*
Karma: 1
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am using Adafruit's Motor Shield as well.  I wonder if my motor wires are not inserted into the correct terminals.  I have each motor to the outer two terminals.  So M1 has two wires going into it.  Then I skip where it says GND, and then I connect the next two.  I do the same for the other side.

I changed the delay to be 8000, and just my M3 and M4 were really going.  There was less twitching (because the delay was greater), but still not moving according to the sketch.  The sketch should have the motors run forward, pause, run backward, pause, release, and then restart the loop over again, correct? 

As I look at the Serial Monitor, it shows the correct "tick", "tock", and "tack" for the respective FORWARD, BACKWARD, and RELEASE.  I hear it make a ticking noise when it is trying to move, but other than that I get nothing.  Could I have made an error in the build of the Motor Shield?  Did you solder any capacitor to your motors? Is it the # of KHz that I set to each motor?  I read that M3 and M4 can only get 1KHz.

Thanks for your help, Pauly.
« Last Edit: February 08, 2011, 02:43:02 pm by Brennn10 » Logged

Rahway, NJ
Offline Offline
Newbie
*
Karma: 0
Posts: 38
Timmy!!!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I don't have a motor shield, but I believe you need to remove the frequency section if you are using dc motors.

AF_DCMotor motor4(4, MOTOR12_1KHZ);

Switched to...

AF_DCMotor motor4(4);
Logged

Offline Offline
Newbie
*
Karma: 1
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

From Adafruit's wiki on DC Motors and the Motor Shield:
Create the AF_DCMotor object with AF_DCMotor(motor#, frequency), to setup the motor H-bridge and latches. The constructor takes two arguments.
The first is which port the motor is connected to, 1, 2, 3 or 4.
frequency is how fast the speed controlling signal is.
Logged

Rahway, NJ
Offline Offline
Newbie
*
Karma: 0
Posts: 38
Timmy!!!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It still should work according to the examples.

If you are forced to enter a parameter then use...
AF_DCMotor motor4(4, MOTOR34_8KHZ);
The prototype is defaulting to that parameter...

You are using DC motors, right?
Logged

Boston
Offline Offline
God Member
*****
Karma: 3
Posts: 575
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Try adding RELEASE in between forward and backward if you want a delay there as well.
Code:
Serial.print("tack");
      motor1.run(RELEASE);
      motor2.run(RELEASE);
      motor3.run(RELEASE);
      motor4.run(RELEASE);      // stopped
      delay(1000);

Also, check that your batteries are fully charged.  Mine need frequent recharging.  Weak batteries can lead to erratic behavior.
Logged

Offline Offline
Newbie
*
Karma: 1
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok, I will do that.  And in regards to my code:

Code:
AF_DCMotor motor2(2, MOTOR12_64KHZ); // create motor #2, 64KHz pwm
    AF_DCMotor motor1(1, MOTOR12_64KHZ);
    AF_DCMotor motor3(3, MOTOR12_1KHZ);
    AF_DCMotor motor4(4, MOTOR12_1KHZ);

Do I need to change anything with the "Motor12" and make it like "Motor34" or something like that?  Because I have them all at Motor12.

( Batteries are brand new, inserted yesterday)
« Last Edit: February 08, 2011, 03:34:18 pm by Brennn10 » Logged

Boston
Offline Offline
God Member
*****
Karma: 3
Posts: 575
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Do I need to change anything with the "Motor12" and make it like "Motor34" or something like that?  Because I have them all at Motor12.

No, I don't think that makes any difference.
Logged

Offline Offline
Newbie
*
Karma: 1
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I think my Arduino is shorting with the Metal surface of the chassis that it is sitting on. When I hold the Arduino, the motors work perfectly.  I will comment here if I run into any more problems.

EDIT:  This is weird.  I placed a non-conductive surface underneath the Arduino board.  But even when that is there, it still twitches.  But when I pick it up, it runs flawlessly.  Any ideas?  Possibly when the wires are more compressed (when it is sitting on the chassis) some wires are touching inside, but when I pick it up, they untouch?
« Last Edit: February 08, 2011, 04:02:27 pm by Brennn10 » Logged

The Udaho Border
Offline Offline
Newbie
*
Karma: 2
Posts: 18
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

EMI through the chassis?
Logged

Offline Offline
Newbie
*
Karma: 1
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

EMI through the chassis?

How would I be able to determine that this exists, or if I can get rid of it?  I do have another attachment to the chassis, which adds another level to the robot.  Should I add this?
Logged

Boston
Offline Offline
God Member
*****
Karma: 3
Posts: 575
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sounds to me like a loose wire or something not soldered together enough.
Logged

The Udaho Border
Offline Offline
Newbie
*
Karma: 2
Posts: 18
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

How would I be able to determine that this exists, or if I can get rid of it?

By trial and error and looking for spurious resets, unconnected inputs, ground loops, etc.

I would start with ground loops and move on to capacitive coupling causing one of the chips to reset.

Are your chassis and circuit grounds connected? are they connected in a star topology (good) or connected in series (grounds at different potentials) or in more than one place (classic ground loop)? How about RFI? is there an ungrounded portion of the chassis broadcasting the rise and fall times of power FETs like an antenna? Is your ground plane capacitively coupled to that antenna?

OTOH, I am no EMI/RFI wizard.
Logged

St. Charles, MO, USA
Offline Offline
Newbie
*
Karma: 0
Posts: 46
It Blinks Finally
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Fell free to build off my code if you want. Its what i used for my mecanum robot. http://arduino.cc/forum/index.php/topic,17451.msg127229.html#msg127229

Code:
#include <AFMotor.h>  // imported AFMotor library

    AF_DCMotor motor1(1);   
    AF_DCMotor motor2(2);   
    AF_DCMotor motor3(3);   
    AF_DCMotor motor4(4);       
   
    void setup() {
     
    }   

    void loop() {
      int speed = analogRead(2);
      speed = map(speed, 0, 1023, -255, 255);
  if (speed < 0)
    {
      motor2.run(FORWARD);
      motor2.setSpeed(abs(speed));   
      motor3.run(FORWARD);
      motor3.setSpeed(abs(speed)); 
    }
  if (speed > 0)
    {
      motor2.run(BACKWARD);
      motor2.setSpeed(speed);
      motor3.run(BACKWARD);
      motor3.setSpeed(speed);
    }
    int speed2 = analogRead(3);
      speed2 = map(speed2,  0, 1023, -255, 255);
  if (speed2 < 0)
    {
      motor1.run(FORWARD);
      motor1.setSpeed(abs(speed2));
      motor4.run(FORWARD);
      motor4.setSpeed(abs(speed2));   
    }
  if (speed2 > 0)
    {
      motor1.run(BACKWARD);
      motor1.setSpeed(speed2);
      motor4.run(BACKWARD);
      motor4.setSpeed(speed2);
    }
   
  }

Logged

Pages: [1]   Go Up
Jump to: