loading

digital potentiometer pid?

hello, i have digital potintiometer u/d fgive you 100 step for 10k ohm so 10k for 100 step, i use it as outpu of pid control that read the distance and set point of required distance and make p and i and d equation based on differance and summation i want to use that pid to altitude contol of helicopter ,the resistor that i change as output is connected to throttle when i increase to max(5k) it stop and min 1k it go ?max speed so  this work  

code arduino
**/

#include <DigiPotX9Cxxx.h>
#include <SoftwareSerial.h>
SoftwareSerial mySerial(52, 9,true); // RX, TX
int f=0;
char *buffer;
byte x;
char array[27];
int counter=0;
unsigned char r;
int p=0;
int last;
int error=0;
int wew;
int required ;
int kpipo;
int n;



DigiPot pot(22,3,24);
void setup() {

   Serial.begin(9600);
  mySerial.begin(9600);
}
void reading(){

  mySerial.println(1);
while (mySerial.available())
{
   x= mySerial.readBytes(buffer,1);
   if(*buffer==0x52){
   x= mySerial.readBytes(buffer,1);
   array[0]=*buffer;
   x= mySerial.readBytes(buffer,1);
   array[1]=*buffer;
   x= mySerial.readBytes(buffer,1);
   array[2]=*buffer;
   }
}

delayMicroseconds(220);
}
void loop()

{
 
  if (f==0){
  delay(600);}
  f=1;
reading();
  int Final_inch=(array[0]-48)*100 + (array[1]-48)*10 +(array[2]-48) ;
  float Final_cm=Final_inch*2.54;

 
  Serial.print(Final_inch);
  Serial.println(" Inch ");
  //Serial.print(Final_cm);
  //Serial.println(" cm ");
required =29;
error = required - Final_inch;
//Serial.print(error);

//Integral = Integral + Error; // accumulate the error integral
//}
//else {
// Integral=0; // zero it if out of bounds
//}
kpipo=1;
p =  (error * kpipo); // calc proportional term
// I = //Integral*kI; // integral term
//int D = (Last-Actual)*.1; // derivative term
wew = (error/2) ;// scale Drive to be in the range 0-99
Serial.print(wew);//(wew)
if (abs(wew)>400){
   wew=0;}
if ( wew >99) { 
wew=99;
}
if (wew <-99) { 
wew=-99;
}
n=abs(wew);
if (wew < 0){ // Check which direction to go.
    pot.increase(n);
    delay(500);
  }
else { // depending on the sign of Error
    pot.decrease(n);
    delay(500);
}

last = Final_inch; // save current value for next time
}

iceng3 years ago
You want to control height above the ground using
the Arduino PID  control of a digital pot to adjust
The main rotor RPM ..... is that correct ?

How does the uP know  how high the helicopter is ? ?
What is the feed-back for PID ( Proportional, Integral, Differential ) loop set point.

A
Use the Arduino PID library !