Go Down

### Topic: Awesome throttle PID , Polulu Driver (Read 682 times)previous topic - next topic

#### LeonardoMello

##### Feb 26, 2012, 11:12 pm
Hello there! I'm new to the ardunio, I have to create a way to drive a stepper motor with a potentiometer, ie for each angle of the potentiometer is moved an angle equal to the stepper motor which will have a second pot to Feedback. Using a dedicated driver Polulu that I generate pulses on a pin and another pin I generate a pulse direction, which goes to a HIGH and LOW direction goes to another.
As follows in the drawing down there.
Thank you if you can help me.
Ai down a code that did this to test the analog inputs and some variables, then not progressed more.
Thanks

Quote

int   PotMan = A0;
int   PotMot = A1;
int   StepPin = 2;
int   DirPin = 3;
int   ValorManete = 0;
int   ValorMotor = 0;
int   v1=0;

void setup() {

pinMode(StepPin, OUTPUT);
pinMode(DirPin, OUTPUT);
pinMode(A0, INPUT);
pinMode(A1, INPUT);
}
void loop()
{
ValorManete = PotMan;
{
ValorManete = map(ValorManete, 0, 1023, 0, 630);
}
{
digitalWrite(StepPin, LOW);
if   ( ValorManete <= 1 )
{
digitalWrite(StepPin, HIGH);
}
{
digitalWrite(StepPin, LOW);
{v1 = constrain(v1, 300, 500);}
if   ( ValorManete == v1 )

{
digitalWrite(StepPin, HIGH);
}
}
{
digitalWrite(StepPin, LOW);

if   ( ValorManete >= 629)

{
digitalWrite(StepPin, HIGH);
}
}
{

ValorMotor = PotMot;
{
ValorMotor= map(ValorMotor, 0, 1023, 0, 315);
}

{
digitalWrite(DirPin, LOW);

if ( ValorMotor <= 1 )

{
digitalWrite(DirPin, HIGH);
}
}
{
digitalWrite(DirPin, LOW);

if ( ValorMotor >= 315 )

{
digitalWrite(DirPin, HIGH);
}
}
}
}
}

#### LeonardoMello

#1
##### Feb 27, 2012, 01:43 am
For Direction I Win  ... easy ¬¬' too
I wanna see for the others....

int   Pot = A0;
int   Stepp = 2;
int   Dir = 3;
int   ValorMan = 0;
int last = 0;
int current = 0;
int difference = 0;

void setup()
{
pinMode(Stepp, OUTPUT);
pinMode(Dir, OUTPUT);
pinMode(A0, INPUT);
}

void loop()
{
{
ValorMan = map(ValorMan, 0, 1023, 0, 360);
}

{
delay(100);
delay(100) ;
}

{
difference = last - current;         //Calculate the difference between the last known acceleration and the current acceleration
}

if (difference > 10)
{
digitalWrite(Stepp, LOW);
}
if (difference < -10)
{
digitalWrite(Stepp, HIGH);
}

}

#### PeterH

#2
##### Feb 27, 2012, 02:23 am

For Direction I Win

For posting code you fail, though.

Click on that # button when you edit your post, and it will put [ code ] and [ /code ] tags in. Put your code in between those, and it will prevent the forum software from munging your code.

#### LeonardoMello

#3
##### Mar 05, 2012, 12:04 am
It's because I was concentrating on other things, but thanks for the detail.
After burning many neurons could make the PID software and it worked perfectly. Oh that some photos of the project working. Now I have to create routines to improve the scales and adjustments to the degrees needed. If you have suggestions for improving the program. Thank you very much. down there in this program.
Quote

//============================================================================================================
//                                                     PROGRAMA DO LEO                                       =
//============================================================================================================
//
//============================================================================================================
//                                                       VARIAVEIS                                           =
//============================================================================================================

int   Pot = A0;
int   PotM = A1;
int   Stepp = 2;
int   Dir = 3;
int   ValorMan = 0;
int   ValorMot = 0;
int   val3=10;
int last = 0;
int current = 0;
int difference = 0;
//int y = 0;
//int b = 0;
int c =0;

//============================================================================================================
//                                                      SETUP                                                =
//============================================================================================================
void setup()
{
pinMode(Stepp, OUTPUT);
pinMode(Dir, OUTPUT);

}

//============================================================================================================
//                                                      SETUP                                                =
//============================================================================================================
void loop()

{
LEITURA:

ValorMan = map(ValorMan, 0, 1023, 0, 360);    // Degrees 1 turn
ValorMot = map(ValorMot, 0, 1023, 0, 360);    // Degrees 1 turn

last = ValorMan; //Read POT Control THROTTLE
current = ValorMot;  //Read POT Motor

difference = last - current;  //Difference between two POTs

c = abs (difference); // positive value always

// LEFT or RIGHT

if (difference > 1/100 )
{
digitalWrite(Dir, LOW);
}
if (difference < 1/100)
{
digitalWrite(Dir, HIGH);
}

if (c >= 3)  // Pulses to the driver . If <= 3 Stop pulses , means motor in position of the throttle.

{
digitalWrite(Stepp, HIGH);
delay(1/10000);
digitalWrite(Stepp, LOW);
delay(1/10000);
}
goto LEITURA;

}

Go Up