Hello
I´m making a 4WD Robot Car with an Arduino Uno and Arduino Wifi.
I have an application with joystick to command my car. Did you know how can i make an interface to put the angle of a curve and send that information to arduino to put the correct velocity and direction on each wheel?
Thank you
I was not aware that a curve had an angle. But, high school geometry will give you all the information and you can compute velocity from that.
Transmit the outer wheel speed and the velocity quotient of the outer and inner wheels.
But i need to insert an angle and the robot needs to know what to do. I can't do what you say, cause for all the angles curves will be diferents
But you think that can't be associeted with an angle?
You will have to make a drawing of what you keep referring to an post it.
I see angles. I do not see an "curve".
Of course you can. The X axis of the joystick gives the direction and speed and the Y axis the left/right ratio.
Yes, but i can say that is a curve that is represented with an angle of 30 º ou 50º. Put an angle as input and obtained as output a trajectory for the car
"Looks like" is not really helpful. How do you get the joystick values, what do they mean?
The ONLY reason your car moves in a "curved" direction is the friction between the wheels and the surface. If you are referring to the angle difference between the axis of each of the 4 wheels, then connect the straight lines to an intersection point. Each wheel will traverse a different path on a circle. Compute the length of that path and from that you can compute the surface speed of the wheel. That will allow you to compute the rotation speed of each wheel.
All this means the wheel friction does not allow any slippage.
In practice some slippage is good, 4WD won't work well without it.
I'd only drive 2 wheels, for simplicity.
I don't understand your question
Only 2 wheels? How?
But I don't know the track the car will be on
4-wheel driving on dry pavement is not good.
Me 2, my crystal ball is in repair ![]()
You have to specify which values (voltage?) you get from your joystick. If you don't know that then nobody can suggest further processing of such unknown data. Then specify how the data relates to your intended angle.
Please do not try to re-invent the wheel from zero. Instead study at least one successful RC car project. That will answer many questions and strip down forum discussion to only meaningful content. Or start with a chassis kit with supplied Arduino code.
I already do that, but all the robots that i saw make a curve just with an arbritrary curves and not so specific as i need
And related with joystick it sends only the way of wheels and velocity (max is 255)
#define ENA_m1 2 // Enable/speed motor Front Right
#define ENB_m1 7 // Enable/speed motor Back Right
#define ENA_m2 8 // Enable/speed motor Front Left
#define ENB_m2 13 // Enable/speed motor Back Left
#define IN_11 5 // L298N #1 in 1 motor Front Right
#define IN_12 6 // L298N #1 in 2 motor Front Right
#define IN_13 3 // L298N #1 in 3 motor Back Right
#define IN_14 4 // L298N #1 in 4 motor Back Right
#define IN_21 11 // L298N #2 in 1 motor Front Left
#define IN_22 12 // L298N #2 in 2 motor Front Left
#define IN_23 9 // L298N #2 in 3 motor Back Left
#define IN_24 10 // L298N #2 in 4 motor Back Left
int command; //Int to store app command state.
int speedCar = 100; // 50 - 255.
int speed_Coeff = 4;
void setup() {
Serial.begin(9600);
pinMode(ENA_m1, OUTPUT);
pinMode(ENB_m1, OUTPUT);
pinMode(ENA_m2, OUTPUT);
pinMode(ENB_m2, OUTPUT);
pinMode(IN_11, OUTPUT);
pinMode(IN_12, OUTPUT);
pinMode(IN_13, OUTPUT);
pinMode(IN_14, OUTPUT);
pinMode(IN_21, OUTPUT);
pinMode(IN_22, OUTPUT);
pinMode(IN_23, OUTPUT);
pinMode(IN_24, OUTPUT);
}
void goAhead(){
digitalWrite(IN_11, HIGH);
digitalWrite(IN_12, LOW);
analogWrite(ENA_m1, speedCar);
digitalWrite(IN_13, LOW);
digitalWrite(IN_14, HIGH);
analogWrite(ENB_m1, speedCar);
digitalWrite(IN_21, LOW);
digitalWrite(IN_22, HIGH);
analogWrite(ENA_m2, speedCar);
digitalWrite(IN_23, HIGH);
digitalWrite(IN_24, LOW);
analogWrite(ENB_m2, speedCar);
}
void goBack(){
digitalWrite(IN_11, LOW);
digitalWrite(IN_12, HIGH);
analogWrite(ENA_m1, speedCar);
digitalWrite(IN_13, HIGH);
digitalWrite(IN_14, LOW);
analogWrite(ENB_m1, speedCar);
digitalWrite(IN_21, HIGH);
digitalWrite(IN_22, LOW);
analogWrite(ENA_m2, speedCar);
digitalWrite(IN_23, LOW);
digitalWrite(IN_24, HIGH);
analogWrite(ENB_m2, speedCar);
}
void goRight(){
digitalWrite(IN_11, LOW);
digitalWrite(IN_12, HIGH);
analogWrite(ENA_m1, speedCar);
digitalWrite(IN_13, HIGH);
digitalWrite(IN_14, LOW);
analogWrite(ENB_m1, speedCar);
digitalWrite(IN_21, LOW);
digitalWrite(IN_22, HIGH);
analogWrite(ENA_m2, speedCar);
digitalWrite(IN_23, HIGH);
digitalWrite(IN_24, LOW);
analogWrite(ENB_m2, speedCar);
}
void goLeft(){
digitalWrite(IN_11, HIGH);
digitalWrite(IN_12, LOW);
analogWrite(ENA_m1, speedCar);
digitalWrite(IN_13, LOW);
digitalWrite(IN_14, HIGH);
analogWrite(ENB_m1, speedCar);
digitalWrite(IN_21, HIGH);
digitalWrite(IN_22, LOW);
analogWrite(ENA_m2, speedCar);
digitalWrite(IN_23, LOW);
digitalWrite(IN_24, HIGH);
analogWrite(ENB_m2, speedCar);
}
void goAheadRight(){
digitalWrite(IN_11, HIGH);
digitalWrite(IN_12, LOW);
analogWrite(ENA_m1, speedCar/speed_Coeff);
digitalWrite(IN_13, LOW);
digitalWrite(IN_14, HIGH);
analogWrite(ENB_m1, speedCar/speed_Coeff);
digitalWrite(IN_21, LOW);
digitalWrite(IN_22, HIGH);
analogWrite(ENA_m2, speedCar);
digitalWrite(IN_23, HIGH);
digitalWrite(IN_24, LOW);
analogWrite(ENB_m2, speedCar);
}
void goAheadLeft(){
digitalWrite(IN_11, HIGH);
digitalWrite(IN_12, LOW);
analogWrite(ENA_m1, speedCar);
digitalWrite(IN_13, LOW);
digitalWrite(IN_14, HIGH);
analogWrite(ENB_m1, speedCar);
digitalWrite(IN_21, LOW);
digitalWrite(IN_22, HIGH);
analogWrite(ENA_m2, speedCar/speed_Coeff);
digitalWrite(IN_23, HIGH);
digitalWrite(IN_24, LOW);
analogWrite(ENB_m2, speedCar/speed_Coeff);
}
void goBackRight(){
digitalWrite(IN_11, LOW);
digitalWrite(IN_12, HIGH);
analogWrite(ENA_m1, speedCar/speed_Coeff);
digitalWrite(IN_13, HIGH);
digitalWrite(IN_14, LOW);
analogWrite(ENB_m1, speedCar/speed_Coeff);
digitalWrite(IN_21, HIGH);
digitalWrite(IN_22, LOW);
analogWrite(ENA_m2, speedCar);
digitalWrite(IN_23, LOW);
digitalWrite(IN_24, HIGH);
analogWrite(ENB_m2, speedCar);
}
void goBackLeft(){
digitalWrite(IN_11, LOW);
digitalWrite(IN_12, HIGH);
analogWrite(ENA_m1, speedCar);
digitalWrite(IN_13, HIGH);
digitalWrite(IN_14, LOW);
analogWrite(ENB_m1, speedCar);
digitalWrite(IN_21, HIGH);
digitalWrite(IN_22, LOW);
analogWrite(ENA_m2, speedCar/speed_Coeff);
digitalWrite(IN_23, LOW);
digitalWrite(IN_24, HIGH);
analogWrite(ENB_m2, speedCar/speed_Coeff);
}
void stopRobot(){
digitalWrite(IN_11, LOW);
digitalWrite(IN_12, LOW);
analogWrite(ENA_m1, speedCar);
digitalWrite(IN_13, LOW);
digitalWrite(IN_14, LOW);
analogWrite(ENB_m1, speedCar);
digitalWrite(IN_21, LOW);
digitalWrite(IN_22, LOW);
analogWrite(ENA_m2, speedCar);
digitalWrite(IN_23, LOW);
digitalWrite(IN_24, LOW);
analogWrite(ENB_m2, speedCar);
}
void loop(){
String readString;
String Q;
while (Serial.available()){
delay(1);
if(Serial.available()>0){
char c = Serial.read();
if(isControl(c)){
break;
}
readString += c;
}
}
Q = readString;
if (Q=="S"){
stopRobot();
}
if (Q=="F"){
goAhead();
}
if (Q=="B"){
goBack();
}
if (Q=="L"){
goLeft();
}
if (Q=="R"){
goRight();
}
if (Q=="I"){
goAheadRight();
}
if (Q=="G"){
goAheadLeft();
}
if (Q=="J"){
goBackRight();
}
if (Q=="H"){
goBackLeft();
}
if (Q=="0"){
speedCar = 100;
}
if (Q=="1"){
speedCar = 120;
}
if (Q=="2"){
speedCar = 135;
}
if (Q=="3"){
speedCar = 155;
}
if (Q=="4"){
speedCar = 170;
}
if (Q=="5"){
speedCar = 185;
}
if (Q=="6"){
speedCar = 195;
}
if (Q=="7"){
speedCar = 215;
}
if (Q=="8"){
speedCar = 235;
}
if (Q=="9"){
speedCar = 255;
}
/* Serial.print(Q);
command = Q.toInt() ;
switch (command) {
case 'F':goAhead();break;
case 'B':goBack();break;
case 'L':goLeft();break;
case 'R':goRight();break;
case 'I':goAheadRight();break;
case 'G':goAheadLeft();break;
case 'J':goBackRight();break;
case 'H':goBackLeft();break;
case '0':speedCar = 100;break;
case '1':speedCar = 120;break;
case '2':speedCar = 135;break;
case '3':speedCar = 155;break;
case '4':speedCar = 170;break;
case '5':speedCar = 185;break;
case '6':speedCar = 195;break;
case '7':speedCar = 215;break;
case '8':speedCar = 235;break;
case '9':speedCar = 255;break;
case 'S':stopRobot();break;

