Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. /* ======== USER INTERFACE TEMPLATE ============= */
  2. /* Insert below the code for your scaling, saturation block, and controllers.*/
  3.  
  4. /* Variables may be declared on the box border, as shown for the input
  5. "Tms" and the output "BallPosn". Variables can also be declared inline as was done for "Temp1". */
  6.  
  7. float Temp1;
  8. float eGearAng;
  9.  
  10. // T = 0.001
  11.  
  12. float e;
  13. float outerErr;
  14.  
  15. float u_old_coeff = 0.968181072658685;
  16. float e_coeff = -3.451295475976174;
  17. float e_old_coeff = 3.342328438925280;
  18.  
  19. float ThRef_old_coeff = 0.997503121098627;
  20. float outerErr_coeff = 6.992484394506866;
  21. float outerErr_old_coeff = -6.990037453183520;
  22.  
  23. float ThRefSat;
  24.  
  25. /* Shift registers permit previous values of variables to be saved.
  26. The output variable "e" is wired to a shift register input on the For Loop border.
  27. The inputs "e1" and "e2"are wired to the corresponding shift register outputs.
  28. "e1" holds the value of "e" from the previous iteration and "e2" holds the value of "e1" from the previous iteration. */
  29.  
  30. /* Place your sensor SCALING here */
  31. /* NO scaling is provided for the demo */
  32.  
  33. BallPosn = 0.103*posV-0.342; //0.105*posV-0.342; /* V to V */
  34. //ServoAng = angV/(-0.589) + 7.234 + 0.3; /* V to V */
  35. ServoAng = angV/(-0.65317) + 6.817 + 0.055;
  36. /* SCALING end */
  37.  
  38. if (Loop < 3) /* all shift registers cleared after 3rd iteration; this statement initializes the shift registers */
  39. {u = e = outerErr =ThRef = posV= angV =ServoAng= BallPosn= 0;}
  40. else
  41. {
  42. if (Manual) /*manual motor voltage control*/
  43. { u = MotV;}
  44. else /*control algorithm*/
  45. {
  46.  
  47. /* CAUTION: DO NOT load the output of a nonlinear block (e.g., saturator, offset) into a SHIFT REGISTER,
  48. to avoid introducing a nonlinearity into your controller loop. Create separate variables to hold nonlinear values.*/
  49.  
  50. /* Place your outer loop BALL POSITION CONTROLLER below */
  51. outerErr = ref - BallPosn;
  52. // question b)
  53. //ThRef = ThRef_old_coeff*ThRef1 - outerErr_coeff*outerErr - outerErr_old_coeff*outerErr1;
  54.  
  55. // question c)
  56. //ThRef = 1.993*ThRef1 - 0.993*ThRef2 - 30*outerErr + 59.98599*outerErr1 - 29.98599007*outerErr2;
  57.  
  58. // question d)
  59. ThRef = 1.996*ThRef1 - 0.996*ThRef2 - 19*outerErr + 37.987985*outerErr1 - 18.98798506*outerErr2;
  60.  
  61. ThRefSat = ThRef;
  62.  
  63. if (ThRefSat > 0) {
  64. ThRefSat += 0.083;
  65. } else if (ThRefSat < 0) {
  66. ThRefSat -= 0.083;
  67. }
  68.  
  69. /* Place your gear angle SATURATOR below */
  70. if(ThRefSat < (-0.7)) {
  71. ThRefSat = -0.7;
  72. } else if(ThRefSat > (0.7)) {
  73. ThRefSat = 0.7;
  74. }
  75.  
  76. /* Place your inner loop GEAR ANGLE CONTROLLER below */
  77. e = ThRefSat - ServoAng;
  78.  
  79. u = u_old_coeff*u1 + e_coeff*e + e_old_coeff*e1;
  80. }
  81. }
  82.  
  83. /* ThRef, ThRef1, e, e1 are present, but not used in this demo.
  84. However, they will be necessary (at a minimum) when the controllers will be implemented. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement