Differential thrust using 2 rc esc's and joystick

I just got my first arduino uno 2 weeks ago and have been loving the learning process and think im doing amazing on it by being able to control 2 rc brushless motors using the 2 axis joystick that i was able to harvest from a wii controller:) . I am able to run both the motors forward and reverse but am struggling with the differential thrust (decreasing power on one side and adding power on the other) depending on the horizontal axis (yAxis). Any help would be appreciated and i have done trial and error to get this far and after i get done with this project i promise to learn the correct way..lol

Heres what i got so far, im suspecting its the "if" statements or stating right and leftThrust too many times but hopefully you all can shed some light on this. Thanks!

#include <Servo.h>
Servo LeftESC, RightESC;
int yAxis=A0;
int xAxis=A1;
int leftThrust;
int rightThrust;

void setup() { 
LeftESC.attach(9, 1000, 2000);       // attached to pin 9 I just do this with 1 Servo
  Serial.begin(9600);    // start serial at 9600 baud
  LeftESC.write(2000);
  delay(2000);
  LeftESC.write(1000);
 
RightESC.attach(10,1000,2000);     // attached to pin 10 I just do this with 1 Servo
  Serial.begin(9600);    // start serial at 9600 baud
  RightESC.write(2000);
  delay(2000);
  RightESC.write(1000);
}

void loop() {
int yAxis = analogRead(A0);
int xAxis = analogRead(A1);

Serial.print("\ leftThrust:  ");
Serial.print(leftThrust);

Serial.print("\ rightThrust:  ");
Serial.print(rightThrust);

Serial.print("\ yAxis:  ");
Serial.print(yAxis);

Serial.print("\ xAxis:  ");
Serial.println(xAxis);
 
while (Serial.available() >0);

if (xAxis < 470) 
    // Turning Right
    { 
    // Map the number to a value of 255 maximum
    //xAxis = map(xAxis, 0, 470, 0, 128);     
    rightThrust = (yAxis - xAxis);
    leftThrust = (yAxis + xAxis);{
    // Don't exceed range of 0-255 for motor speeds 
    if(rightThrust <= 0)rightThrust = 128;
    else if(leftThrust >= 255)leftThrust = 255;}
    leftThrust = map(leftThrust, 0, 255, 1000, 2000);
    rightThrust = map(rightThrust, 0, 255, 1000, 2000);
    LeftESC.write(leftThrust);
    RightESC.write(rightThrust);     
    }
else if (xAxis>550) 
    // Turning Left
     {
    //xAxis = map(xAxis, 550, 1023, 128, 255);
    leftThrust = (xAxis - xAxis);
    rightThrust = (yAxis + xAxis);{
    // Don't exceed range of 0-255 for motor speeds
    if (leftThrust >= 255 )leftThrust = 255;
    else if(rightThrust <= 0)rightThrust = 128;}
    leftThrust = map(leftThrust, 0, 255, 1000, 2000);
    rightThrust = map(rightThrust, 0, 255, 1000, 2000);
    LeftESC.write(leftThrust);
    RightESC.write(rightThrust);        
    }

rightThrust = map(yAxis, 0,1020, 1000, 2000);
leftThrust = map(yAxis, 0,1020, 1000, 2000);  
LeftESC.write(leftThrust);
RightESC.write(rightThrust);
             
delay(500);
}

Too vague description. Give some engineering facts, data......
A flow chart of the code would likely tell how You are thinking, how the attempt is coded.
Dry reading code, trying to identify Your idea and finding the fault is very time consuming, more than many helpers will take on.

Sorry what i was referring to was that when i turn to the joystick left (xAxis > 550) i would like to decrease the pwm signal to leftthrust and increase to rightThrust and vice versa with turning right (xAxis<470) however currently the thrust values stay the same. Like i said i just got this 2 weeks ago and am unfamiliar with flow charts, dry reading code and i am running out of keywords to search to find the answers. i believe my issue is between line 40 and line 67 of the script i have posted in the post unless this isnt the place to post these type of issues.

Okey.

You have managed to get things moving, quite well. That's much more than many new members do.

Differential.... Difference between which....? Is a change in X joystick supposed to affect the Y joystick action?...

Shakespeare is known to use the highest amount of words but words, novells, never manage to be precise, pin point the target.

"i just got this 2 weeks ago " tells what? Many helpers are highly qualified and experienced engineers and expect questions to have some engineering taste. "Mama help me" gives more or less sarkastic replies.

This part in loop looks odd, unusual to me:

while (Serial.available() >0);

if (xAxis < 470) 

Enough. Post engineering facts, not words.

With myself not being a engineer and only having this product for 2 weeks your clearly talking over my head. A quick google search will explain differential thrust i will try to explain again, when turning the xAxis (horizontal) pot to the left i would like the leftThrust (leftESC) to decrease pwm and the rightThrust (rightESC) to increase pwm and when i turn the pot to the right i would like the rightThrust (rightESC) to decrease pwm and leftThrust (leftESC) to increasepwm. I have tried to make a statement in the code to limit it to not go over the maximum amount and not go under as well. This seems very similar to a 2 motor robot that turns using the motor speed, all the examples i have found use motor drivers and i am having issues making it work for a rc ESC using PWM. If you feel like you need to have anymore sarcastic reply's then just let someone that can provide some guidance chime in as i obviously can not give you the required info for your assistance. Thanks!

