polymorphic base structures for easily implementing different gaits. Triangle wave is already in there
Dependents: robotic_fish_ver_4_9_pixy
fishgait.h@1:0aa1a6ccf5fe, 2014-06-19 (annotated)
- Committer:
- sandwich
- Date:
- Thu Jun 19 19:51:59 2014 +0000
- Revision:
- 1:0aa1a6ccf5fe
- Parent:
- 0:aec7653a5b19
- Child:
- 2:d95c40ac8a3e
fixed a bug where amplitude would be incorrect because wave isn't centered on 0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sandwich | 0:aec7653a5b19 | 1 | #pragma once |
sandwich | 0:aec7653a5b19 | 2 | #include "mbed.h" |
sandwich | 0:aec7653a5b19 | 3 | |
sandwich | 0:aec7653a5b19 | 4 | class fishgait |
sandwich | 0:aec7653a5b19 | 5 | { |
sandwich | 0:aec7653a5b19 | 6 | protected: |
sandwich | 0:aec7653a5b19 | 7 | Timer* t; |
sandwich | 0:aec7653a5b19 | 8 | public: |
sandwich | 0:aec7653a5b19 | 9 | fishgait(); //give the constructor a timer to use |
sandwich | 0:aec7653a5b19 | 10 | ~fishgait(); |
sandwich | 0:aec7653a5b19 | 11 | void setTimer(Timer* tObject); //give the instance a timer to base its calculations off of instead of making a new one |
sandwich | 0:aec7653a5b19 | 12 | virtual float compute()=0; //asbtract function to compute output duty cycle. Must redefine in child classes |
sandwich | 0:aec7653a5b19 | 13 | }; |
sandwich | 0:aec7653a5b19 | 14 | |
sandwich | 0:aec7653a5b19 | 15 | class triangleGait: public fishgait |
sandwich | 0:aec7653a5b19 | 16 | { |
sandwich | 0:aec7653a5b19 | 17 | private: |
sandwich | 0:aec7653a5b19 | 18 | float frq; |
sandwich | 0:aec7653a5b19 | 19 | float amp; |
sandwich | 0:aec7653a5b19 | 20 | public: |
sandwich | 0:aec7653a5b19 | 21 | triangleGait(float freq, float amplitude); |
sandwich | 0:aec7653a5b19 | 22 | //~triangleGait(); |
sandwich | 0:aec7653a5b19 | 23 | float compute(); //this does a triangle wave pattern. frequency and amplitude controlled |
sandwich | 1:0aa1a6ccf5fe | 24 | }; |
sandwich | 1:0aa1a6ccf5fe | 25 | |
sandwich | 1:0aa1a6ccf5fe | 26 | class squareGait: public fishgait |
sandwich | 1:0aa1a6ccf5fe | 27 | { |
sandwich | 1:0aa1a6ccf5fe | 28 | private: |
sandwich | 1:0aa1a6ccf5fe | 29 | float frq; |
sandwich | 1:0aa1a6ccf5fe | 30 | float amp; |
sandwich | 1:0aa1a6ccf5fe | 31 | public: |
sandwich | 1:0aa1a6ccf5fe | 32 | squareGait(float freq, float amplitude); |
sandwich | 1:0aa1a6ccf5fe | 33 | //~triangleGait(); |
sandwich | 1:0aa1a6ccf5fe | 34 | float compute(); //this does a triangle wave pattern. frequency and amplitude controlled |
sandwich | 0:aec7653a5b19 | 35 | }; |