Arduino2Arduino RC via serial of DE Sabertooth

Hello All!

Since this is my first post in any forum I would like to extend my thanks to all those whom have helped me so far by assisting others (I have been floating around learning a little by little from observing this forum).

I have picked up a project to hopefully teach myself a little about a lot. Ultimately to use two Arduino’s to control a 1/8th scale model King Tiger tank. A Duemilanove as a transmitter and a Mega as a receiver.

At present I have hit a wall with the receiver sketch. Currently I have the transmitter and receiver sending and receiving packets and being able to Serial.print the results but as of yet have not been able to have the Mega control the 2x25 Sabertooth I have on my testbed. http://www.dimensionengineering.com/datasheets/Sabertooth2x25.pdf

Transmitter;

/*
--Dual Liquidware Input Shield Controller/Transmitter--

Components;
Arduino Duemilanove
Dual Liquidware Lithiun Backpacks
Liquidware Triplewide Extender Sheild
Xbee Sheild
  - Modified to fit in center panel of Extender Shield
    (Protruding edge removed)
  - 5V and GND wires soldered in to power Xbee
    (No ICSP Pins on Extender Shield for power)
Xbee 900 Pro (wire ant.)

--Arduino Pin Configuration--
Digital-
4   - Button LB
5   - Button LA
6   - Button LJOY
8   - Button RB
9   - Button RA
10  - Button RJOY
Analog
2   - Joy LV
3   - Joy LH
4   - Joy RV
5   - Joy RH

Remote Serial communication via Xbee 900 Pro (wire ant.) 
Current Xbee Config;
VID - 7FFF
HP  - 7
SH  - 13A200
SL  - 405387D8
DH  - 13A200
DL  - 40531963
BD  - 38400
NB  - 0
RO  - 0

Xbee modules in use are paired - see corressponding SH and DL settings.
*/
byte ljoyV, ljoyH, rjoyV, rjoyH;
const byte southpaw = 0;
//change value to any int other than 0 for southpaw setup.
int digital;
int LA = 5;
int LB = 4;
int LJ = 6;
int RA = 9;
int RB = 8;
int RJ = 10;
int notdeadyet = 13;
int i;

void setup(){
  Serial.begin(38400);
  digitalWrite(LA, HIGH); pinMode(LA, INPUT);
  digitalWrite(LB, HIGH); pinMode(LB, INPUT);
  digitalWrite(LJ, HIGH); pinMode(LJ, INPUT);
  digitalWrite(RA, HIGH); pinMode(RA, INPUT);
  digitalWrite(RB, HIGH); pinMode(RB, INPUT);
  digitalWrite(RJ, HIGH); pinMode(RJ, INPUT);
  
  pinMode(notdeadyet, OUTPUT);
  i = 0;
}

void loop(){
  rjoyV = map(analogRead(2), 0, 1023, 1, 255);
  delay(5);
  rjoyH = map(analogRead(3), 0, 1023, 1, 255);
  delay(5);
  ljoyV = map(analogRead(4), 0, 1023, 1, 255);
  delay(5);
  ljoyH = map(analogRead(5), 0, 1023, 1, 255);
  delay(5);
  digital = 1;
  if(digitalRead(RJ) == LOW){
    digital = 2;
  }
  if(digitalRead(RB) == LOW){
    digital = 4;
  }
  if(digitalRead(RA) == LOW){
    digital = 8;
  }
  if(digitalRead(LB) == LOW){ 
    digital = 16;
  }
  if(digitalRead(LA) == LOW){
    digital = 32;
  }
  if(digitalRead(LJ) == LOW){
    digital = 64;
  }

  Serial.print(0xff,BYTE);
  Serial.print(rjoyV,BYTE);
  Serial.print(rjoyH,BYTE);
  Serial.print(ljoyV,BYTE);
  Serial.print(ljoyH,BYTE);
  Serial.print(digital,BYTE);  // buttons
  Serial.print(southpaw,BYTE); // southpaw??
  Serial.print((unsigned char)(255 - (rjoyV+rjoyH+ljoyV+ljoyH+soutpaw+digital)%256),BYTE);
/* 
  //For Debug print packet
  Serial.print(int(rjoyV));
  Serial.print("' ");
  Serial.print(int(rjoyH));
  Serial.print("' ");
  Serial.print(int(ljoyV));
  Serial.print(int(ljoyH));
  Serial.print("' ");
  Serial.print(int(digital));
  Serial.print("' ");
  Serial.print(int(soutpaw));
  Serial.print("' ");
  Serial.print(int((rjoyV+rjoyH+ljoyV+ljoyH+digital)));
  Serial.print("\n");
*/ 
  for(i ; i == 10 ; )
  {
    digitalWrite(notdeadyet,HIGH);
    delay(6);
    digitalWrite(notdeadyet,LOW);
    i=0;
    Serial.flush(); //ensure buffer clears
  }
  i++;
  delay(32);
}

Receiver

/*
-----End project------
 --1/8th scale Tiger 2--
 
 Sabertooth Setups
 --Hull--
 Address; 130
 Dip Configuration;
 Dip1 - Down
 Dip2 - Down
 Dip3 - Up
 Dip4 - Up
 Dip5 - Down
 Dip6 - Up
 Single joystick instead of skid steering
 Mixed mode commands - command1, command2
 
 --Turret--
 Address; 128
 Dip Configuration;
 Dip1 - Down
 Dip2 - Down
 Dip3 - Up
 Dip4 - Up
 Dip5 - Up
 Dip6 - Up
 Standard motor control commands - command3, command4
 Channel 1 - Turret Rotation
 Channel 2 - Gun Elevation
 
 Arduino MEGA VIN        --   Hull Sabertooth 5V
 Arduino MEGA GND        --   Hull Sabertooth 0V
 Arduino MEGA Serial1    --   Hull and Turret Sabertooth S1 (Serial connection)
 Arduino MEGA I/O pin 54 --   Hull and Turrey Sabertooth S2 (Kill Switch) (Not yet implemented)
 Arduino MEGA Serial     --   Xbee/Xbee and Serial Monitor
 
 All Sabertooth S1 inputs are tied together.
 All Sabertooth S2 inputs can be tied together. Pulling the S2 input low will cause the driver to shut down.
 
 Remote Serial communication via Xbee 900 Pro (U.fl) 
 Current Xbee Config;
 VID - 7FFF
 HP  - 7
 SH  - 13A200
 SL  - 40531963
 DH  - 13A200
 DL  - 405387D8
 BD  - 38400
 NB  - 0
 RO  - 0
 
 Xbee modules in use are paired - see corressponding SH and DL settings.
 
 50kg of mad metal tank when a sketch doesnt work the way you want....
 
 Thus...
 
 --Test Bed Setup--
 7.4V LiPo
 Arduino Mega
 Single 2x25 Sabertooth
 Switch - Umm... on and off?
 Mega Protosheild
 Tamiya Dual gearbox
 Replacement motors for gearbox fitted with filter caps (noisey buggers)
 Pololu injection moulded sprockets and mini tracks
 Tamiya Universal Plate set (Chassis and decks)
 
 Arduino MEGA VIN       --   Hull Sabertooth 5V
 Arduino MEGA GND       --   Hull Sabertooth 0V
 Arduino MEGA Serial1   --   Hull Sabertooth S1 
 Arduino MEGA Serial    --   Xbee/Xbee and Serial Monitor
 
 Sabertooth Setup
 Address; 130
 Dip Configuration;
 Dip1 - Down
 Dip2 - Down
 Dip3 - Down (LiPo)
 Dip4 - Up
 Dip5 - Down
 Dip6 - Up
 
 Again remote serial communication via Xbee 900 Pro (U.fl)
 (modified with additional wire ant. for use on Test bed) 
 Current Xbee Config;
 VID - 7FFF
 HP  - 7
 SH  - 13A200
 SL  - 40531963
 DH  - 13A200
 DL  - 405387D8
 BD  - 38400
 NB  - 0
 RO  - 0
 Xbees have been proven.
 */

