Thirteenth day

Hello everyone!

Everyone made it to the school today! First time in a month.

Let’s summarize today’s work:

-Shield: it’s almost finished, we have to solder 2 or 3 components to go.

-Structure: we attached 2 wheels to it, the main goal is to test stability in one axis. Below, you can find some pics.ImageImage

Image

-PID algorithm: Finally, we are able to execute the algorithm in a fixed period. Below you can check the code used for the test.

  1. #include <qPIDs.h>
  2. // avr-libc library includes
  3. #include <avr/io.h>
  4. #include <avr/interrupt.h>
  5. #define setPointPin A0
  6. #define feedbackPin A5
  7. #define pwmPin 9
  8. qPID ctrl;
  9. volatile float feedback;
  10. float setPoint;
  11. float terms[3];
  12. volatile float CO;
  13. void setup()
  14. {
  15. //I/O configuration
  16. pinMode(setPointPin,INPUT);
  17. pinMode(fedbackPin,INPUT);
  18. pinMode(pwmPin, OUTPUT);
  19. //serial port configuration
  20. Serial.begin(115200);
  21. // PID’s configuration
  22. ctrl.AntiWindup = ENABLED;
  23. ctrl.Bumpless = ENABLED;
  24. ctrl.Mode = AUTOMATIC;
  25. ctrl.OutputMax = 255.0;
  26. ctrl.OutputMin = 0;
  27. ctrl.Ts = 0.009984; //the timer is actually interrupting a little faster than 10mS
  28. ctrl.b = 1.0;
  29. ctrl.c = 1.0;
  30. ctrl.K = 0.2;
  31. ctrl.Ti = 0.5;
  32. ctrl.Td = 0.001;
  33. ctrl.N = 5;
  34. qPID_Init(&ctrl);
  35. // initialize Timer1
  36. cli(); // disable global interrupts
  37. TCCR1A = 0; // set entire TCCR1A register to 0
  38. TCCR1B = 0; // same for TCCR1B
  39. // set compare match register to desired timer count:
  40. OCR1A = 155;
  41. // turn on CTC mode:
  42. TCCR1B |= (1 << WGM12);
  43. // Set CS10 and CS12 bits for 1024 prescaler:
  44. TCCR1B |= (1 << CS10);
  45. TCCR1B |= (1 << CS12);
  46. // enable timer compare interrupt:
  47. TIMSK1 |= (1 << OCIE1A);
  48. // enable global interrupts:
  49. sei();
  50. }
  51. void loop()
  52. {
  53. feedback=analogRead(feedbackPin);
  54. setPoint=analogRead(setPointPin);
  55. Serial.print(CO);
  56. Serial.print(“\t”);
  57. Serial.print(setPoint);
  58. Serial.print(“\t”);
  59. Serial.println(feedback);
  60. }
  61. ISR(TIMER1_COMPA_vect)
  62. {
  63. CO = qPID_Process(&ctrl,setPoint,feedback,terms);
  64. analogWrite(pwmPin,CO);
  65. }

Of course, if you have any doubts, just leave them at the comments section and we will try to answer as fast as possible.

-IMU: even though a lot of effort has been made to make the readings better, or at least understand the problem, there’s still no clue.

Well that’s all for this week, stay tuned 😉

P.S:we won’t be posting in the next two weeks because of the winter break.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s