You tell You're struggling. No information in that. Can You tell what is actually happening?
What does the Serial.print data look like? What does a sweep from the very left to the very right tell?

What is the purpose of while (Serial.available() > 0);?
The execution will run in loop until a character is available.
Then the execution will hang up on that line and the outputs will run using the last written value.

what is happening is when i push forward on the vertical yaxis both (left and right thrust values go to full as they should, works great forward and backward. my whole issue iwhole issue seem to be in my "if" statements where i am expecting to turn the joystick on the xAxis to the left and see the left thrust value decrease and the right thrust value to increase and vice versa going to the other direction. currently both left and rightthrust values stay the same.

As far as the (Serial.available() > 0); ? i deleted that as it was part of a failed attempt using someones elses code.

That will always be zero.

is there a better way of decreasing the value in that instance? i added a "if" statement after that if it less than 0 just make it zero to keep out of the negative values but it makes sense what your saying now.

Check up this piece of code. Why that left curly bracket at the end of the first snippet line? The corresponding right bracket needs to be handle, removed, as well.

    rightThrust = (yAxis + xAxis); {
      // Don't exceed range of 0-255 for motor speeds
      if (leftThrust >= 255 )leftThrust = 255;
      else if (rightThrust <= 0)rightThrust = 128;
    }

The IDE autoformat function, Ctrl+T, or tools/autoformat often makes it easy to see mistakes.

I didnt even know the name of the curly bracket or snippet line so i will have to look those up and how they are used. I noticed in other peoples codes they were used so I was under the impression they were used for a nesting formula or something to that nature. Thanks for the Ctrl+T tip that works great!

You have copied some code?
That curly bracket is likely a remainder from an earlier version being changed but not properly cleaned up.

After a few more failed attempts and going back over a helpful youtube video here Arduino DC Motor Control Tutorial - L298N | H-Bridge | PWM | Robot Car - YouTube I was able to get it working. Here is my code incase anyone can improve on it or will find it useful.

#include <Servo.h>
Servo LeftESC, RightESC;
int yAxis = A0;
int xAxis = A1;
int leftThrust;
int rightThrust;
int xMapped;

void setup() {
  LeftESC.attach(9, 1000, 2000);
  Serial.begin(9600);
  LeftESC.write(2000);
  delay(2000);
  LeftESC.write(1000);

  RightESC.attach(10, 1000, 2000);   
  Serial.begin(9600);
  RightESC.write(2000);
  delay(2000);
  RightESC.write(1000);
}
void loop() {
  int yAxis = analogRead(A0);
  int xAxis = analogRead(A1);

  Serial.print("\ leftThrust:  ");
  Serial.print(leftThrust);

  Serial.print("\ rightThrust:  ");
  Serial.print(rightThrust);

  Serial.print("\ yAxis:  ");
  Serial.print(yAxis);

  Serial.print("\ xAxis:  ");
  Serial.println(xAxis);

  if (yAxis < 470) {
    // Reverse
    leftThrust = map(yAxis, 470, 0, 1000, 1500);
    rightThrust = map(yAxis, 470, 0, 1000, 1500);
  }
  else if (yAxis > 550) {
    //Forward
    leftThrust = map(yAxis, 550, 1023, 1500, 2000);
    rightThrust = map(yAxis, 550, 1023, 1500, 2000);
  }
  else {
    leftThrust = 1500;
    rightThrust = 1500;
  }
  if (xAxis <= 470) {
    // Turning Right
    int xMapped = (xAxis, 470, 0, 1500, 2000);
    rightThrust = rightThrust - xMapped;
    leftThrust = leftThrust + xMapped;
    if (rightThrust < 1500)rightThrust = 1500; {
      if (leftThrust > 2000)leftThrust = 2000;
    }
  }
  if (xAxis >= 550) {
    // Turning Left
    int xMapped = (xAxis, 550, 1023, 1500, 2000);
    leftThrust = leftThrust - xMapped;
    rightThrust = rightThrust + xMapped;
    if (leftThrust < 1500 )leftThrust = 1500; {
      if (rightThrust > 2000)rightThrust = 2000;
    }
  }
  LeftESC.write(leftThrust);
  RightESC.write(rightThrust);

  delay(500);
}

Key observation: Represent the thrust as a mean thrust and a difference explicitly.

Don't use leftThrust and rightThrust.

Whenever you want to output thrusts output the mean+difference and mean-difference
to the two ESCs.

This same approach is used in quadcopters for deciding the 4 thrusts based on throttle, roll, pitch and yaw command inputs.

front_left.write (throttle + pitch + roll + yaw) ;
front_right.write (throttle + pitch - roll - yaw) ;
back_left.write (throttle - pitch + roll - yaw) ;
back_right.write (throttle - pitch - roll + yaw) ;

So by doing that will i have something like LeftESC.write(thrust + pitch) and RightESC.write(thrust - picth) on each of the if statements in the current code and do away with the thrust values?

They are thrust values, but common and differential, rather than left and right. Its like driving a car (throttle+steering) compared to driving a tank (left + right handles).