byte  ljoyver, ljoylat;   //Received left joystick readings
byte  rjoylat, rjoyver;   //Received left joystick readings
byte  digital;            //Yet to be used, for determining if buttons have been pressed on controller
int   vals[7];            //Stores received serial bytes
int   checksum   =   0;
byte  southpaw;
int   count      =  -1;
int   error      =  13;   //Error indication on LED pin 13
int   badpacket  =   0;   //Counts bad packets
int   stoppin    =  54;   //Connected to Sabertooth S2 on both controllers - not used on testbed.

//For digital inputs on controller
int   digdata;
const byte dig1  =   1; 
const byte dig2  =   2; 
const byte dig3  =   4; 
const byte dig4  =   8; 
const byte dig5  =  16; 
const byte dig6  =  32; 

//Hull Sabertooth Motor Command bytes
const byte mixedforward =  8;
const byte mixedreverse =  9;
const byte mixedright   = 10;
const byte mixedleft    = 11;
//Turret Sabertooth Motor Command bytes
const byte rotleft      =  0;
const byte rotright     =  1;
const byte gunup        =  4;
const byte gundown      =  5;
//Commands returned from function hull() and turret().
byte  command1, command2, command3, command4;
byte  drive, steer, rotation, elevation;

//For functions senddrive, sendrotation and sendelevation.
byte  command1B, command2B, command3B, command4B;
byte  driveB, steerB, rotationB, elevationB;
//Not sure if are really required. See below in void loop()

void setup() 
{
  pinMode(error, OUTPUT);      //Indicates (blink) if a bad packet has been recieved
  pinMode(stoppin, OUTPUT);    //Emergency Stop pin
  digitalWrite(stoppin, HIGH); //If brought low shuts down Saberteeth
  Serial.begin(38400);
  Serial1.begin(38400);        // start serial port controlling Sabertooth Controllers
  delay(2000);                 // Required 2000 delay before sending 170(byte) to Sabertooth Controllors
  Serial1.print(170, BYTE);    // Bauding character to set Sabertooth Controllor's baud rate
  // Digital pins
  pinMode (40, OUTPUT);
  pinMode (44, OUTPUT);
  pinMode (46, OUTPUT);
  pinMode (48, OUTPUT);
  pinMode (50, OUTPUT);
  pinMode (52, OUTPUT);  
}

//Turret and Gun Control//
byte turret(byte rjoylat, byte rjoyver)
{
  byte command3, command4;
  byte rotation, elevation;
  //Gun elevation - Up commands//
  if (rjoyver > 140)
  {                                     
    command3 = gunup;
    elevation = map(elevation, 141, 255, 1, 127);
  } 
  //Gun elevation - Down commands//
  else if (rjoyver < 115)
  {                              
    command3 = gundown;
    elevation = (128 - (map(rjoyver, 1, 115, 1, 127)));
  }
  //Elevation Idle//    
  else
  {                                                    
    command3 = gunup;
    elevation = 0;
  }
  //Turret - right rotation//
  if (rjoylat > 140)
  {                                    
    command4 = rotright;
    rotation = map(rjoylat, 141, 255, 1, 127);
  } 
  //Turret - left rotation//
  else if  (rjoylat < 115)
  {                              
    command4 = rotleft;
    rotation = (128 - (map(rjoylat, 1, 115, 1, 127)));
  }
  //Rotation Idle//
  else
  {                           
    command4 = rotleft;
    rotation = 0;
  }
  return command3, command4;
  return rotation, elevation;
}
//Hull control//
byte hull(byte ljoyver, byte ljoylat)
{
  byte command1, command2;
  byte drive, steer;
  //Forward Right Mixed Commands//
  if (ljoyver > 140 && ljoylat < 115)
  {
    command1 = mixedforward;
    command2 = mixedright;
    drive = map(ljoyver, 140, 255, 1, 127);
    steer = (115 - (map(ljoylat, 1, 115, 1, 127)));
  } 
  //Forward Left Mixed Commands//
  else if ((ljoyver > 140) && (ljoylat > 140))
  {   
    command1 = mixedforward;
    command2 = mixedleft;
    drive = map(ljoyver, 141, 255, 1, 127); //Not mapped from 140 as it the minimum would be 141.
    steer = (ljoylat  - 140);
  }
  //Reverse Right Mixed Commands//
  else if ((ljoyver < 115) && (ljoylat < 115))
  {          
    command1 = mixedreverse;
    command2 = mixedright;  
    drive = (128 - (map(ljoyver, 1, 115, 1, 127))); //0 = Stop 128 used to prevent this
    steer = (115 - (map(ljoylat, 1, 115, 1, 127))); //Ditto
  }
  //Reverse Left Mixed Commands//
  else if ((ljoyver < 115) && (ljoylat > 140))
  {         
    command1 = mixedreverse;
    command2 = mixedleft;
    drive = (128 - (map(ljoyver, 1, 115, 1, 127)));
    steer = map(ljoylat, 141, 255, 1, 127);
  }
  //Forward Mixed - Straight//
  else if ((ljoyver > 140) && ((115 <= ljoylat) && (ljoylat <= 140)))
  {   
    command1 = mixedforward;
    command2 = mixedright;
    drive = map(ljoyver, 141, 255, 1, 127);
    steer = 0;
  }
  //Reverse Mixed - Straight//
  else if ((ljoyver < 115) && ((115 <= ljoylat) && (ljoylat <= 140)))
  {   
    command1 = mixedreverse;
    command2 = mixedright;
    drive = (128 - (map(ljoyver, 1, 115, 1, 127)));
    steer = 0;
  } 
  //Full Right Mixed//
  else if (((115 <= ljoyver) && (ljoyver <= 140)) && (ljoylat < 115))
  {   
    command1 = mixedforward;
    command2 = mixedright;
    drive = 0;
    steer = (128 - (map(ljoylat, 1, 115, 1, 127)));
  }  
  //Full Left Mixed//
  else if (((115 <= ljoyver) && (ljoyver <= 140)) && (ljoylat > 140))
  {   
    command1 = mixedreverse;
    command2 = mixedright;
    drive = 0;
    steer = map(ljoylat, 141, 255, 1, 127);
  }
  //Both Motors Idle//
  else   //No conditions required -- all thats left
  {
    command1 = mixedreverse;
    command2 = mixedright;
    drive = 0;
    steer = 0;
  } 
  return command1, command2;
  return drive, steer;
}
//void senddrive sends via Serial1 two packets, one for direction and a second for mixed steering.
//Both channels controlled from one joystick and sent to the same Sabertooth - Addressed 130
void senddrive(byte command1B, byte driveB, byte command2B, byte steerB)
{//Capital B's may be removed, unsure if converting hull() and turret() outputs help..
  Serial1.print(130, BYTE);      //Address
  Serial1.print(command1B, BYTE); //Direction
  Serial1.print(driveB, BYTE);    //Rate
  Serial1.print((130 + command1B + driveB) & 0b01111111, BYTE); //Required checksum with mask
  delay(5);
  Serial1.print(130, BYTE);      //Address
  Serial1.print(command2B, BYTE); //Direction
  Serial1.print(steerB, BYTE);    //Rate
  Serial1.print((130 + command2B + steerB) & 0b01111111, BYTE); //Required checksum with mask 
}/*
void senddrive(byte command1, byte drive, byte command2, byte steer) //original
{
  Serial1.print(130, BYTE);      //Address
  Serial1.print(command1, BYTE); //Direction
  Serial1.print(drive, BYTE);    //Rate
  Serial1.print((130 + command1 + drive) & 0b01111111, BYTE); //Required checksum with mask
  Serial1.print(130, BYTE);      //Address
  Serial1.print(command2, BYTE); //Direction
  Serial1.print(steer, BYTE);    //Rate
  Serial1.print((130 + command2 + steer) & 0b01111111, BYTE); //Required checksum with mask 
}*/

