Pages: [1] 2   Go Down
Author Topic: Sabertooth Analog mode  (Read 2047 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 26
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello guys,,
Im using two Sabertooth Dual 25A motor controllers to control 4 DC motors:

and my S1 and S2 pins are going to PWM in arduino , so that i can write analog data to Sabertooth

now ive used the standard servo method in writing the code which is:

Code:
#include <Servo.h>

Servo M1;
Servo M2;
Servo M3;
Servo M4;

int angle = 0;
Void setup()
{
M1.attach(5,1000,2000);  // attaches the servo M1 on pin 5 to the servo object.
M2.attach(9,1000,2000);  // attaches the servo M2 on pin 9 to the servo object.
M3.attach(10,1000,2000); // attaches the servo M3 on pin 10 to the servo object.
M4.attach(11,1000,2000); // attaches the servo M4 on pin 11 to the servo object.
}


void loop()
{
for(angle = 0; angle < 180; angle += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
M1.write(angle); // tell servo to go to position in variable 'angle'
M3.write(angle);
delay(20); // waits 20ms between servo commands
}
for(angle = 180; angle >= 1; angle -= 1) // goes from 180 degrees to 0 degrees
{
M1.write(angle); // tell servo to go to position in variable 'pos'
M3.write(angle);
delay(20); // waits 20ms between servo commands
}

now im not sure whether this will give the right speed to the motors or not,,
first of all is this good to be used on analog mode??
and secondly how do i put this in any desired speed i want?

I ve read sabertooth user's manual and the only thing that it says abt this is that this mode operates between 0 and 5V
in which 0v is full reverse, 2.5 gives zero speed and 5v if full forward motion..

so if the angle i used above (ie 180degrees) is correct how will it correspond to this voltage???

thank you
« Last Edit: May 05, 2012, 10:35:07 pm by hesham2012 » Logged

Greenville, IL
Offline Offline
Edison Member
*
Karma: 15
Posts: 1330
Warning Novice on board! 0 to 1 chance of errors!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


  You might want to provide the link for the Savertooth.

 Also you might want to look over this thread to see if it is helpful. http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1281909517/all
Logged


Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 631
Posts: 50179
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You might also want to see if the code compiles before you waste time posting it. Yours won't.

Since you can't even compile that code, clearly you didn't try it out to see if it does anything. So, you can't tell us what that code does, or what you expect it to do, and, if those two things are different, what the difference is.

All in all, a waste of time.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 26
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Cyclegadget the link for sabertooth is:
http://www.dimensionengineering.com/datasheets/Sabertooth2x25.pdf

and i've already checked the link u provided before i wrote my original post

and

Pauls
the code i posted is just the section that deals with the motors and my questions was just specific to the voltage and speed and not anything else,
and btw my original code does work , y would waste anyones time, i ve already compiled it and it works,

waiting for your help guys
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 631
Posts: 50179
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
the code i posted is just the section that deals with the motors and my questions was just specific to the voltage and speed and not anything else,
and btw my original code does work , y would waste anyones time, i ve already compiled it and it works,
Code:
Void setup()
{
M1.attach(5,1000,2000);  // attaches the servo M1 on pin 5 to the servo object.
M2.attach(9,1000,2000);  // attaches the servo M2 on pin 9 to the servo object.
M3.attach(10,1000,2000); // attaches the servo M3 on pin 10 to the servo object.
M4.attach(11,1000,2000); // attaches the servo M4 on pin 11 to the servo object.
}
Void with a capital V is not valid syntax. That code will NOT compile.

Why did you waste everyone's time with code that does not compile? Post your real code!
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 26
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

OMG ok pauls i will post the real code , here

Code:
int ultrasoundsignalpin1 = 0; //6ultrasound signla pins
int ultrasoundsignalpin2 = 1; //6ultrasound signla pins
int ultrasoundsignalpin3 = 2; //6ultrasound signla pins
int ultrasoundsignalpin4 = 3; //6ultrasound signla pins
int ultrasoundsignalpin5 = 4; //6ultrasound signla pins
int ultrasoundsignalpin6 = 5; //6ultrasound signla pins

int ultrasoundtriggerpin=6; // rx pin, the trigger pin

float sensor1=0;
float sensor2=0;
float sensor3=0;
float sensor4=0;
float sensor5=0;
float sensor6=0;

//char *sensorstring[]={"Right: " , "  frontright: " , "  front 2: " , "  front 1: " , "  frontleft: " , "  Left: "};// (NOT NESSECARY)

#include <Servo.h>

Servo M1;
Servo M2;
Servo M3;
Servo M4;

int angle = 0;

void setup()


Serial.begin(9600);
     
pinMode(ultrasoundsignalpin1,INPUT);//set ultrasoundsignalpins as input
pinMode(ultrasoundsignalpin2,INPUT);
pinMode(ultrasoundsignalpin3,INPUT);
pinMode(ultrasoundsignalpin4,INPUT);
pinMode(ultrasoundsignalpin5,INPUT);
pinMode(ultrasoundsignalpin6,INPUT);
   
  pinMode(ultrasoundtriggerpin,OUTPUT);//set rx pin as output
  delay(250);// time to boot up
 
digitalWrite(ultrasoundtriggerpin, HIGH);//send rx pin high for at least 20microsecs
delayMicroseconds(20);
digitalWrite(ultrasoundtriggerpin, LOW);
pinMode(ultrasoundtriggerpin, INPUT);
delay(1000);
delay(20000);
M1.attach(5,1000,2000);  // attaches the servo M1 on pin 5 to the servo object.
M2.attach(9,1000,2000);  // attaches the servo M2 on pin 9 to the servo object.
M3.attach(10,1000,2000); // attaches the servo M3 on pin 10 to the servo object.
M4.attach(11,1000,2000); // attaches the servo M4 on pin 11 to the servo object.

 }
 


void loop()
{
                        sensorsread:
                        float sensor1 = analogRead(ultrasoundsignalpin1) * (254.0/1024.0) * 2.54;
                        delay(50);
                        float sensor2 = analogRead(ultrasoundsignalpin2) * (254.0/1024.0) * 2.54;
                        delay(50);
                        float sensor3 = analogRead(ultrasoundsignalpin3) * (254.0/1024.0) * 2.54;
                        delay(50);
                        float sensor4 = analogRead(ultrasoundsignalpin4) * (254.0/1024.0) * 2.54;
                        delay(50);
          float sensor5 = analogRead(ultrasoundsignalpin5) * (254.0/1024.0) * 2.54;
                        delay(50);
          float sensor6 = analogRead(ultrasoundsignalpin6) * (254.0/1024.0) * 2.54;
                       
                       
                            if (sensor1 < 50 && sensor2 > 50 && sensor3 > 50 && sensor4 > 50 && sensor5 > 50 && sensor6 > 50 )
                            {
                             motors1and3();
                             motors1and3();
                                    float sensor1 = analogRead(ultrasoundsignalpin1) * (254.0/1024.0) * 2.54;
                                    delay(50);
                                    float sensor2 = analogRead(ultrasoundsignalpin2) * (254.0/1024.0) * 2.54;
                                    delay(50);
                                    float sensor3 = analogRead(ultrasoundsignalpin3) * (254.0/1024.0) * 2.54;
                                    delay(50);
                                    float sensor4 = analogRead(ultrasoundsignalpin4) * (254.0/1024.0) * 2.54;
                                    delay(50);
                      float sensor5 = analogRead(ultrasoundsignalpin5) * (254.0/1024.0) * 2.54;
                                    delay(50);
                      float sensor6 = analogRead(ultrasoundsignalpin6) * (254.0/1024.0) * 2.54;
                                         if (sensor1 < 50 && sensor2 > 50 && sensor3 > 50 && sensor4 > 50 && sensor5 > 50 && sensor6 > 50)
                                         {
                                         motors1and3();
                                         motors1and3();
                                         goto sensorsread;
                                         }
                                         else
                                         {
                                         motors2and4();                         
                                         motors2and4(); 
                                         goto sensorsread;
                                         }
                            }
                           
                           
                           
                           
         
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
                           
}

                         
                         
                       




void motors1and3()
{

for(angle = 0; angle < 180; angle += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
M1.write(angle); // tell servo to go to position in variable 'angle'
M3.write(angle);
delay(20); // waits 20ms between servo commands
}
for(angle = 180; angle >= 1; angle -= 1) // goes from 180 degrees to 0 degrees
{
M1.write(angle); // tell servo to go to position in variable 'pos'
M3.write(angle);
delay(20); // waits 20ms between servo commands
}
}


void motors2and4()
{

for(angle = 0; angle < 180; angle += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
M2.write(angle); // tell servo to go to position in variable 'angle'
M4.write(angle);
delay(20); // waits 20ms between servo commands
}
for(angle = 180; angle >= 1; angle -= 1) // goes from 180 degrees to 0 degrees
{
M2.write(angle); // tell servo to go to position in variable 'pos'
M4.write(angle);
delay(20); // waits 20ms between servo commands
}
}
                       
void reverse()
{
M2.write(0); // tell servo to go to position in variable 'angle'
M4.write(0);
M1.write(0); // tell servo to go to position in variable 'pos'
M3.write(0);
delay(20); // waits 20ms between servo commands
}
                     
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 631
Posts: 50179
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Some suggestions. Learn to use the Tools + Auto Format menu option. There is no excuse for code jumping half way across the page.

Judicious use of blank lines makes the code more readable. All those blank lines you have do not.

The label and goto statements are useless. Get rid of them.

Arrays are useful to collect related data, like ultrasound pin numbers. Then, for loops can iterate over them without the need to copy and paste code.

Commented out code does not have any bearing on your problem (whatever it is). Delete it before posting.

You have a Serial.begin() statement, and no other Serial method calls. Add some. What are you reading from the ultrasound sensors? What kind of ultrasound sensors are they?

Code:
M2.write(0); // tell servo to go to position in variable 'angle'
M4.write(0);
M1.write(0); // tell servo to go to position in variable 'pos'
M3.write(0);
Useless comments are bed enough. Comments that are flat out wrong are really bad. Fix them or get rid of them.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 26
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

can i say one thing,
why r u so stubborn Pauls,

you have deviated completely from the original question i asked, y everytime i ask abt something you talk abt something else???????????????

what part  of answer the question  related to the motor controllers only and not anything else u do not understand???
voltage and speed only !!!
sabertooth only!!!1

if you can answer that question you're welcome , otherwise do not reply please, thank you...........
Logged

Gosport, UK
Offline Offline
Faraday Member
**
Karma: 21
Posts: 3113
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Personally, I'm not sure what your question is. The thread heading is about Analog mode on the Sabertooth, but your sketch is using RC mode. The two modes are independant. Which do you want to use?

FWIW, the label and gotos are functionally redundant.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 26
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ok i want to use the analog mode ,




this is the kinda reply im expecting thank you
Logged

New Hampshire
Offline Offline
God Member
*****
Karma: 17
Posts: 781
There are 10 kinds of people, those who know binary, and those who don't.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
why r u so stubborn Pauls,

This: http://www.catb.org/~esr/faqs/smart-questions.html#intro
And this: http://mattgemmell.com/2008/12/08/what-have-you-tried/

Explain in spendid detail why Pauls and many others are the way they are.
Logged


Gosport, UK
Offline Offline
Faraday Member
**
Karma: 21
Posts: 3113
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Can the analog mode take PWM, or does it need a true 0-5v continuous voltage?

If PWM is ok, then you'll need to get rid of the Servo library stuff, and use analogWrite() on the pins you have connected to the Sabertooth analog inputs.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 309
Posts: 26485
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Can the analog mode take PWM
No, it can't, it needs to be filtered.

@Op,  the reason people ask questions around the issue is because of the number of posts they have experienced and wasted time on, where the person asking the question has posted a perfectly innocuous segment of code where they believe their problem to lie, only to find an array bounds problem, or a wiring problem elsewhere.
Logged

"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.

Gosport, UK
Offline Offline
Faraday Member
**
Karma: 21
Posts: 3113
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Can the analog mode take PWM
No, it can't, it needs to be filtered.

In that case, someone else will need to chip in.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 309
Posts: 26485
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I don't understand why anyone would want to use an analogue method, when a perfectly good digital one exists.
Perhaps we will be enlightened.
Logged

"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.

Pages: [1] 2   Go Up
Jump to: