Go Down

Topic: Sabertooth Analog mode (Read 2394 times) previous topic - next topic

dxw00d

Well no. I can't either, but each to their own.

AWOL

#16
May 08, 2012, 09:21 pm Last Edit: May 09, 2012, 08:55 am by AWOL Reason: 1
@OP
Your sketch is too long and rambling.
You've been asked to implement arrays and functions to simplify and shorten it.
You've been asked to add debug prints; you're the one with the hardware and you need some observations to figure out what it is doing.
You've been asked to remove useless code and useless comments; they just add to the noise.

And please, please, drop the txt and start using the shift key.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

simonfrfr

Ironically I had the same problem,  because I have the sabertooth too. I figured mine out. First set all of the DIP switches to the OFF position, then arduino code time. Servo.write(120); is backwards (in my case), Servo.writeMicroseconds(1200); is forwards (in my case). Now you have independent control of each motor. This has nothing to do with how far it has gone, so in that case, you would have to get encoders or optical interrupters. I hope to be building an AI/pathfinding robot using this speed controller (2x12). You can adjust the speed accordingly. Oh and by the way I have a serial sample code for you where you can test out the different frequencies

Code: [Select]

// If you need any help feel free to PM me (simonfrfr) or email me
// at newtonlabs@bellsouth.net
String readString;
#include <Servo.h>
Servo myservo;  // create servo object to control a servo
Servo myservo2; // create second servo object
const int left = 10; // left motor's pin on arduino
const int right = 9; // right motor's pin on arduino
void setup() {
  Serial.begin(9600);
  Serial.println("servo-test-22-dual-input"); // so I can keep track of what is loaded
}

void loop() {
  while (Serial.available()) {
    char c = Serial.read();  //gets one byte from serial buffer
    readString += c; //makes the string readString
    delay(2);  //slow looping to allow buffer to fill with next character
  }

  if (readString.length() >0) {
    Serial.println(readString);  //so you can see the captured string
    if (readString == "l") // acfivates left servo only
    {
      myservo.attach(left); // writing both to left motor
      myservo2.attach(left);
    }
        if (readString == "r") // activates right servo only
    {
      myservo.attach(right); // writing both to left motor
      myservo2.attach(right);
    }
        if (readString == "b") // activates both motors
    {
      myservo.attach(left); // writing to left motor
      myservo2.attach(right); // writing to right motor
    }
    int n = readString.toInt();  //convert readString into a number

    // auto select appropriate value, copied from someone elses code.
    if(n >= 500)
    {
      Serial.print("writing Microseconds: "); // serial display
      Serial.println(n); // number
      myservo.writeMicroseconds(n); // writes to ports
      myservo2.writeMicroseconds(n);
    }
    else
    {   
      Serial.print("writing Angle: "); // serial display
      Serial.println(n); // number
      myservo.write(n); // writes to ports
      myservo2.write(n);
    }

    readString=""; //empty for next input
  }
}

simonfrfr

PS: forgot to tell you, that is only for one.

Go Up