Second part of the Receiver sketch;

//only testable currently by changing testbed sabertooth's address to 128
//void sendelevation sends via Serial1 a single packet to control gun elevation.
//elevation acheived via Sabertooth -> 12v linear actuator(stroke internally limited)
//Single packet for second channel on second Sabertooth, Addressed - 128.
void sendelevation(byte command3B, byte elevationB)
{//Capital B's may be removed, unsure if converting hull() and turret() outputs help..
  Serial1.print(128, BYTE);
  Serial1.print(command3B, BYTE);
  Serial1.print(elevationB, BYTE);
  Serial1.print((128 + command3B + elevationB) & 0b01111111, BYTE); //Required checksum with mask
}/*
void sendelevation(byte command3, byte elevation) //original
{
  Serial1.print(128, BYTE);
  Serial1.print(command3, BYTE);
  Serial1.print(elevation, BYTE);
  Serial1.print((128 + command3 + elevation) & 0b01111111, BYTE); //Required checksum with mask
}*/

//only testable currently by changing testbed sabertooth's address to 128
//void sendrotation sends via Serial1 a single packet to control turret rotation.
//turret rotation acheived via Sabertooth -> 12v gearmotor
//Single packet for first channel on second Sabertooth, Addressed - 128.
void sendrotation(byte command4B, byte rotationB)
{//Capital B's may be removed, unsure if converting hull() and turret() outputs help..
  Serial1.print(128, BYTE);
  Serial1.print(command4B, BYTE);
  Serial1.print(rotationB, BYTE);
  Serial1.print((128 + command4B + rotationB) & 0b01111111, BYTE); //Required checksum with mask
}/*
void sendrotation(byte command4, byte rotation) //original
{
  Serial1.print(128, BYTE);
  Serial1.print(command4, BYTE);
  Serial1.print(rotation, BYTE);
  Serial1.print((128 + command4 + rotation) & 0b01111111, BYTE); //Required checksum with mask
}*/

void loop()
{ 
  if(Serial.available() > 0)
  {
    if(count == -1)
    { // new packet?
      if(Serial.read() == 0xff)
      {
        count = 0;
        checksum = 0;
      }
    }
    else if(count == 0)
    {
      vals[count] = Serial.read();
      if(vals[count] != 0xff)
      {            
        checksum += vals[count];
        count++;
      }
    }
    else
    {
      vals[count] = Serial.read();
      checksum += vals[count];
      count++;
      if(count == 7)
      {// packet complete
        if(checksum%256 != 255)
        {// packet error!
          badpacket++;
          packeterror(badpacket);
        }
        else
        {//Assign values from array
          digital   = vals[4];
          southpaw  = vals[5];
          digdata   = digital;
          digitalout(digdata);
          badpacket = 0;
          if((southpaw) == true)
          {// SouthPaw controlls
            ljoyver = vals[0];
            ljoylat = vals[1];
            rjoyver = vals[2];
            rjoylat = vals[3];
          }
          else
          {
            rjoyver = vals[0];
            rjoylat = vals[1];
            ljoyver = vals[2];
            ljoylat = vals[3];
          } 
        }
        count = -1;
        Serial.flush(); //clear buffer
      }
    } 
    
    Serial.print("rjoyver = ");
    Serial.print(int(rjoyver));
    Serial.print(",  rjoylat = ");
    Serial.print(int(rjoylat));
    Serial.print("\n");
    Serial.print("ljoyver = ");
    Serial.print(int(ljoyver));
    Serial.print(",  ljoylat = ");
    Serial.print(int(ljoylat));
    Serial.print("\n");
    Serial.print("digital = ");
    Serial.print(int(digital));
    Serial.print("\n");

    hull(ljoyver, ljoylat);           //Should return values to sendrive
    turret(rjoyver, rjoylat);         //Should return values to sendelevation and send rotation
    
    command1 = command1B;           //If conversion is not required remove and uncomment alternate function calls
    command2  = command2B;
    command3 = command3B;
    command4 = command4B;
    driveB = drive;
    steerB = steer;
    elevationB = elevation;
    rotationB = rotation;
    senddrive(command1B, driveB, command2B, steerB);//Should controll the hull sabertooth with two serial packets
    sendelevation(command3B, elevationB);         //Should controll the turret sabertooth with a single serial packet
    sendrotation(command4B, rotationB);           //Should controll the turret sabertooth with a single serial packet
  /*
    hull(ljoyver, ljoylat);                     //Should return values to sendrive
    turret(rjoyver, rjoylat);                   //Should return values to sendelevation and send rotation
    senddrive(command1, drive, command2, steer);//Should controll the hull sabertooth with two serial packets
    sendelevation(command3, elevation);         //Should controll the turret sabertooth with a single serial packet
    sendrotation(command4, rotation);           //Should controll the turret sabertooth with a single serial packet
  */
  }
  else
  {
  Serial.print("No serial input available");
  Serial.print("\n");
  }
}

//Digital outs
//may change void to byte to accomodate use of digital or analog inputs ie; compass/gyro/acceler etc
//for target tracking or other applications.
void digitalout(byte digdata) 
{
  switch (digdata)
  {
  case dig1://RJ - Right joy button
    digitalWrite(40, HIGH);
    break;
  case dig2://RB - Right B button
    digitalWrite(44, HIGH);
    break;
  case dig3://RA - Right A button
    digitalWrite(46, HIGH);
    break;
  case dig4://LB - Left B button
    digitalWrite(48, HIGH);
    break;
  case dig5://LA - Left A button
    digitalWrite(50, HIGH);
    break;
  case dig6://LJ - Left joy button
    digitalWrite(52, HIGH);
    break;
  default://No buttons pressed this packet.
    digitalWrite(40, LOW);
    digitalWrite(44, LOW);
    digitalWrite(46, LOW);
    digitalWrite(48, LOW);
    digitalWrite(50, LOW);
    digitalWrite(52, LOW);
  }
} 
void packeterror(int badpacket)
{
  digitalWrite(error, HIGH);
  delay(5);
  digitalWrite(error, LOW);
  Serial.print("checksum fail");
  Serial.print("\n");

  if(badpacket > 254)
  {
    digitalWrite(error, HIGH);
    digitalWrite(stoppin, LOW);
    Serial.print("Reached 255 Bad Packets - Sabertooth Stop");
    Serial.print("\n");
  }
}

