I have built an arduino uno based car which utilizes mecanum (omnidirection) wheels controlled via a L293D motor driver. I can get the car to move in all directions except directly LEFT or RIGHT. When I select LEFT or Right, only motor 1 and 2 are driven. Motors 3 and 4 do nothing. I can go Forward, backward, diagonal left and right both backward and forward and spin left or right with all four wheels turning simultaneously. However, only motors 1 and 2 will turned as designed WHEN i TRY TO GO left OR right. I can get either motor 3 or 4 to work with them but not all four. Whenever I add code to turn on the 4th motor neither motors 3 nor 4 will work. Weird since all four wheels work properly when going forward or backward.
You have skipped the instructions on how to post an effective question. The current post does not have enough detail about your system, to offer meaningful feedback or useful help.
Thanks for the feedback. It works fine driving all four motors going backward and forward. I tried to upload my code but system will not let me as I am a new user.
Below is my code. Car works great in all directions except LEFT and RIGHT. I can get 3 motors to turn if I comment out either motor 3 or motor 4 control. Strangely enough, As you can see via my comments, the SW command for controlling motor 3 actually controls motor 4, and visa versa. But only for a few for the directions. Really weird.
//Viral Science www.viralsciencecreativity.com www.youtube.com/c/viralscience
//Arduino Bluetooth App Control Mecanum Wheel Robot
#include <AFMotor.h> //Download and Install AFMotor.h Library
AF_DCMotor motor1(1); //Front Left Wheel
AF_DCMotor motor2(2); //Back Left Wheel
AF_DCMotor motor3(3); //Back Right Wheel
AF_DCMotor motor4(4); //Front Right Wheel
String readString;
void setup() {
Serial.begin(9600);
motor1.setSpeed(255); //Set Motor Speed - 250 max
motor2.setSpeed(255);
motor3.setSpeed(255);
motor4.setSpeed(255);
}
void loop() {
while(Serial.available()){
delay(50);
char c=Serial.read();
readString+=c;
}
if(readString.length()>0){
Serial.println(readString);
if (readString =="FORWARD"){ // MOVE FORWARD
motor1.run (FORWARD);
motor2.run (FORWARD);
motor3.run (FORWARD);
motor4.run (FORWARD);
}
if (readString =="BACKWARD"){ // MOVE BACKWARD
motor1.run (BACKWARD);
motor2.run (BACKWARD);
motor3.run (BACKWARD);
motor4.run (BACKWARD);
}
if (readString =="LEFT"){ // MOVE LEFT SIDE
motor1.run (FORWARD);
motor2.run (BACKWARD);
motor4.run (FORWARD); //Actually controls motor 3
motor3.run (BACKWARD);
}
if (readString =="RIGHT"){ // MOVE RIGHT SIDE
motor1.run (BACKWARD);
motor2.run (FORWARD);
motor3.run (BACKWARD);
motor4.run (FORWARD);
}
if (readString =="FORWARDLEFT"){ // MOVE FORWARD LEFT
motor1.run (RELEASE);
motor2.run (FORWARD);
motor3.run (FORWARD); // actually controls wheel 4
motor4.run (RELEASE); // actually controlls wheel 3
}
if (readString =="FORWARDRIGHT"){ // MOVE FORWARD RIGHT
motor1.run (FORWARD);
motor2.run (RELEASE);
motor3.run (RELEASE); // actually controls wheel 4
motor4.run (FORWARD); // actually controls wheel 3
}
if (readString =="BACKWARDLEFT"){ // MOVE BACKWARD LEFT
motor1.run (BACKWARD);
motor2.run (RELEASE);
motor3.run (BACKWARD);
motor4.run (RELEASE);
}
if (readString =="BACKWARDRIGHT"){ // MOVE BACKWARD RIGHT
motor1.run (RELEASE);
motor2.run (BACKWARD);
motor3.run (RELEASE);
motor4.run (BACKWARD);
}
if (readString =="ROTATELEFT"){ // ROTATE LEFT SIDE
motor1.run (BACKWARD);
motor2.run (BACKWARD);
motor3.run (FORWARD);
motor4.run (FORWARD);
}
if (readString =="ROTATERIGHT"){ // ROTATE RIGHT SIDE
motor1.run (FORWARD);
motor2.run (FORWARD);
motor3.run (BACKWARD);
motor4.run (BACKWARD);
}
if (readString =="STOP"){ // STOP
motor1.run (RELEASE);
motor2.run (RELEASE);
motor3.run (RELEASE);
motor4.run (RELEASE);
}
readString="";
}
}
I cannot figure out the placement of the motors. Also how can you make all motors turn in the same direction for forward and backward move? I'd expect that the left and right motors have to turn in opposite (cw/ccw) direction.
Motor 1 is left front. Motor 2 is left rear. Motor 2 is right rear. Motor 4 is right front.
Motors(wheels) turning in opposite directions is a capability of the mecanum wheels. It allows the car to travel in 9 different directions depending on the rotation of the wheels. The weird thing here is that all four wheels turn simultaneously going forward or backwards and turn in the correct rotation for all directions except for direct LEFT or direct RIGHT. If you look at Youtube videos on mecanum wheel car it's pretty cool.
Two things really perplex me. Only wheels 1 and 2 (instead of all four) turn when selecting LEFT or RIGHT. I can get 3 wheels to turn if I comment out the Motor3 or Motor 4 line. Secondly, on some commands, the motor4.run command actually moves Motor 3 and visa versa. Makes absolutely no sense. I have verified the commands are correct coming from my phone app and, as mentioned, control is weird on a couple commands as indicated in my comments.
I was wondering if there is a bug in the library.
Thanks for your interest in helping me resolve this.
If motor3.run() sometimes seems to control motor 4 then your wiring is bad. There may be shorts somewhere that cause weird behavior and even can have already damaged your drivers.
Sorry for the typo. Motor 2 is left rear. Motor 3 is right rear. Could be short somewhere in the motor shield somewhere. Wiring is pretty straightforward. Only + and - to each motor control on motor shield board. Really weird and very repeatable behavior. Maybe I'll try reloading from a different computer. Code is very straightforward - motor3.run command should always control motor 3 but that's not the case for those commands to which I have placed comments in code.