How could I get the Cascade-PID controller working with my Arduino?How can a Java program get its own process ID?How to get PID of background process?How to check if a process id (PID) existsget pid in shell (bash)Arduino PID relay output with ds1820 not behaving as expectedCan I implement PID control directly on velocity along axis for a quadcopterBalancing quadcopter using arduinoIs it necessary to control a servo with pidPID implementation in arduinoarduino c++ multi time communication get garbled

Can an airline pilot be prosecuted for killing an unruly passenger who could not be physically restrained?

How would fantasy dwarves exist, realistically?

Can 2 light bulbs of 120V in series be used on 230V AC?

Does the talk count as invited if my PI invited me?

How do you cope with rejection?

Have GoT's showrunners reacted to the poor reception of the final season?

Using `printf` to print variable containing `%` percent sign results in "bash: printf: `p': invalid format character"

Driving a school bus in the USA

Largest memory peripheral for Sinclair ZX81?

Are there any symmetric cryptosystems based on computational complexity assumptions?

Why does Taylor’s series “work”?

Real-life exceptions to PEMDAS?

Gaussian kernel density estimation with data from file

Would a "ring language" be possible?

How do I balance a campaign consisting of four kobold PCs?

Don't replace "|" with "(empty)" when generating slugs from title?

Does the US Supreme Court vote using secret ballots?

When did Britain learn about the American Declaration of Independence?

Why does a table with a defined constant in its index compute 10X slower?