Hopefully someone can help this noob with my problem, as I'm at a loss to find where my problem lies.. It could be a simple logical error on my part or I'm heading off in the wrong dirrection.

My thanks in advance! /me

There are instructions on the data sheet that you linked to for connecting the Sabertooth to the battery and motors, and controlling them with a potentiometer.

Have you done that, to verify that the Sabertooth and motors are working?

In the mega code, you have this:

  pinMode (40, OUTPUT);
  pinMode (44, OUTPUT);
  pinMode (46, OUTPUT);
  pinMode (48, OUTPUT);
  pinMode (50, OUTPUT);
  pinMode (52, OUTPUT);

This gives no clue what pin 46, for example, is controlling, and makes coding mistakes, when you type digitalWrite(46, HIGH); when you meant digitalWrite(48, HIGH); hard to find and debug.

const int forwardPin = 46;
pinMode(forwardPin, OUTPUT);
digitalWrite(forwardPin, HIGH);

makes it much easier to see logic mistakes. forwardPin is harder to mistake for backwardPin than 46 is to mistake for 48.

Not that this addresses your problem, directly, but I don't know what your problem is, exactly.

You said

as of yet have not been able to have the Mega control the 2x25 Sabertooth

But, then you posted several pages of code that may or may not be working, without explaining whether simple code works with the Sabertooth, or whether you have indeed verified that the hardware is working.

Many thanks for the reply PaulS,

Yes the Sabertooth is funtional.

I have it working with RC filtered pwm and by treating the inputs on the motor controllor as servo’s.

Below is a sketch that works with the transmitter sketch slightly modified, (analog inputs are mapped 0 to 32, when read out of the array in the ‘servo’ receiver sketch these values are mapped back up to 180. It may not be the tidiest way to remove jitter when the joysticks are centered, but it does work rather well)

With this code I am trying to have a smaller tracked test bed, using a single Sabertooth, have a software and hardware kill switch. As my end result will be controlling a +50kg metal 1/8th model tank. I have had the larger model working well with pwm in the past but a loose ground connection has me feeling that that approach is a safety concern, which my roller door can attest to.

Servo receiver sketch;

--Test Bed Setup--
 7.4V LiPo
 Arduino Mega
 Single 2x25 Sabertooth
 Switch - Umm... on and off?
 Mega Protosheild
 Tamiya Dual gearbox
 Replacement motors for gearbox fitted with filter caps (noisey buggers)
 Pololu injection moulded sprockets and mini tracks
 Tamiya Universal Plate set (Chassis and decks)
 
 Arduino MEGA VIN       --   Hull Sabertooth 5V
 Arduino MEGA GND       --   Hull Sabertooth 0V
 Arduino MEGA I/O 36    --   Hull Sabertooth S1 
 Arduino MEGA I/O 42    --   Hull Sabertooth S2
 Arduino MEGA Serial    --   Xbee/Xbee and Serial Monitor
 
 Sabertooth Setup
 R/C Mode, LiPo, Micro controller
 Dip Configuration;
 Dip1 - Down
 Dip2 - Up
 Dip3 - Down (LiPo)
 Dip4 - Up
 Dip5 - Up
 Dip6 - Down
 
 Again remote serial communication via Xbee 900 Pro (U.fl)
 (modified with additional wire ant. for use on Test bed) 
 Current Xbee Config;
 VID - 7FFF
 HP  - 7
 SH  - 13A200
 SL  - 40531963
 DH  - 13A200
 DL  - 405387D8
 BD  - 38400
 NB  - 0
 RO  - 0
 */

#include <Servo.h>
byte  ljoyver, ljoylat;   //Received left joystick readings
byte  rjoylat, rjoyver;   //Received left joystick readings
byte  digital;            
int   vals[7];            
int   checksum   =   0;
byte  southpaw;
int   count      =  -1;
int   error      =  13;   //Error indication on LED pin 13
int   badpacket  =   0;   //Counts bad packets
int   stoppin    =  54;   //Connected to Sabertooth S2 on both controllers - not used on testbed.

//For digital inputs on controller
int   digdata;
const byte dig1  =   1; 
const byte dig2  =   2; 
const byte dig3  =   4; 
const byte dig4  =   8; 
const byte dig5  =  16; 
const byte dig6  =  32; 

Servo servo1; 
Servo servo2;
Servo servo3;
Servo servo4;

int motor1Pin = 36; 
int motor2Pin = 42; 
int motor3Pin = 11; 
int motor4Pin = 12; 


void setup() 
{
  servo1.attach(motor1Pin,1000,2000);
  servo2.attach(motor2Pin,1000,2000);
  servo3.attach(motor3Pin,1000,2000);                                          
  servo4.attach(motor4Pin,1000,2000);
  Serial.begin(38400);
  /*
  // Digital pins
  pinMode (40, OUTPUT);
  pinMode (44, OUTPUT);
  pinMode (46, OUTPUT);
  pinMode (48, OUTPUT);
  pinMode (50, OUTPUT);
  pinMode (52, OUTPUT);  */
}

void loop()
{ 
  while(Serial.available() > 0)
  {
    if(count == -1)
    { // new packet?
      if(Serial.read() == 0xff)
      {
        count = 0;
        checksum = 0;
      }
    }
    else if(count == 0)
    {
      vals[count] = Serial.read();
      if(vals[count] != 0xff)
      {            
        checksum += vals[count];
        count++;
      }
    }
    else
    {
      vals[count] = Serial.read();
      checksum += vals[count];
      count++;
      if(count == 7)
      {// packet complete
        if(checksum%256 != 255)
        {}// packet error!
        else
        {//Assign values from array
          digital   = vals[4];
          southpaw  = vals[5];
          digdata   = digital;
          //digitalout(digdata);
          if((southpaw) == true)
          {// SouthPaw controlls
            ljoyver = vals[0];
            ljoylat = vals[1];
            rjoyver = vals[2];
            rjoylat = vals[3];           
          }
          else
          {
            rjoyver = vals[0];
            rjoylat = vals[1];
            ljoyver = vals[2];
            ljoylat = vals[3];
          } 
        }
        count = -1;
        Serial.flush(); //clear buffer
      }
    } 
   servo1.write(map(ljoyver, 0, 32, 0, 180));
   servo2.write(map(ljoylat, 0, 32, 0, 180));
   servo3.write(map(rjoyver, 0, 32, 0, 180));
   servo4.write(map(rjoylat, 0, 32, 0, 180));
  }
}
/*
//Digital outs
//may change void to byte to accomodate use of digital or analog inputs ie; compass/gyro/acceler etc
//for target tracking or other applications.
void digitalout(byte digdata) 
{
  switch (digdata)
  {
  case dig1://RJ - Right joy button
    digitalWrite(40, HIGH);
    break;
  case dig2://RB - Right B button
    digitalWrite(44, HIGH);
    break;
  case dig3://RA - Right A button
    digitalWrite(46, HIGH);
    break;
  case dig4://LB - Left B button
    digitalWrite(48, HIGH);
    break;
  case dig5://LA - Left A button
    digitalWrite(50, HIGH);
    break;
  case dig6://LJ - Left joy button
    digitalWrite(52, HIGH);
    break;
  default://No buttons pressed this packet.
    digitalWrite(40, LOW);
    digitalWrite(44, LOW);
    digitalWrite(46, LOW);
    digitalWrite(48, LOW);
    digitalWrite(50, LOW);
    digitalWrite(52, LOW);
  }
} 
*/

