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