Motors out of sync after wait time.
In my previous post i neglected to provide a full example of my code. Sorry
I have a Arduino Duemilanove (ATmega328P with a Rugged dual 2A motor shield. My goal is to drive a robot forward for 10 seconds. Then wait for 2 hours before returning while in reverse to its starting point. Seems simple the motors start at the same time in forward. But everything I have tried to make them stop and wait 2 hours causes out of sync motors. Basically one re-starts before the other.
Due to the large size of the tracked robot 27" length 15" width and 48" height, I need to use two high power motors.
Right now the motors are not in sync after the first forward 10 seconds. One starts then one second later the other starts.
This causes the robot not to return to its starting place.
Sorry, I don't know how to includ the code in a code screen.
Here is one of my many code attempts:
/* Define which board you are using. Only uncomment one of the
following #define's. Or comment them all and let this file
guess the board based on the processor:
ATmega328P --> Duemilanove/Uno
ATmega324P --> Gator
ATmega1280 --> Mega (also ATmega2560)
/
//#define BOARD 0 / Arduino Duemilanove/Uno (ATmega328P) /
//#define BOARD 1 / Arduino Mega (ATmega1280) /
//#define BOARD 2 / Rugged Circuits Gator (ATmega324P) */
// In case no board is defined, guess from the processor
#ifndef BOARD
if defined(AVR_ATmega328P)
define BOARD 0
elif defined(AVR_ATmega1280) || defined(AVR_ATmega2560)
define BOARD 1
elif defined(AVR_ATmega324P)
define BOARD 2
else
error You must define BOARD near the top of this file
endif
#endif
#if (BOARD!=0) && (BOARD!=1) && (BOARD!=2)
#error Unknown board
#endif
// Enable (PWM) outputs
#define EN1_PIN 3
#define EN2_PIN 11
// Direction outputs
#define DIR1_PIN 12
#define DIR2_PIN 13
void setup()
{
// Configure all outputs on for now
pinMode(EN1_PIN, OUTPUT); digitalWrite(EN1_PIN, HIGH);
pinMode(EN2_PIN, OUTPUT); digitalWrite(EN2_PIN, HIGH);
pinMode(DIR1_PIN, OUTPUT); digitalWrite(DIR1_PIN, HIGH);
pinMode(DIR2_PIN, OUTPUT); digitalWrite(DIR2_PIN, HIGH);
}
void loop()
{
digitalWrite(DIR1_PIN, HIGH); // Set Motor 1 forward direction
analogWrite(EN1_PIN, 255); // Motor 1 on in forward direction
delay(10000);
digitalWrite(DIR2_PIN, LOW); // Set Motor 2 forward direction
analogWrite(EN2_PIN, 255); // Motor 2 on in forward direction
delay(10000);
analogWrite(EN1_PIN, 0); // Motor 1 off
delay(720000);
analogWrite(EN2_PIN, 0); // Motor 2 off
delay(720000);
digitalWrite(DIR1_PIN, HIGH); // Set Motor 1 reverse direction
analogWrite(EN1_PIN, 255); // Motor 1 on in reverse direction
delay(10000);
digitalWrite(DIR2_PIN, HIGH); // Set Motor 2 reverse direction
analogWrite(EN2_PIN, 255); // Motor 2 on in reverse direction
delay(10000);
analogWrite(EN1_PIN, 0); // Motor 1 off
delay(720000);
analogWrite(EN2_PIN, 0); // Motor 2 off
delay(720000);
}