Currently my ‘serial’ receiver sketch is different now, have realised that I cannot have multiple results from functions returned to being global. I believe that I still have a few logical errors too, but cant really put my finger on what they would be.

This gives no clue what pin 46, for example, is controlling, and makes coding mistakes, when you type digitalWrite(46, HIGH); when you meant digitalWrite(48, HIGH); hard to find and debug.

Yes, I do understand that, as I already have corresponding bytes comming through from the trasmitter Arduino, I have pulled them out into their own function. These are not used anywhere else in the sketch so I have left them alone for the time being. In the end they will be used to switch transitor driven relays.

And the corresponding, working, transmitter sketch for the Arduino treating the Sabertooth as a pair of servos.

It may help other noobs with similar intentions as myself..

 /*
--Dual Liquidware Input Shield Controller/Transmitter--
For Sabertooth 2x25 using Micro Controllor RC settings - Servo input 
Components;
Arduino Duemilanove
Dual Liquidware Lithiun Backpacks
Liquidware Triplewide Extender Sheild
Xbee Sheild
  - Modified to fit in center panel of Extender Shield
    (Protruding edge removed)
  - 5V and GND wires soldered in to power Xbee
    (No ICSP Pins on Extender Shield for power)
Xbee 900 Pro (wire ant.)

--Arduino Pin Configuration--
Digital-
4   - Button LB
5   - Button LA
6   - Button LJOY
8   - Button RB
9   - Button RA
10  - Button RJOY
Analog
2   - Joy LV
3   - Joy LH
4   - Joy RV
5   - Joy RH

Remote Serial communication via Xbee 900 Pro (wire ant.) 
Current Xbee Config;
VID - 7FFF
HP  - 7
SH  - 13A200
SL  - 405387D8
DH  - 13A200
DL  - 40531963
BD  - 38400
NB  - 0
RO  - 0

Xbee modules in use are paired - see corressponding SH and DL settings.
*/
byte ljoyV, ljoyH, rjoyV, rjoyH;
const byte southpaw = 0;
//change value to any int other than 0 for southpaw setup.
int digital;
int LA = 5;
int LB = 4;
int LJ = 6;
int RA = 9;
int RB = 8;
int RJ = 10;
int notdeadyet = 13;
int i;

void setup(){
  Serial.begin(38400);
  digitalWrite(LA, HIGH); pinMode(LA, INPUT);
  digitalWrite(LB, HIGH); pinMode(LB, INPUT);
  digitalWrite(LJ, HIGH); pinMode(LJ, INPUT);
  digitalWrite(RA, HIGH); pinMode(RA, INPUT);
  digitalWrite(RB, HIGH); pinMode(RB, INPUT);
  digitalWrite(RJ, HIGH); pinMode(RJ, INPUT);
  
  pinMode(notdeadyet, OUTPUT);
  i = 0;
}

void loop(){
  //Mapped to 0 -> 32 for smoother opperation and a less active stick center
  rjoyV = map(analogRead(2), 0, 1023, 0, 32);
  delay(5);
  rjoyH = map(analogRead(3), 0, 1023, 0, 32);
  delay(5);
  ljoyV = map(analogRead(4), 0, 1023, 0, 32);
  delay(5);
  ljoyH = map(analogRead(5), 0, 1023, 0, 32);
  delay(5);
  digital = 1;
  if(digitalRead(RJ) == LOW){
    digital = 2;
  }
  if(digitalRead(RB) == LOW){
    digital = 4;
  }
  if(digitalRead(RA) == LOW){
    digital = 8;
  }
  if(digitalRead(LB) == LOW){ 
    digital = 16;
  }
  if(digitalRead(LA) == LOW){
    digital = 32;
  }
  if(digitalRead(LJ) == LOW){
    digital = 64;
  }

  Serial.print(0xff,BYTE);     //Header/indicator/flag..
  Serial.print(rjoyV,BYTE);
  Serial.print(rjoyH,BYTE);
  Serial.print(ljoyV,BYTE);
  Serial.print(ljoyH,BYTE);
  Serial.print(digital,BYTE);  // buttons
  Serial.print(southpaw,BYTE); // southpaw??
  Serial.print((unsigned char)(255 - (rjoyV+rjoyH+ljoyV+ljoyH+southpaw+digital)%256),BYTE);
/* 
  //For Debug print packet
  Serial.print(int(rjoyV));
  Serial.print("' ");
  Serial.print(int(rjoyH));
  Serial.print("' ");
  Serial.print(int(ljoyV));
  Serial.print(int(ljoyH));
  Serial.print("' ");
  Serial.print(int(digital));
  Serial.print("' ");
  Serial.print(int(southpaw));
  Serial.print("' ");
  Serial.print(int((rjoyV+rjoyH+ljoyV+ljoyH+digital)));
  Serial.print("\n");
*/ 
  for(i ; i == 10 ; )
  {
    digitalWrite(notdeadyet,HIGH);
    delay(6);
    digitalWrite(notdeadyet,LOW);
    i=0;
    Serial.flush(); //ensure buffer clears
  }
  i++;
  delay(32);
}

Yes, it happens to be more pages of code, hopefully it helps others understand my setup and what I wish to be achieving.

And here is the ‘serial’ sketch in it’s current state;

 byte  ljoyver, ljoylat;   //Received left joystick readings
byte  rjoylat, rjoyver;   //Received left joystick readings
byte  digital;            //Yet to be used, for determining if buttons have been pressed on controller
int   vals[7];            //Stores received serial bytes
int   checksum   =   0;
byte  southpaw;
int   count      =  -1;
//int   error      =  13;   //Error indication on LED pin 13
//int   badpacket  =   0;   //Counts bad packets
//int   stoppin    =  54;   //Connected to Sabertooth S2 on both controllers - not used on testbed.

//For digital inputs on controller
int   digdata;
const byte dig1  =   1; 
const byte dig2  =   2; 
const byte dig3  =   4; 
const byte dig4  =   8; 
const byte dig5  =  16; 
const byte dig6  =  32; 
//Hull Sabertooth Motor Command bytes
const byte mixedforward =  8;
const byte mixedreverse =  9;
const byte mixedright   = 10;
const byte mixedleft    = 11;
//Turret Sabertooth Motor Command bytes
const byte rotleft      =  0;
const byte rotright     =  1;
const byte gunup        =  4;
const byte gundown      =  5;
//Commands returned from function hull() and turret().
byte  command1, command2, command3, command4;
byte  drive, steer, rotation, elevation;

