Logo

Forums » Lawnbot400 » Sabertooth code

basspro30
Avatar
I got my sabertooth x60 yesterday and hooked it up to 2 small hobby dc motors to do a mini test of receiver/transmitter with your sabertooth code. At first the motors stayed on. I changed dip switch settings. Still had same issue. So iI removed arduino and just hooked the receiver up to motor controller. Forward and reverse worked perfectly. I don't know what I did wrong. Probably some little thing I am over looking. Did you have any issues with the sabertooth code? It seems like the motor controller isn't sensing a good pwm signal. Everything in serial monitor gave me a response for fwd(1900)/rev(1100). Neutral 1500. Can you please help?
johndavid400
Avatar
sure thing, can you post a link to the code you are using? I will also look up the product description for the 2x60 controller.
basspro30
Avatar
I used your sabertooth code from your chapter 10 link that you provided in your book.
johndavid400
Avatar

I see the problem... that code is for use with the Analog mode on the Sabertooth, but I'm guessing you had it configured for R/C mode. R/C mode uses pulse position modulation to send the speed value using the length of the pulse (a pulse with a length of between 600-2400 microseconds, where 1500uS is neutral), while the Analog mode uses a PWM signal (a simulated 0-5v signal with 2.5v as neutral) to control the speed and direction of the motor.

But I no longer use the Arduino to decode the radio signals that control the motors. I connect those directly to the Sabertooth. The Arduino is now used to decode at least one of the R/C signals from the receiver, to control a safety cutoff switch.

I use a 12v automotive relay rated for 60amps to control the power to the Sabertooth, which allows me to use the toggle switch on my R/C transmitter to remotely disable the motors on my mower, which I feel is an essential feature on your lawnbot. Follow the link below to download the code for the safety switch and other accessories:

https://sites.google.com/site/arduinorobotics/home/chapter10_/lawnbot400_failsafe_accessories.pde?attredirects=0&d=1

basspro30
Avatar

Thank you sooo much. Putting it in analog mode worked but now it is jittery when in neutral postition. I looked at serial monitor and noticed the neutral value 1500 keeps changing. Sometimes it will jump as low as 830. Do I need to mess with the values in the sabertooth code?

// You can adjust these values to calibrate the code to your specific radio - check the Serial Monitor to see your values.
int low1 = 1100;
int high1 = 1900;
int low2 = 1100;
int high2 = 1900;

and do I need to change these values too?

  if (servo1_Ready) {  

    // channel 1
    adj_val1 = map(servo1_val, low1, high1, 0, 255);
    adj_val1 = constrain(adj_val1, 0, 255);

    if (adj_val1 > 255) {
      adj_val1 = 255;
    }
    if (adj_val1 < 0) {
      adj_val1 = 0;
    }

    analogWrite(motor1, adj_val1);

    if (adj_val1 > 124 && adj_val1 < 132){
      digitalWrite(ledPin1, HIGH);
    }
    else{
      digitalWrite(ledPin1, LOW);
    }

  }

  if (servo2_Ready) {

    // channel 2
    adj_val2 = map(servo2_val, low2, high2, 0, 255);
    adj_val2 = constrain(adj_val2, 0, 255);

    if (adj_val2 > 255) {
      adj_val2 = 255;
    }
    if (adj_val2 < 0) {
      adj_val2 = 0;
    }

    analogWrite(motor2, adj_val2);      

    if (adj_val2 > 124 && adj_val2 < 132){
      digitalWrite(ledPin2, HIGH);
    }
    else{
      digitalWrite(ledPin2, LOW);
    }

  }

johndavid400
Avatar

You should edit the High and Low values for the R/C if when reading them on the Serial montior, they are much different from those listed in the code:

// You can adjust these values to calibrate the code to your specific radio - check the Serial Monitor to see your values.
int low1 = 1100;
int high1 = 1900;
int low2 = 1100;
int high2 = 1900;

I had one radio that would only go up to 1850 or so, and I changed it from 1900 to 1850.... but if your radio goes up slightly higher than 1900 or slightly lower than 1100, I would leave them alone.

And no, you shouldn't have to change the other values if your High and Low values are correct.

As far as the jittery behavior, you should probably use an R/C (resistor capacitor) filter on the PWM output of the Arduino to keep it from sending erroneous values. To do this, you will need a resistor and a capacitor like so:

 

You need to do this because the PWM output from the Arduino switches on and off really fast, which is fine if controlling a motor. Reading PWM as an analog voltage from another microcontroller (like the Sabertooth) can cause problems because the microcontroller reading the PWM can read it too precisely - to remedy this, the capacitor serves to even out the switching signal and keep it at a nominal voltage that can be read by the Sabertooth. There is more information about this in the Sabertooth 2x25 owners manual, but basically you put a 10k resistor in line (series) with the PWM output to the Sabertooth, and a 0.1uF capacitor from the PWM output to GND on your Arduino.