RegEx with d doesn’t work in if-else statement with [[

Should all adjustments be random effects in a mixed linear effect?

What should I wear to go and sign an employment contract?

Failing students when it might cause them economic ruin

Cryptic crossword (printer's devilry edition)



How could I get the Cascade-PID controller working with my Arduino?


How can a Java program get its own process ID?How to get PID of background process?How to check if a process id (PID) existsget pid in shell (bash)Arduino PID relay output with ds1820 not behaving as expectedCan I implement PID control directly on velocity along axis for a quadcopterBalancing quadcopter using arduinoIs it necessary to control a servo with pidPID implementation in arduinoarduino c++ multi time communication get garbled






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I've built a quadcopter and tried to stabilize it with the MPU6050(accelerometer and gyroskop) and an Arduino Uno as flightcontroller.

I'm trying to implement a Cascade PID Controller but without success. I've allready implemented a Rate PID-Loop which worked as expected. So you could fly the quadcopter but not in Angle-Mode like in a Flightcontoller with Betaflight flashed.



I've allready tried to dampen the vibrations but this only helped in Rate PID Mode.



This is the PID-Loop and the calculations.
If you set a looptime it will return the previous output of the PID-Calculation.



float PID::pidLoop(float setpoint, float position, float dt)
if(isLoopTime)
if(prevLoopTime + loopTime < millis())
prevLoopTime = millis();
return calcPid(setpoint, position, dt);
else
return output;

else
return calcPid(setpoint, position, dt);




float PID::calcPid(float setpoint, float position, float dt)
error = position - setpoint;
errorSum += error * dt;
dError = (error - prevError) / dt;
prevError = error;
output = kp * error + ki * errorSum + kd * dError;
if(isMinMax)
output = minMax(min, max, output);

return output;



Since the outerloop should be 4 times slower then the inner loop I've set an refreshtime of 0.016 seconds, because the inner Loop is as fast as the escs wich is a refreshreate of 0.004 seconds



//outer PID LOOP
pitchAnglePid = anglePid[pitch].pidLoop(setpoint[pitch], mpu6050.getPitchAngle(), 0.016);
rollAnglePid = anglePid[roll].pidLoop(setpoint[roll],mpu6050.getRollAngle(), 0.016);

//inner PID
pitch_pid = ratePid[pitch].pidLoop(pitchAnglePid, mpu6050.getPitchRate(), interval);
roll_pid = ratePid[roll].pidLoop(rollAnglePid, mpu6050.getRollRate(),interval);
yaw_pid = ratePid[yaw].pidLoop(setpoint[yaw], mpu6050.getYawRate(), interval);


The results of the inner loop are added/subtracted to the ESCs.



esc_1 = instructions[throttle]- pitch_pid + roll_pid - yaw_pid;
esc_2 = instructions[throttle]+ pitch_pid + roll_pid + yaw_pid;
esc_3 = instructions[throttle]+ pitch_pid - roll_pid - yaw_pid;
esc_4 = instructions[throttle]- pitch_pid - roll_pid + yaw_pid;


My PID coefficients:



//PID Controller //PITCH ROLL YAW
PID ratePid[3] = PID(2,0,0), PID(2,0,0), PID(4,0,0);
PID anglePid[2] = PID(1,0,0,0.016),PID(1,0,0,0.016);


In theory it should stabilize in degree now, but the Quadcopter just flips at the start for no reason. It is not possible to fly it.
Any help is appreciated. Thanks in advance










share|improve this question






























    0















    I've built a quadcopter and tried to stabilize it with the MPU6050(accelerometer and gyroskop) and an Arduino Uno as flightcontroller.

    I'm trying to implement a Cascade PID Controller but without success. I've allready implemented a Rate PID-Loop which worked as expected. So you could fly the quadcopter but not in Angle-Mode like in a Flightcontoller with Betaflight flashed.



    I've allready tried to dampen the vibrations but this only helped in Rate PID Mode.



    This is the PID-Loop and the calculations.
    If you set a looptime it will return the previous output of the PID-Calculation.



    float PID::pidLoop(float setpoint, float position, float dt)
    if(isLoopTime)
    if(prevLoopTime + loopTime < millis())
    prevLoopTime = millis();
    return calcPid(setpoint, position, dt);
    else
    return output;

    else
    return calcPid(setpoint, position, dt);




    float PID::calcPid(float setpoint, float position, float dt)
    error = position - setpoint;
    errorSum += error * dt;
    dError = (error - prevError) / dt;
    prevError = error;
    output = kp * error + ki * errorSum + kd * dError;
    if(isMinMax)
    output = minMax(min, max, output);

    return output;



    Since the outerloop should be 4 times slower then the inner loop I've set an refreshtime of 0.016 seconds, because the inner Loop is as fast as the escs wich is a refreshreate of 0.004 seconds



    //outer PID LOOP
    pitchAnglePid = anglePid[pitch].pidLoop(setpoint[pitch], mpu6050.getPitchAngle(), 0.016);
    rollAnglePid = anglePid[roll].pidLoop(setpoint[roll],mpu6050.getRollAngle(), 0.016);

    //inner PID
    pitch_pid = ratePid[pitch].pidLoop(pitchAnglePid, mpu6050.getPitchRate(), interval);
    roll_pid = ratePid[roll].pidLoop(rollAnglePid, mpu6050.getRollRate(),interval);
    yaw_pid = ratePid[yaw].pidLoop(setpoint[yaw], mpu6050.getYawRate(), interval);


    The results of the inner loop are added/subtracted to the ESCs.



    esc_1 = instructions[throttle]- pitch_pid + roll_pid - yaw_pid;
    esc_2 = instructions[throttle]+ pitch_pid + roll_pid + yaw_pid;
    esc_3 = instructions[throttle]+ pitch_pid - roll_pid - yaw_pid;
    esc_4 = instructions[throttle]- pitch_pid - roll_pid + yaw_pid;


    My PID coefficients:



    //PID Controller //PITCH ROLL YAW
    PID ratePid[3] = PID(2,0,0), PID(2,0,0), PID(4,0,0);
    PID anglePid[2] = PID(1,0,0,0.016),PID(1,0,0,0.016);


    In theory it should stabilize in degree now, but the Quadcopter just flips at the start for no reason. It is not possible to fly it.
    Any help is appreciated. Thanks in advance










    share|improve this question


























      0












      0








      0








      I've built a quadcopter and tried to stabilize it with the MPU6050(accelerometer and gyroskop) and an Arduino Uno as flightcontroller.

      I'm trying to implement a Cascade PID Controller but without success. I've allready implemented a Rate PID-Loop which worked as expected. So you could fly the quadcopter but not in Angle-Mode like in a Flightcontoller with Betaflight flashed.



      I've allready tried to dampen the vibrations but this only helped in Rate PID Mode.



      This is the PID-Loop and the calculations.
      If you set a looptime it will return the previous output of the PID-Calculation.



      float PID::pidLoop(float setpoint, float position, float dt)
      if(isLoopTime)
      if(prevLoopTime + loopTime < millis())
      prevLoopTime = millis();
      return calcPid(setpoint, position, dt);
      else
      return output;

      else
      return calcPid(setpoint, position, dt);




      float PID::calcPid(float setpoint, float position, float dt)
      error = position - setpoint;
      errorSum += error * dt;
      dError = (error - prevError) / dt;
      prevError = error;
      output = kp * error + ki * errorSum + kd * dError;
      if(isMinMax)
      output = minMax(min, max, output);

      return output;



      Since the outerloop should be 4 times slower then the inner loop I've set an refreshtime of 0.016 seconds, because the inner Loop is as fast as the escs wich is a refreshreate of 0.004 seconds



      //outer PID LOOP
      pitchAnglePid = anglePid[pitch].pidLoop(setpoint[pitch], mpu6050.getPitchAngle(), 0.016);
      rollAnglePid = anglePid[roll].pidLoop(setpoint[roll],mpu6050.getRollAngle(), 0.016);

      //inner PID
      pitch_pid = ratePid[pitch].pidLoop(pitchAnglePid, mpu6050.getPitchRate(), interval);
      roll_pid = ratePid[roll].pidLoop(rollAnglePid, mpu6050.getRollRate(),interval);
      yaw_pid = ratePid[yaw].pidLoop(setpoint[yaw], mpu6050.getYawRate(), interval);


      The results of the inner loop are added/subtracted to the ESCs.



      esc_1 = instructions[throttle]- pitch_pid + roll_pid - yaw_pid;
      esc_2 = instructions[throttle]+ pitch_pid + roll_pid + yaw_pid;
      esc_3 = instructions[throttle]+ pitch_pid - roll_pid - yaw_pid;
      esc_4 = instructions[throttle]- pitch_pid - roll_pid + yaw_pid;


      My PID coefficients:



      //PID Controller //PITCH ROLL YAW
      PID ratePid[3] = PID(2,0,0), PID(2,0,0), PID(4,0,0);
      PID anglePid[2] = PID(1,0,0,0.016),PID(1,0,0,0.016);


      In theory it should stabilize in degree now, but the Quadcopter just flips at the start for no reason. It is not possible to fly it.
      Any help is appreciated. Thanks in advance










      share|improve this question
















      I've built a quadcopter and tried to stabilize it with the MPU6050(accelerometer and gyroskop) and an Arduino Uno as flightcontroller.

      I'm trying to implement a Cascade PID Controller but without success. I've allready implemented a Rate PID-Loop which worked as expected. So you could fly the quadcopter but not in Angle-Mode like in a Flightcontoller with Betaflight flashed.



      I've allready tried to dampen the vibrations but this only helped in Rate PID Mode.



      This is the PID-Loop and the calculations.
      If you set a looptime it will return the previous output of the PID-Calculation.



      float PID::pidLoop(float setpoint, float position, float dt)
      if(isLoopTime)
      if(prevLoopTime + loopTime < millis())
      prevLoopTime = millis();
      return calcPid(setpoint, position, dt);
      else
      return output;

      else
      return calcPid(setpoint, position, dt);




      float PID::calcPid(float setpoint, float position, float dt)
      error = position - setpoint;
      errorSum += error * dt;
      dError = (error - prevError) / dt;
      prevError = error;
      output = kp * error + ki * errorSum + kd * dError;
      if(isMinMax)
      output = minMax(min, max, output);

      return output;



      Since the outerloop should be 4 times slower then the inner loop I've set an refreshtime of 0.016 seconds, because the inner Loop is as fast as the escs wich is a refreshreate of 0.004 seconds



      //outer PID LOOP
      pitchAnglePid = anglePid[pitch].pidLoop(setpoint[pitch], mpu6050.getPitchAngle(), 0.016);
      rollAnglePid = anglePid[roll].pidLoop(setpoint[roll],mpu6050.getRollAngle(), 0.016);

      //inner PID
      pitch_pid = ratePid[pitch].pidLoop(pitchAnglePid, mpu6050.getPitchRate(), interval);
      roll_pid = ratePid[roll].pidLoop(rollAnglePid, mpu6050.getRollRate(),interval);
      yaw_pid = ratePid[yaw].pidLoop(setpoint[yaw], mpu6050.getYawRate(), interval);


      The results of the inner loop are added/subtracted to the ESCs.



      esc_1 = instructions[throttle]- pitch_pid + roll_pid - yaw_pid;
      esc_2 = instructions[throttle]+ pitch_pid + roll_pid + yaw_pid;
      esc_3 = instructions[throttle]+ pitch_pid - roll_pid - yaw_pid;
      esc_4 = instructions[throttle]- pitch_pid - roll_pid + yaw_pid;


      My PID coefficients:



      //PID Controller //PITCH ROLL YAW
      PID ratePid[3] = PID(2,0,0), PID(2,0,0), PID(4,0,0);
      PID anglePid[2] = PID(1,0,0,0.016),PID(1,0,0,0.016);


      In theory it should stabilize in degree now, but the Quadcopter just flips at the start for no reason. It is not possible to fly it.
      Any help is appreciated. Thanks in advance







      arduino pid arduino-c++






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 23 at 17:07









      πάντα ῥεῖ

      74.9k1078147




      74.9k1078147










      asked Mar 23 at 17:07









      KimJongTiramisuKimJongTiramisu

      11




      11






















          0






          active

          oldest

          votes












          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55316269%2fhow-could-i-get-the-cascade-pid-controller-working-with-my-arduino%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55316269%2fhow-could-i-get-the-cascade-pid-controller-working-with-my-arduino%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

          용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

          155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해