void setup() 
{
  //digitalWrite(stoppin, HIGH); //If brought low shuts down Saberteeth
  Serial.begin(38400);
  Serial1.begin(38400);        // start serial port controlling Sabertooth Controllers
  delay(2000);                 // Required 2000 delay before sending 170(byte) to Sabertooth Controllors
  Serial1.print(170, BYTE);    // Bauding character to set Sabertooth Controllor's baud rate
  // Digital pins
  pinMode (40, OUTPUT);
  pinMode (44, OUTPUT);
  pinMode (46, OUTPUT);
  pinMode (48, OUTPUT);
  pinMode (50, OUTPUT);
  pinMode (52, OUTPUT);  
}

//Turret and Gun Control//
void turret(byte rjoylat, byte rjoyver)
{
  //Gun elevation - Up commands//
  if (rjoyver > 140)
  {                                     
    command3 = gunup;
    elevation = map(elevation, 141, 255, 1, 127);
  } 
  //Gun elevation - Down commands//
  else if (rjoyver < 115)
  {                              
    command3 = gundown;
    elevation = (128 - (map(rjoyver, 1, 115, 1, 127)));
  }
  //Elevation Idle//    
  else
  {                                                    
    command3 = gunup;
    elevation = 0;
  }
  //Turret - right rotation//
  if (rjoylat > 140)
  {                                    
    command4 = rotright;
    rotation = map(rjoylat, 141, 255, 1, 127);
  } 
  //Turret - left rotation//
  else if  (rjoylat < 115)
  {                              
    command4 = rotleft;
    rotation = (128 - (map(rjoylat, 1, 115, 1, 127)));
  }
  //Rotation Idle//
  else
  {                           
    command4 = rotleft;
    rotation = 0;
  }
    sendelevation(command3, elevation);
    sendrotation(command4, rotation);  
}
//Hull control//
void hull(byte ljoyver, byte ljoylat)
{
  //Forward Right Mixed Commands//
  if (ljoyver > 140 && ljoylat < 115)
  {
    command1 = mixedforward;
    command2 = mixedright;
    drive = map(ljoyver, 140, 255, 1, 127);
    steer = (115 - (map(ljoylat, 1, 115, 1, 127)));
  } 
  //Forward Left Mixed Commands//
  else if ((ljoyver > 140) && (ljoylat > 140))
  {   
    command1 = mixedforward;
    command2 = mixedleft;
    drive = map(ljoyver, 141, 255, 1, 127); //Not mapped from 140 as it the minimum would be 141.
    steer = (ljoylat  - 140);
  }
  //Reverse Right Mixed Commands//
  else if ((ljoyver < 115) && (ljoylat < 115))
  {          
    command1 = mixedreverse;
    command2 = mixedright;  
    drive = (128 - (map(ljoyver, 1, 115, 1, 127))); //0 = Stop 128 used to prevent this
    steer = (115 - (map(ljoylat, 1, 115, 1, 127))); //Ditto
  }
  //Reverse Left Mixed Commands//
  else if ((ljoyver < 115) && (ljoylat > 140))
  {         
    command1 = mixedreverse;
    command2 = mixedleft;
    drive = (128 - (map(ljoyver, 1, 115, 1, 127)));
    steer = map(ljoylat, 141, 255, 1, 127);
  }
  //Forward Mixed - Straight//
  else if ((ljoyver > 140) && ((115 <= ljoylat) && (ljoylat <= 140)))
  {   
    command1 = mixedforward;
    command2 = mixedright;
    drive = map(ljoyver, 141, 255, 1, 127);
    steer = 0;
  }
  //Reverse Mixed - Straight//
  else if ((ljoyver < 115) && ((115 <= ljoylat) && (ljoylat <= 140)))
  {   
    command1 = mixedreverse;
    command2 = mixedright;
    drive = (128 - (map(ljoyver, 1, 115, 1, 127)));
    steer = 0;
  } 
  //Full Right Mixed//
  else if (((115 <= ljoyver) && (ljoyver <= 140)) && (ljoylat < 115))
  {   
    command1 = mixedforward;
    command2 = mixedright;
    drive = 0;
    steer = (128 - (map(ljoylat, 1, 115, 1, 127)));
  }  
  //Full Left Mixed//
  else if (((115 <= ljoyver) && (ljoyver <= 140)) && (ljoylat > 140))
  {   
    command1 = mixedreverse;
    command2 = mixedright;
    drive = 0;
    steer = map(ljoylat, 141, 255, 1, 127);
  }
  //Both Motors Idle//
  else   //No conditions required -- all thats left
  {
    command1 = mixedreverse;
    command2 = mixedright;
    drive = 0;
    steer = 0;
  } 
  senddrive(command1, drive, command2, steer);//Should controll the hull sabertooth with two serial packets
}

void senddrive(byte command1, byte drive, byte command2, byte steer) //original
{
  Serial1.print(130, BYTE);      //Address
  Serial1.print(command1, BYTE); //Direction
  Serial1.print(drive, BYTE);    //Rate
  Serial1.print((130 + command1 + drive) & 0b01111111, BYTE); //Required checksum with mask
  Serial1.print(130, BYTE);      //Address
  Serial1.print(command2, BYTE); //Direction
  Serial1.print(steer, BYTE);    //Rate
  Serial1.print((130 + command2 + steer) & 0b01111111, BYTE); //Required checksum with mask 
}

void sendelevation(byte command3, byte elevation) //original
{
  Serial1.print(128, BYTE);
  Serial1.print(command3, BYTE);
  Serial1.print(elevation, BYTE);
  Serial1.print((128 + command3 + elevation) & 0b01111111, BYTE); //Required checksum with mask
}
void sendrotation(byte command4, byte rotation) //original
{
  Serial1.print(128, BYTE);
  Serial1.print(command4, BYTE);
  Serial1.print(rotation, BYTE);
  Serial1.print((128 + command4 + rotation) & 0b01111111, BYTE); //Required checksum with mask
}
//Digital outs
//may change void to byte to accomodate use of digital or analog inputs ie; compass/gyro/acceler etc
//for target tracking or other applications.
void digitalout(byte digdata) 
{
  switch (digdata)
  {
  case dig1://RJ - Right joy button
    digitalWrite(40, HIGH);
    break;
  case dig2://RB - Right B button
    digitalWrite(44, HIGH);
    break;
  case dig3://RA - Right A button
    digitalWrite(46, HIGH);
    break;
  case dig4://LB - Left B button
    digitalWrite(48, HIGH);
    break;
  case dig5://LA - Left A button
    digitalWrite(50, HIGH);
    break;
  case dig6://LJ - Left joy button
    digitalWrite(52, HIGH);
    break;
  default://No buttons pressed this packet.
    digitalWrite(40, LOW);
    digitalWrite(44, LOW);
    digitalWrite(46, LOW);
    digitalWrite(48, LOW);
    digitalWrite(50, LOW);
    digitalWrite(52, LOW);
  }
} 

