Electric Vehicle Pt 2.

Thanks for everyone who helped and gave suggestions. I'm happy to say that our vehicle works now. Although our new problem is that it tends to curve to the left now. We gave the same amount of speed for each motor so we're not entirely sure why it's doing that. If anyone has any suggestions or advice feel free to help. Thank ya. :slight_smile:
Sincerely,
Less desperate high school student

#include <AFMotor.h>

#include <AFMotor.h>

AF_DCMotor motor(2, MOTOR12_64KHZ); // create motor #2, 64KHz pwmAF_DCMotor motor(3, MOTOR12_64KHZ); // create motor #2, 64KHz pwm
AF_DCMotor Amotor(3, MOTOR12_64KHZ); // create motor #2, 64KHz pwmAF_DCMotor motor(3, MOTOR12_64KHZ); // create motor #2, 64KHz pwm
AF_DCMotor Bmotor(4,MOTOR12_64KHZ);
AF_DCMotor Cmotor(1,MOTOR12_64KHZ);

void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps
Serial.println("Motor test!");

motor.setSpeed(255);// set the speed to 200/255
Amotor.setSpeed(255);
Bmotor.setSpeed(255);
Cmotor.setSpeed(255);
}

void loop() {
Serial.print("tick");

motor.run(FORWARD); // turn it on going forward

Amotor.run(BACKWARD);

Bmotor.run(FORWARD);

Cmotor.run(FORWARD);
delay (23000);\

Serial.print("tack");
motor.run(RELEASE); // stopped

Amotor.run(RELEASE);

Bmotor.run(RELEASE);

Cmotor.run(RELEASE);
delay (100000);
}

We gave the same amount of speed for each motor so we're not entirely sure why it's doing that.

You seem to think that two similar motors, of whatever type you are using, will operate exactly the same way. Welcome to the real world.

Since you have 4 instances of the AF_DCMotor class, are you sure that you don't need to include AFMotor.h a couple more times?

SwitchSama:
#include <AFMotor.h>

#include <AFMotor.h>

motor.run(FORWARD); // turn it on going forward

Amotor.run(BACKWARD);

Bmotor.run(FORWARD);

Cmotor.run(FORWARD);
delay (23000);

Just picking two things up.

  1. You only need to include the motor library once.

  2. Why is one motor running backwards? That will surely affect the speed of one side of your robot and cause it to turn to one side.

Hi,
One motor is running backwards I would say because both motors and gearboxes are identical, and have right angle drive output.
So one motor has to be positioned in the opposite orientation to the other so drive comes out each side of chassis, hence one has to run backwards, while the other forwards to make the chassis move in the one direction.
As in this pic.
magician-build-9-500x500.jpg
I personally, switch the polarity of one motor connections, so I have forward and forward.
Tom.. :slight_smile: