SHARE
TWEET

microcode

a guest Jan 26th, 2020 116 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // LQR Code
  2.  
  3. "//========================================
  4. /*  
  5. Generated by: Wolfram Language 12.0.0
  6. Date        : Sat 25 Jan 2020 16:32:52
  7. File        : m000003101401.cpp
  8.  */
  9. //========================================
  10. #include <stdint.h>
  11. #include <avr/interrupt.h>
  12. #include <math.h>
  13. #include <Arduino.h>
  14. double read_adc(uint8_t channel)
  15. {
  16. double adcValue;
  17. switch ( channel)
  18. {
  19. case 0:
  20. adcValue = (5. * analogRead(A0)) / 1023;
  21. break;
  22.  
  23. case 1:
  24. adcValue = (5. * analogRead(A1)) / 1023;
  25. break;
  26.  
  27. case 2:
  28. adcValue = (5. * analogRead(A2)) / 1023;
  29. break;
  30. }
  31. return adcValue;
  32. }
  33. double u[3] = {0, 0, 0};
  34. double y[1] = {84.38063590995105};
  35. void update_nssm(double *u, double *y)
  36. {
  37. y[0] = -26.8591906126124*(-M_PI + u[0]) - 2.8517595773639597*u[1] + \
  38. 0.018993162921974713*u[2];
  39. }
  40. void setup()
  41. {
  42. analogReference(DEFAULT);
  43. Serial.begin(9600);
  44. }
  45. void loop()
  46. {
  47. double uu0 = read_adc(0);
  48. double uu1 = read_adc(1);
  49. double uu2 = read_adc(2);
  50. u[0] = uu0;
  51. u[1] = uu1;
  52. u[2] = uu2;
  53. update_nssm(u, y);
  54. Serial.write(19);
  55. Serial.print(y[0], 2);
  56. Serial.write(17);
  57. delayMicroseconds(150);
  58. }
  59.  
  60. // LQI code
  61.  
  62. "//========================================
  63. /*  
  64. Generated by: Wolfram Language 12.0.0
  65. Date        : Mon 27 Jan 2020 00:16:37
  66. File        : m000009101401.cpp
  67.   */
  68. //========================================
  69. #include <stdint.h>
  70. #include <avr/interrupt.h>
  71. #include <Arduino.h>
  72. double read_adc(uint8_t channel)
  73. {
  74. double adcValue;
  75. switch ( channel)
  76. {
  77. case 0:
  78. adcValue = (5. * analogRead(A0)) / 1023;
  79. break;
  80.  
  81. case 1:
  82. adcValue = (5. * analogRead(A1)) / 1023;
  83. break;
  84.  
  85. case 2:
  86. adcValue = (5. * analogRead(A2)) / 1023;
  87. break;
  88. }
  89. return adcValue;
  90. }
  91. double u[3] = {0, 0, 0};
  92. double y[1] = {84.38063590995105};
  93. void update_nssm(double *u, double *y)
  94. {
  95. static double x[1] = {0};
  96. double x1[1];
  97. y[0] = 84.38063590995105 - 1.5041146743062945*x[0] - \
  98. 0.7520573371531473*u[0] - 2.8517595773639597*u[1] + \
  99. 0.018993162921974713*u[2];
  100. x1[0] = 1.*x[0] + 1.*u[0];
  101. x[0] = x1[0];
  102. }
  103. void setup()
  104. {
  105. analogReference(DEFAULT);
  106. Serial.begin(9600);
  107. }
  108. void loop()
  109. {
  110. double uu0 = read_adc(0);
  111. double uu1 = read_adc(1);
  112. double uu2 = read_adc(2);
  113. u[0] = uu0;
  114. u[1] = uu1;
  115. u[2] = uu2;
  116. update_nssm(u, y);
  117. Serial.write(19);
  118. Serial.print(y[0], 2);
  119. Serial.write(17);
  120. delay(1);
  121. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top