void loop()
{ 
  while(Serial.available() > 0)
  {
    if(count == -1)
    { // new packet?
      if(Serial.read() == 0xff)
      {
        count = 0;
        checksum = 0;
      }
    }
    else if(count == 0)
    {
      vals[count] = Serial.read();
      if(vals[count] != 0xff)
      {            
        checksum += vals[count];
        count++;
      }
    }
    else
    {
      vals[count] = Serial.read();
      checksum += vals[count];
      count++;
      if(count == 7)
      {// packet complete
        if(checksum%256 != 255)
        {// packet error!
        }
        else
        {//Assign values from array
          digital   = vals[4];
          southpaw  = vals[5];
          digdata   = digital;
          digitalout(digdata);
          if((southpaw) == true)
          {// SouthPaw controlls
            ljoyver = vals[0];
            ljoylat = vals[1];
            rjoyver = vals[2];
            rjoylat = vals[3];
          }
          else
          {
            rjoyver = vals[0];
            rjoylat = vals[1];
            ljoyver = vals[2];
            ljoylat = vals[3];
          } 
        }
        count = -1;
        Serial.flush(); //clear buffer
      }
    } 
    /*
    Serial.print("rjoyver = ");
    Serial.print(int(rjoyver));
    Serial.print(",  rjoylat = ");
    Serial.print(int(rjoylat));
    Serial.print("\n");
    Serial.print("ljoyver = ");
    Serial.print(int(ljoyver));
    Serial.print(",  ljoylat = ");
    Serial.print(int(ljoylat));
    Serial.print("\n");
    Serial.print("digital = ");
    Serial.print(int(digital));
    Serial.print("\n");
   */
    hull(ljoyver, ljoylat);
    turret(rjoyver, rjoylat);  
  }
}

I have left out the setup information at the top of the sketch as it remains the same.

/me

I'm still not sure what your problem is, and I can't see how you have the Sabertooth connected.

Why not write a simple sketch that does no serial communication. Instead, just have a loop run from 0 to 180. In the loop, use servo.write to set the position that the motor should move to, if they are indeed supposed to act like servos (which I have my doubts about).

I'm still not sure what your problem is, and I can't see how you have the Sabertooth connected.

At the top of each sketch I have layed out how the hardware is connected and set up, bar the supplied voltage from a battery and the connections to the two motors, all of which are connected corretly;

Sabertooth Setups
 --Hull--
 Address; 130
 Dip Configuration;
 Dip1 - Down
 Dip2 - Down
 Dip3 - Up
 Dip4 - Up
 Dip5 - Down
 Dip6 - Up
 Single joystick instead of skid steering
 Mixed mode commands - command1, command2

 --Turret--
 Address; 128
 Dip Configuration;
 Dip1 - Down
 Dip2 - Down
 Dip3 - Up
 Dip4 - Up
 Dip5 - Up
 Dip6 - Up
 Standard motor control commands - command3, command4
 Channel 1 - Turret Rotation
 Channel 2 - Gun Elevation

 Arduino MEGA VIN        --   Hull Sabertooth 5V
 Arduino MEGA GND        --   Hull Sabertooth 0V
 Arduino MEGA Serial1    --   Hull and Turret Sabertooth S1 (Serial connection)
 Arduino MEGA I/O pin 54 --   Hull and Turrey Sabertooth S2 (Kill Switch) (Not yet implemented)
 Arduino MEGA Serial     --   Xbee/Xbee and Serial Monitor

Everything is as per the data sheet connection wise.

I have changed the format of the sketch, pulling the guts out of the functions relating to what should be being to the Sabertooth so that these values can be read on the serial monitor.

Sketch - in two parts;

byte  ljoyver, ljoylat;   //Received left joystick readings
byte  rjoylat, rjoyver;   //Received left joystick readings
byte  digital;            //Yet to be used, for determining if buttons have been pressed on controller
int   vals[7];            //Stores received serial bytes
int   checksum   =   0;
byte  southpaw;
int   count      =  -1;
int   voltcount  =   0;
//int   error      =  13;   //Error indication on LED pin 13
//int   badpacket  =   0;   //Counts bad packets
//int   stoppin    =  54;   //Connected to Sabertooth S2 on both controllers - not used on testbed.

//For digital inputs on controller
int   digdata;
const byte dig1  =   1; 
const byte dig2  =   2; 
const byte dig3  =   4; 
const byte dig4  =   8; 
const byte dig5  =  16; 
const byte dig6  =  32; 
//Set Sabertooth minvolts each run
const byte minvolts     =  1; // 6.2Volts (minvolts = (desired volts-6) x 5)
//Hull Sabertooth Motor Command bytes
const byte mixedforward =  8;
const byte mixedreverse =  9;
const byte mixedright   = 10;
const byte mixedleft    = 11;
//Turret Sabertooth Motor Command bytes
const byte rotleft      =  0;
const byte rotright     =  1;
const byte gunup        =  4;
const byte gundown      =  5;
//Commands returned from function hull() and turret().
byte  command1, command2, command3, command4;
byte  drive, steer, rotation, elevation;

void setup() 
{
  //digitalWrite(stoppin, HIGH); //If brought low shuts down Saberteeth
  Serial.begin(38400);
  Serial1.begin(38400);        // start serial port controlling Sabertooth Controllers
  delay(2000);                 // Required 2000 delay before sending 170(byte) to Sabertooth Controllors
  Serial1.print(170, BYTE);    // Bauding character to set Sabertooth Controllor's baud rate
  delay(10);

  // Digital pins
  pinMode (40, OUTPUT);
  pinMode (44, OUTPUT);
  pinMode (46, OUTPUT);
  pinMode (48, OUTPUT);
  pinMode (50, OUTPUT);
  pinMode (52, OUTPUT);  
}

//Digital outs
//may change void to byte to accomodate use of digital or analog inputs ie; compass/gyro/acceler etc
//for target tracking or other applications.
void digitalout(byte digdata) 
{
  switch (digdata)
  {
  case dig1://RJ - Right joy button
    digitalWrite(40, HIGH);
    break;
  case dig2://RB - Right B button
    digitalWrite(44, HIGH);
    break;
  case dig3://RA - Right A button
    digitalWrite(46, HIGH);
    break;
  case dig4://LB - Left B button
    digitalWrite(48, HIGH);
    break;
  case dig5://LA - Left A button
    digitalWrite(50, HIGH);
    break;
  case dig6://LJ - Left joy button
    digitalWrite(52, HIGH);
    break;
  default://No buttons pressed this packet.
    digitalWrite(40, LOW);
    digitalWrite(44, LOW);
    digitalWrite(46, LOW);
    digitalWrite(48, LOW);
    digitalWrite(50, LOW);
    digitalWrite(52, LOW);
  }
} 

