Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // LQR Code
- "//========================================
- /*
- Generated by: Wolfram Language 12.0.0
- Date : Sat 25 Jan 2020 16:32:52
- File : m000003101401.cpp
- */
- //========================================
- #include <stdint.h>
- #include <avr/interrupt.h>
- #include <math.h>
- #include <Arduino.h>
- double read_adc(uint8_t channel)
- {
- double adcValue;
- switch ( channel)
- {
- case 0:
- adcValue = (5. * analogRead(A0)) / 1023;
- break;
- case 1:
- adcValue = (5. * analogRead(A1)) / 1023;
- break;
- case 2:
- adcValue = (5. * analogRead(A2)) / 1023;
- break;
- }
- return adcValue;
- }
- double u[3] = {0, 0, 0};
- double y[1] = {84.38063590995105};
- void update_nssm(double *u, double *y)
- {
- y[0] = -26.8591906126124*(-M_PI + u[0]) - 2.8517595773639597*u[1] + \
- 0.018993162921974713*u[2];
- }
- void setup()
- {
- analogReference(DEFAULT);
- Serial.begin(9600);
- }
- void loop()
- {
- double uu0 = read_adc(0);
- double uu1 = read_adc(1);
- double uu2 = read_adc(2);
- u[0] = uu0;
- u[1] = uu1;
- u[2] = uu2;
- update_nssm(u, y);
- Serial.write(19);
- Serial.print(y[0], 2);
- Serial.write(17);
- delayMicroseconds(150);
- }
- // LQI code
- "//========================================
- /*
- Generated by: Wolfram Language 12.0.0
- Date : Mon 27 Jan 2020 00:16:37
- File : m000009101401.cpp
- */
- //========================================
- #include <stdint.h>
- #include <avr/interrupt.h>
- #include <Arduino.h>
- double read_adc(uint8_t channel)
- {
- double adcValue;
- switch ( channel)
- {
- case 0:
- adcValue = (5. * analogRead(A0)) / 1023;
- break;
- case 1:
- adcValue = (5. * analogRead(A1)) / 1023;
- break;
- case 2:
- adcValue = (5. * analogRead(A2)) / 1023;
- break;
- }
- return adcValue;
- }
- double u[3] = {0, 0, 0};
- double y[1] = {84.38063590995105};
- void update_nssm(double *u, double *y)
- {
- static double x[1] = {0};
- double x1[1];
- y[0] = 84.38063590995105 - 1.5041146743062945*x[0] - \
- 0.7520573371531473*u[0] - 2.8517595773639597*u[1] + \
- 0.018993162921974713*u[2];
- x1[0] = 1.*x[0] + 1.*u[0];
- x[0] = x1[0];
- }
- void setup()
- {
- analogReference(DEFAULT);
- Serial.begin(9600);
- }
- void loop()
- {
- double uu0 = read_adc(0);
- double uu1 = read_adc(1);
- double uu2 = read_adc(2);
- u[0] = uu0;
- u[1] = uu1;
- u[2] = uu2;
- update_nssm(u, y);
- Serial.write(19);
- Serial.print(y[0], 2);
- Serial.write(17);
- delay(1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement