joystick (2pots) and 2 dc motors "tank"

hi can anyone help I want to control a tank steer bot with a joystick, the the motor have a pwm pin and a reverse pin each and the joy is an x and y pot how do I go about coding in reverse and differential drive??

Read the x pot setting, using analogRead. The range of values returned should be between 0 and 1023. With the joystick in the neutral position, the value should be around 512. If the value is greater than the neutral position, go one direction. If it's less than the neutral position, go the other way.

Read the y pot setting. The range of values returned should be between 0 and 1023. With the joystick in the neutral position, the value should be around 512. If the value is greater than the neutral position, go left (or right). If it's less than the neutral position, go the other way. The farther from the neutral position, the greater the value to send to the outside motor and the smaller the value to send to the inside motor.

yes I understood that from the start, what I was looking for was a way to do the math that "keeps it simple"

anyway after about 10 minutes of posting I started putting something together and it resulted in this, I went down this route as i'm trying to get "fluent" with arduino language there is probably an easy way to do it and please point me in the right direction but im still on a steep learning curve.

//
//
// Tank bot work in progress 30/12/10 version 0.5:

#include "Ultrasonic.h"

#include <Servo.h>

#include <LiquidCrystal.h>

// Displays/leds

LiquidCrystal lcd(23, 25, 27, 29, 31, 33);
int backlight  = 13 ;

//turret and servo(s)

Ultrasonic ultrasonic  (45,47);
Servo scanservo ;
Servo Larmservo ;
Servo Harmservo ;

long LDistance = 0 ;
long RDistance = 0 ;
long CDistance = 0 ;

//motor pins and reverse

const int RTMPin     = 5 ;
const int RTRPin     = 4 ;
const int LTMPin     = 6 ;
const int LTRPin     = 7 ;

// pointometers/joystick

int potpin   = A13 ;
int joyx     = A15 ;
int joyy     = A14 ;

// digital sensors/buttons

int Lbump    = 49 ;
int Rbump    = 51 ;

// variables
int potval  = 0 ;
int joyxval = 0 ;
int joyyval = 0 ;
int RTval   = 0 ;
int LTval   = 0 ;
int LDval   = 0 ;
int RDval   = 0 ;

/////////////////////////////////////////////////////////////////////////////////////

void setup() {

Serial.begin(9600);
 
lcd.begin(16, 2);
lcd.print("testing...");
pinMode (backlight, OUTPUT);
analogWrite (backlight, 25);

scanservo.attach(9);
Larmservo.attach(11);
Harmservo.attach(12);

scanservo.write(90);
Harmservo.write(35);
Larmservo.write(0);

pinMode (RTMPin, OUTPUT);
pinMode (RTRPin, OUTPUT);
pinMode (LTMPin, OUTPUT);
pinMode (LTRPin, OUTPUT);

pinMode (potpin, INPUT);
pinMode (joyx,   INPUT);
pinMode (joyy,   INPUT);
pinMode (Lbump,  INPUT);
pinMode (Rbump,  INPUT);
}

/////////////////////////////////////////////////////////////////////////////////////

void loop()
{
  potval = analogRead(potpin); 
  LDval = analogRead(joyy);
  RDval = analogRead(joyy); 
  LDval = map (LDval, 515, 610, 0, 255);
  RDval = map (RDval, 515, 425, 0, 255);
  
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("pot, ");
  lcd.print(RDval);
  lcd.setCursor(0, 1);
  lcd.print("range, ");
  lcd.print(ultrasonic.Ranging(CM));
   
 
if (analogRead(joyx)<512)
{
LTval = analogRead(joyx);            
LTval = map(LTval, 500, 410, 0, 255);
RTval = analogRead(joyx);            
RTval = map(RTval, 500, 410, 0, 255);

LTval = (LTval - constrain (RDval, 0, 255));
RTval = (RTval - constrain (LDval, 0, 255));

analogWrite  (RTMPin, constrain (LTval, 0, 255));       
analogWrite  (LTMPin, constrain (RTval, 0, 255));
digitalWrite (RTRPin, HIGH);
digitalWrite (LTRPin, HIGH);
}
if (analogRead(joyx)>513)
{
LTval = analogRead(joyx);            
LTval = map(LTval, 510, 600, 0, 255);
RTval = analogRead(joyx);           
RTval = map(RTval, 510, 600, 0, 255);

LTval = (LTval - constrain (RDval, 0, 255));
RTval = (RTval - constrain (LDval, 0, 255));

analogWrite  (RTMPin, constrain (LTval, 0, 255));       
analogWrite  (LTMPin, constrain (RTval, 0, 255));
digitalWrite (RTRPin, LOW);
digitalWrite (LTRPin, LOW);
}

delay(150);
 
}

A few quick thoughts for you.

I can see some places where you've mixed up "joyx" and "joyy" in your code. Compilers usually can't catch errors like that for you, so you need to make them easier to spot for yourself. It helps to make names more distinct visually. In this case, I'd name those variables "joy_x" and "joy_y".

You'll need to create "dead bands" in the center of the joystick axes, unless you're secretly a robot who can move the joystick exactly down the center of one axis in a perfect straight line when you don't want to affect the other axis. And you're going to need to tweak those values after you've experimented with your design. You may also need to tweak them to account for the part-to-part variations among joysticks. So you'll want to define them as symbolic constants, or maybe even variables you load out of EEPROM at startup, like:

#define X_deadband_min 500
#define X_deadband_max 525

or

int X_deadband_min = 500;
int X_deadband_max = 525;

This wil also make your code easier to read, because it will provide an indication of what those map() calls are doing.

Thanks for the help.
I have deadbands in the mapped values, It works good for now. I have written more into the sketch and I'll upload a video of the testing soon and an updated version of the code.
What i wanted to be able to do was when i have no forward input only direction was reverse one and give a proportional speed value, but this works and is easy to control and adjust.

just had a better thought of how to map the values

map (val, 0, 1024, -255, 255)
if (val<0)
map (val, 0, -255, 0, 255)
if (val>0)
constrain (val, 0, 255)