Motors in quadrocopter problem after adding radio control.


hello everyone. first topic please forgiving:)


as in topic have problem motors. i'm developing own flight control software quadrocopter on arduino mega. worked intended until add radio control. i'm using pin interrupt method. without motors working smooth, rc not. speed jump , down split second. different motors in random time. such problem can't config pid. here code responsible rc:

code: [select]
double ch1val = 0;
double ch2val = 0;
double ch3val = 0;
double ch4val = 0;
int ch1time = 0;
int ch2time = 0;
int ch3time = 0;
int ch4time = 0;
void ch1intend() {
  if (digitalread(ch1)==high){
    ch1time = micros();
  } else {
    ch1time = micros()-ch1time; 
    int ch1val = map(ch1time,970,1980,0,100);
    ch1val = ch1val/2;
    setbaseval(60+ch1val);
  }
  if (ch1time<1000) {
    pidenabled = false;
  } else {
    pidenabled = true;
  }
}
void ch2intend() {
  if (digitalread(ch2)==high){
    ch2time = micros();
  } else {
    ch2time = micros()-ch2time; 
    int ch2val = map(ch2time,892,1900,-50,50);
    ch2val = ch2val/5;
    setpoweryaw(ch2val);
  }
}
void ch3intend() {
  if (digitalread(ch3)==high){
    ch3time = micros();
  } else {
    ch3time = micros()-ch3time; 
    int ch3val = map(ch3time,970,1980,-50,50);
    ch3val = ch3val/10;
    setpowerpitch(ch3val);
  }
}
void ch4intend() {
  if (digitalread(ch4)==high){
    ch4time = micros();
  } else {
    ch4time = micros()-ch4time; 
    int ch4val = map(ch4time,970,1980,-50,50);
    ch4val = ch4val/10;
    setpowerroll(ch4val);
  }
}


attachinterrupt in other function. looks this:

code: [select]
attachinterrupt(0, ch1intend, change);
attachinterrupt(1, ch2intend, change);
attachinterrupt(5, ch3intend, change);
attachinterrupt(4, ch4intend, change);


does have idea can cause problem? if i'll grateful help.

i suspect problem isr's using decode pwm rc receiver taking time , screwing output pwm motors

i'm no expert, if @ apm board (diydrones), uses dedicated atmega328 pwm think.
i presume because mega process in available time.


apart asking why you'd want make own software this, ie been done loads of time already, there no point writing scratch yourself...

you try either optimizing rc decode isr's.  suspect best bet switch faster processor.

maple mini clones operate @ 72mhz , around $5 on ebay , aliexpress , there beta port of 1.6.rc1 ide support (see micro controllers forum)

alternatively teensy bit faster again maple mini's @ using instead (albeit $19 + postage , postage can expensive if outside usa)




Arduino Forum > Using Arduino > Project Guidance > Motors in quadrocopter problem after adding radio control.


arduino

Comments

Popular posts from this blog

invalid use of void expresion in FlexiTimer2 library

error: a function-definition is not allowed here before '{' token

LED Strip Code