void loop()
{ 
  if(voltcount == 0)// True only once
  {
    Serial1.print(130, BYTE);      //Address
    Serial1.print(2, BYTE);        //Min Voltage Command
    Serial1.print(minvolts, BYTE); //Min Voltage
    Serial1.print((132 + minvolts) & 0b01111111, BYTE); //Required checksum with mask
    delay(10);
    Serial1.print(128, BYTE);
    Serial1.print(2, BYTE);
    Serial1.print(minvolts, BYTE);
    Serial1.print((130 + minvolts) & 0b01111111, BYTE);
    voltcount++;
  }
  while(Serial.available() > 0)
  {
    if(count == -1)
    { // new packet?
      if(Serial.read() == 0xff)
      {
        count = 0;
        checksum = 0;
      }
    }
    else if(count == 0)
    {
      vals[count] = Serial.read();
      if(vals[count] != 0xff)
      {            
        checksum += vals[count];
        count++;
      }
    }
    else
    {
      vals[count] = Serial.read();
      checksum += vals[count];
      count++;
      if(count == 7)
      {// packet complete
        if(checksum%256 != 255)
        {// packet error!
        }
        else
        {//Assign values from array
          digital   = vals[4];
          southpaw  = vals[5];
          digdata   = digital;
          digitalout(digdata);
          if((southpaw) == true)
          {// SouthPaw controlls
            ljoyver = vals[0];
            ljoylat = vals[1];
            rjoyver = vals[2];
            rjoylat = vals[3];
          }
          else
          {
            rjoyver = vals[0];
            rjoylat = vals[1];
            ljoyver = vals[2];
            ljoylat = vals[3];
          } 
        }
        count = -1;
        Serial.flush(); //clear buffer
      }
    } 
    
    Serial.print("rjoyver = ");
     Serial.print(int(rjoyver));
     Serial.print(",  rjoylat = ");
     Serial.print(int(rjoylat));
     Serial.print("\n");
     Serial.print("ljoyver = ");
     Serial.print(int(ljoyver));
     Serial.print(",  ljoylat = ");
     Serial.print(int(ljoylat));
     Serial.print("\n");
     Serial.print("digital = ");
     Serial.print(int(digital));
     Serial.print("\n");
     
    //Forward Right Mixed Commands//
    if (ljoyver > 140 && ljoylat < 115)
    {
      command1 = mixedforward;
      command2 = mixedright;
      drive = map(ljoyver, 140, 255, 1, 127);
      steer = (115 - (map(ljoylat, 1, 115, 1, 127)));
    } 
    //Forward Left Mixed Commands//
    else if ((ljoyver > 140) && (ljoylat > 140))
    {   
      command1 = mixedforward;
      command2 = mixedleft;
      drive = map(ljoyver, 141, 255, 1, 127); //Not mapped from 140 as it the minimum would be 141.
      steer = (ljoylat  - 140);
    }
    //Reverse Right Mixed Commands//
    else if ((ljoyver < 115) && (ljoylat < 115))
    {          
      command1 = mixedreverse;
      command2 = mixedright;  
      drive = (128 - (map(ljoyver, 1, 115, 1, 127))); //0 = Stop 128 used to prevent this
      steer = (115 - (map(ljoylat, 1, 115, 1, 127))); //Ditto
    }
    //Reverse Left Mixed Commands//
    else if ((ljoyver < 115) && (ljoylat > 140))
    {         
      command1 = mixedreverse;
      command2 = mixedleft;
      drive = (128 - (map(ljoyver, 1, 115, 1, 127)));
      steer = map(ljoylat, 141, 255, 1, 127);
    }
    //Forward Mixed - Straight//
    else if ((ljoyver > 140) && ((115 <= ljoylat) && (ljoylat <= 140)))
    {   
      command1 = mixedforward;
      command2 = mixedright;
      drive = map(ljoyver, 141, 255, 1, 127);
      steer = 0;
    }
    //Reverse Mixed - Straight//
    else if ((ljoyver < 115) && ((115 <= ljoylat) && (ljoylat <= 140)))
    {   
      command1 = mixedreverse;
      command2 = mixedright;
      drive = (128 - (map(ljoyver, 1, 115, 1, 127)));
      steer = 0;
    } 
    //Full Right Mixed//
    else if (((115 <= ljoyver) && (ljoyver <= 140)) && (ljoylat < 115))
    {   
      command1 = mixedforward;
      command2 = mixedright;
      drive = 0;
      steer = (128 - (map(ljoylat, 1, 115, 1, 127)));
    }  
    //Full Left Mixed//
    else if (((115 <= ljoyver) && (ljoyver <= 140)) && (ljoylat > 140))
    {   
      command1 = mixedreverse;
      command2 = mixedright;
      drive = 0;
      steer = map(ljoylat, 141, 255, 1, 127);
    }
    //Both Motors Idle//
    else   //No conditions required -- all thats left
    {
      command1 = mixedreverse;
      command2 = mixedright;
      drive = 0;
      steer = 0;
    }
    //Gun elevation - Up commands//
    if (rjoyver > 140)
    {                                     
      command3 = gunup;
      elevation = map(elevation, 141, 255, 1, 127);
    } 
    //Gun elevation - Down commands//
    else if (rjoyver < 115)
    {                              
      command3 = gundown;
      elevation = (128 - (map(rjoyver, 1, 115, 1, 127)));
    }
    //Elevation Idle//    
    else
    {                                                    
      command3 = gunup;
      elevation = 0;
    }
    //Turret - right rotation//
    if (rjoylat > 140)
    {                                    
      command4 = rotright;
      rotation = map(rjoylat, 141, 255, 1, 127);
    } 
    //Turret - left rotation//
    else if  (rjoylat < 115)
    {                              
      command4 = rotleft;
      rotation = (128 - (map(rjoylat, 1, 115, 1, 127)));
    }
    //Rotation Idle//
    else
    {                           
      command4 = rotleft;
      rotation = 0;
    }
    //For debug
    Serial.print("command1 = ");
    Serial.print(int(command1));
    Serial.print(", drive = ");
    Serial.print(int(drive));
    Serial.print("\n");
    Serial.print("command2 = ");
    Serial.print(int(command2));
    Serial.print(", steer = ");
    Serial.print(int(steer));
    Serial.print("\n");
    Serial.print("command3 = ");
    Serial.print(int(command3));
    Serial.print(", elevation = ");
    Serial.print(int(elevation));
    Serial.print("\n");
    Serial.print("command4 = ");
    Serial.print(int(command4));
    Serial.print(", rotation = ");
    Serial.print(int(rotation));
    Serial.print("\n");

The remaining section of the sketch;

Serial1.print(130, BYTE);       //Address
    Serial1.print(command1, BYTE);  //Direction
    Serial1.print(drive, BYTE);     //Rate
    Serial1.print((130 + command1 + drive) & 0b01111111, BYTE); //Required checksum with mask
    Serial1.print(130, BYTE);       //Address
    Serial1.print(command2, BYTE);  //Direction
    Serial1.print(steer, BYTE);     //Rate
    Serial1.print((130 + command2 + steer) & 0b01111111, BYTE); //Required checksum with mask 
    Serial1.print(128, BYTE);       //Address
    Serial1.print(command3, BYTE);  //Direction
    Serial1.print(elevation, BYTE); //Rate
    Serial1.print((128 + command3 + elevation) & 0b01111111, BYTE); //Required checksum with mask
    Serial1.print(128, BYTE);       //Address
    Serial1.print(command4, BYTE);  //Direction
    Serial1.print(rotation, BYTE);  //Rate
    Serial1.print((128 + command4 + rotation) & 0b01111111, BYTE); //Required checksum with mask
  }
}

And what do I know.... it now works albeit the steering is reversed and the control is clunky (updates seem to be a little delayed)...

PaulS, thanks for the assistance, now I need to work out where I was going wrong when using the functions. Do you know if they will have much of an effect on the responsiveness to the changes from the transmitter side of things?

Again thanks, I best be off to bed now, almost 1am with a 5am start tomorrow, one pro when I'm away working is that the office is home too! But the cons... I wont start, thanks!! /me

Ferret, Your code looks great! I have been working on something similar arduino + 2x25 sabertooth + snowblower. The turret an hull controls are very interesting to me. I will need to change direction of the chute. So far I can make it go forward and stop via usb. I would like to see more out there on sabertooth! Good luck.

All right. I want to see a video of an Arduino powered snow blower.