Controlling Sabertooth 2x60A with PS3 Controller

Hi everybody,

This is my first post here. I have read a lot here and can learn a lot her, but I did not find a solution
here for my problem. I tried I guess hundreds of things but now I am totally confused…

I want to control two Scooter Motors 24V / 250 each with rated 11.5 A (Unite Motor MY1016) with
a PS3 Controller and a Sabertooth 2 x 60A Motor Controller.

I just can’t get the two Motors running Forward and Backward properly. I guess I have a problem
to understand the mapping. I get Response with the code below but it is not going smooth
forward and backward, it is more a mix of going fast Revers when pushing the Y-Axis to the front
smoothly and then when I push more it goes slowly Forward. I tried many many combinations
but, I don’t know…

Before I bought the Sabertooth I had the Motors running with two H-Bridges, one for each Motor.
I could control them perfectly. The difference is that these H-Bridges hat PWM and PHASE pins,
so quiet easy to control.

On the Sabertooth I did the DIP-Switch settings: 1, 4 and 5 off and the rest on.
I am using the Arduino Uno. I connected the Sabertooth GND with the Arduino GND,
Arduino Pin 3 with Sabertooth S1 and Arduino Pin 5 with the Sabertooth S2.
The Arduino is powered by USB at the Moment, the Motors are powered by a 12V / 24 AH
battery. I also installed a R/C filter with a 10K resistor and a 0,1 uF on both lines.

I already contacted Dimension Engineering with my problem but they could not help me
as they did not have the case before that someone is using a Playstation 3 Controller with their
Sabertooth 2x60.

Maybe I can get a bit of help here as I really do not know what else I should try.

Here is the code that worked with my two H-Bridges and below what I tried with the Sabertooth:

/*
 This is a modified version of the PS3BT.ino example sketch by Kristian Lauszus
 For more information visit his blog: http://blog.tkjelectronics.dk/ or 
 send him an e-mail:  kristianl@tkjelectronics.com
 */

#include <PS3BT.h>   

USB Usb;
BTD Btd(&Usb);
PS3BT PS3(&Btd); 


//H-Bridge 1
int mleftpwm = 3;
int mleftphase = 4;
int mleftreset = 2;

//H-Bridge 2
int mrightpwm = 5;
int mrightphase = 6;
int mrightreset = 8;


int j = 0;
int k = 0;


void setup() {


  digitalWrite(mleftreset, HIGH); //Reset pin von H-Brücke links muss High sein
  delay(200);
  digitalWrite(mrightreset, HIGH); //Reset pin von H-Brück rechts muss High sein
  delay(200);


  Serial.begin(115200);
  while (!Serial); // Wait for serial port to connect   
  if (Usb.Init() == -1) {                                            
    Serial.print(F("\r\nOSC did not start"));
    while(1); //halt
  }

  Serial.print(F("\r\nPS3 Bluetooth Library Started"));  

}
void loop() {


  Usb.Task(); 
  {

    if(PS3.PS3Connected || PS3.PS3NavigationConnected) {
      int Ly =(map(PS3.getAnalogHat(LeftHatY),0,255,0,1023));
      int Ry =(map(PS3.getAnalogHat(RightHatY),0,255,0,1023));
      Serial.print(F("\r\nLy: "));
      Serial.print(PS3.getAnalogHat(LeftHatY));
      Serial.print(F("\tRy: "));
      Serial.print(PS3.getAnalogHat(RightHatY));

      //Left Joystick Y-Axis

      j=Ly -517; //0-Point / Center Y-Axis
      j=abs(j);  
      if(j>=600){
        j=250;//PWM Reverse
      }
      if(j<=150&&j>10){
        j=250;//PWM Forward
      }
      if(j<=10){
        j=0; // Below 10 Y-Axis is at 0-Point
      }

      if
        (Ly >=630 ){
        digitalWrite(mleftphase, LOW); // H-Bridge left motor LOW, Reverse
        analogWrite(mleftpwm,j/2);//PWM Speed /2
        Serial.print(F("\r\nLy: "));
        Serial.print(PS3.getAnalogHat(LeftHatY));
      }

      if
        (Ly <=450 ){
        digitalWrite(mleftphase, HIGH); // H-Bridge left Motor HIGH, Forward
        analogWrite(mleftpwm,j/2);//PWM Speed /2
        Serial.print(F("\r\nLy: "));
        Serial.print(PS3.getAnalogHat(LeftHatY)); 
      }

      // Right Joystick Y-Axis

      k=Ry -517;  //0-Point 
      k=abs(k);
      if(k>=600){
        k=300; //PWM Reverse
      }
      if(k<=150&&k>=10){
        k=300;//PWM Forward

        if(k<=10){
          k=0; // Below 10 Y-Axis is at 0-Point
        }

        if
          (Ry >=630 ){
          digitalWrite(mrightphase, HIGH); // H-Bridge left motor HIGH, Reverse  
          analogWrite(mrightpwm,k/2); //PWM Speed /2
          Serial.print(F("\tRy: "));
          Serial.print(PS3.getAnalogHat(RightHatY));
        }

        if
          (Ry <=450 ){
          digitalWrite(mrightphase, LOW); // H-Brücke LOW, FORWARD
          analogWrite(mrightpwm,k/2); //PWM Speed /2
          Serial.print(F("\tRy: "));
          Serial.print(PS3.getAnalogHat(RightHatY));
        }

        //Both Axis at 0-Point / Center

        if((Ly <=580&&Ly>=450)&&(Ry<=580&&Ry>=450)){
          analogWrite(mleftpwm,0);
          analogWrite(mrightpwm,0);
          Serial.print(F("\r\nLy: "));
          Serial.print(PS3.getAnalogHat(LeftHatY)); 
          Serial.print(F("\tRy: "));
          Serial.print(PS3.getAnalogHat(RightHatY));
        }

        if(PS3.getButtonClick(PS)){
          analogWrite(mleftpwm,0);
          analogWrite(mrightpwm,0);
          PS3.disconnect(); //BT OFF
          Serial.print(F("\r\nLy: "));
          Serial.print(PS3.getAnalogHat(LeftHatY)); 
          Serial.print(F("\tRy: "));
          Serial.print(PS3.getAnalogHat(RightHatY));
          Serial.print(F("\r\nMotors STOPPED")); 
        }
        if(PS3.getButtonClick(CROSS)){
          analogWrite(mleftpwm,0);
          analogWrite(mrightpwm,0);
          PS3.disconnect(); //BT OFF
          Serial.print(F("\r\nLy: "));
          Serial.print(PS3.getAnalogHat(LeftHatY)); 
          Serial.print(F("\tRy: "));
          Serial.print(PS3.getAnalogHat(RightHatY));
          Serial.print(F("\r\nMotors STOPPED"));

        }
      }
    }
  }
}

And here what I tried last with the Sabertooth:

/*
 This is a modified version of the PS3BT.ino example sketch by Kristian Lauszus
 For more information visit his blog: http://blog.tkjelectronics.dk/ or 
 send him an e-mail:  kristianl@tkjelectronics.com
 */

//Sabertooth Dip-switch settings  1,4,5 OFF and 2,3,6 ON 

#include <PS3BT.h>    
#include <Servo.h>

USB Usb;
BTD Btd(&Usb);
PS3BT PS3(&Btd); 


Servo motorlinks;
Servo motorrechts;


void setup() {


  motorlinks.attach(3);
  motorrechts.attach(5);

  motorlinks.write(0);
  motorrechts.write(0);


  Serial.begin(115200);
  while (!Serial); // Wait for serial port to connect   
  if (Usb.Init() == -1) {                                            
    Serial.print(F("\r\nOSC did not start"));
    while(1); //halt
  }

  Serial.print(F("\r\nPS3 Bluetooth Library Started"));  

}
void loop() {


  Usb.Task(); 
  {

    if(PS3.PS3Connected || PS3.PS3NavigationConnected) {
      Serial.print(F("\r\nLy: "));
      Serial.print(PS3.getAnalogHat(LeftHatY));
      Serial.print(F("\tRy: "));
      Serial.print(PS3.getAnalogHat(RightHatY));
      motorlinks.write(0);
      motorrechts.write(0);

      //Left Joystick Y-Axis

    }

    if
      (PS3.getAnalogHat(LeftHatY)>=135){
      motorlinks.write(map(PS3.getAnalogHat(LeftHatY), 30, 160, 80,50)); //Reverse

    }
    if
      (PS3.getAnalogHat(LeftHatY)<=117){
      motorlinks.write(map(PS3.getAnalogHat(LeftHatY),140, 70,70,95));   //Forward

    }

    //Right Joystick Y-Axis
    
    if
      (PS3.getAnalogHat(RightHatY)>=135){
      motorrechts.write(map(PS3.getAnalogHat(RightHatY),80, 160, 50,50)); //Reverse

    }
    if
      (PS3.getAnalogHat(RightHatY)<=117){
      motorrechts.write(map(PS3.getAnalogHat(RightHatY),50,40,70,95));   //Forward

    }
  }
}

Thanks in advance for any help I can get…

Patrick

After trying some other codes but with no satisfiying response on this combination I give up hope
with the PS3 Controller and Sabertooth combination and gonna buy me a RC Transmitter/Receiver
as the setup is much easier with this combination.

I will use the PS3 Controller with my other H-Bridges and build up a small racer for my kids.

Thanks anyway for having interest in reading this topic and I will keep an eye if anyone else
is trying it in the future, just for my interest.

Regards,
Patrick

Those drivers are pretty good.

You have to be sure to set the ‘dip switches’ correctly.

It looks like your code is trying to send the control via a PWM. what happens if you throw it into the serial mode and set the “lock the two motors together” mode…

Just throwing it out there.

I’ve used it’s little brother (the 20a) model and it works better in the serial mode.

one project I did… the motors had a stupid high start up current and I needed to put a little ceramic cap across the motor (a starting capacitor).

Thanks for your answer.
As I am waiting for my RC Transm./Rec. to arrive I am of course interested how it works with the
PS3 Controller.
I tried your suggestion with Serial mode but I couldn't make it. The Dim. Eng. examples are running
good but I don't know how to include this in the PS3BT Code to get a smooth acceleration and not
a stop and go thing with what I tried then.
I am obviously too much a beginner to understand how all the modes work with the Sabertooth Controllers,
it is yet too confusing to me.

So in Serial mode I set the DIP Switch 2 and 4 down for 9600 Baud.
Motor1: 1 is full reverse, 64 stop and 127 full Forward.
Motor2: 128 full reverse, 192 stop and 255 full Forward.

This is how I understood it when I read the DE Manual.

But how can I tell him to accelerate more while pushing the left or right hand Y axis harder and
vice versa ?

This is what I mean I don't understand how to map it.

Are you using any type of encoders on those motors?

Without encoders it's almost impossible to synchronize two motors, so you won't be able to go really "forward" or "backward".