My modifications/additions to the code
Dependencies: ADXL345 ADXL345_I2C IMUfilter ITG3200 Servo fishgait mbed-rtos mbed pixy_cam
Fork of robotic_fish_ver_4_8 by
MainController.h@19:655db88b045c, 2014-05-28 (annotated)
- Committer:
- rkk
- Date:
- Wed May 28 01:48:23 2014 +0000
- Revision:
- 19:655db88b045c
- Parent:
- 18:9ba4566f2361
- Child:
- 20:6ae16da1492a
added yaw controller with adjustable frequency for either half to do a turning motion
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rkk | 11:8ec915eb70f6 | 1 | #ifndef MBED_MAINCONTROLLER_H |
rkk | 11:8ec915eb70f6 | 2 | #define MBED_MAINCONTROLLER_H |
rkk | 11:8ec915eb70f6 | 3 | |
rkk | 11:8ec915eb70f6 | 4 | #include "mbed.h" |
rkk | 11:8ec915eb70f6 | 5 | #include "PwmIn.h" |
rkk | 11:8ec915eb70f6 | 6 | #include "motor_controller.h" |
rkk | 12:7eeb29892625 | 7 | #include "guardian.h" |
rkk | 12:7eeb29892625 | 8 | //#include "IMU.h" |
rkk | 17:6970aef8154b | 9 | #include "Servo.h" |
rkk | 17:6970aef8154b | 10 | |
rkk | 12:7eeb29892625 | 11 | |
rkk | 11:8ec915eb70f6 | 12 | |
rkk | 11:8ec915eb70f6 | 13 | #define MATH_PI 3.14159265359 |
rkk | 11:8ec915eb70f6 | 14 | |
rkk | 11:8ec915eb70f6 | 15 | /** MainController class to get control inputs and place them onto the system |
rkk | 11:8ec915eb70f6 | 16 | * |
rkk | 11:8ec915eb70f6 | 17 | * |
rkk | 11:8ec915eb70f6 | 18 | */ |
rkk | 11:8ec915eb70f6 | 19 | class MainController { |
rkk | 11:8ec915eb70f6 | 20 | public: |
rkk | 11:8ec915eb70f6 | 21 | /** Create a MainController |
rkk | 11:8ec915eb70f6 | 22 | * |
rkk | 11:8ec915eb70f6 | 23 | * @param |
rkk | 11:8ec915eb70f6 | 24 | */ |
rkk | 11:8ec915eb70f6 | 25 | MainController() ; |
rkk | 11:8ec915eb70f6 | 26 | |
rkk | 11:8ec915eb70f6 | 27 | /** Start the main controller |
rkk | 11:8ec915eb70f6 | 28 | * |
rkk | 11:8ec915eb70f6 | 29 | * @returns |
rkk | 11:8ec915eb70f6 | 30 | */ |
rkk | 11:8ec915eb70f6 | 31 | void start(); |
rkk | 11:8ec915eb70f6 | 32 | |
rkk | 11:8ec915eb70f6 | 33 | float getDutyCycle(); |
rkk | 11:8ec915eb70f6 | 34 | float getFrequency(); |
rkk | 11:8ec915eb70f6 | 35 | float getVolume(); |
rkk | 11:8ec915eb70f6 | 36 | float getAmplitude(); |
rkk | 19:655db88b045c | 37 | float getYaw(); |
rkk | 17:6970aef8154b | 38 | float getPitch(); |
rkk | 19:655db88b045c | 39 | float getTimeAdd(); |
rkk | 11:8ec915eb70f6 | 40 | |
rkk | 11:8ec915eb70f6 | 41 | /** Stop the main controller |
rkk | 11:8ec915eb70f6 | 42 | * |
rkk | 11:8ec915eb70f6 | 43 | * @returns |
rkk | 11:8ec915eb70f6 | 44 | */ |
rkk | 11:8ec915eb70f6 | 45 | void stop(); |
rkk | 11:8ec915eb70f6 | 46 | |
rkk | 11:8ec915eb70f6 | 47 | |
rkk | 11:8ec915eb70f6 | 48 | protected: |
rkk | 11:8ec915eb70f6 | 49 | void control(); |
rkk | 11:8ec915eb70f6 | 50 | float calculateFrequency(); |
rkk | 19:655db88b045c | 51 | float calculateAmplitude(); |
rkk | 19:655db88b045c | 52 | float calculateYaw(); |
rkk | 17:6970aef8154b | 53 | float calculatePitch(); |
rkk | 13:5ed8fd870723 | 54 | float signum(float input); |
rkk | 15:dc5753a5b83e | 55 | float saturate(float input); |
rkk | 11:8ec915eb70f6 | 56 | |
rkk | 11:8ec915eb70f6 | 57 | private: |
rkk | 17:6970aef8154b | 58 | PwmIn ch1; |
rkk | 17:6970aef8154b | 59 | PwmIn ch2; |
rkk | 11:8ec915eb70f6 | 60 | PwmIn ch3; |
rkk | 12:7eeb29892625 | 61 | PwmIn ch4; |
rkk | 11:8ec915eb70f6 | 62 | PwmIn ch6; |
rkk | 11:8ec915eb70f6 | 63 | PololuMController mcon; |
rkk | 12:7eeb29892625 | 64 | Guardian ap; |
rkk | 18:9ba4566f2361 | 65 | //Servo leftservo; |
rkk | 18:9ba4566f2361 | 66 | //Servo rightservo; |
rkk | 12:7eeb29892625 | 67 | |
rkk | 11:8ec915eb70f6 | 68 | Timer timer1; |
rkk | 11:8ec915eb70f6 | 69 | Ticker ticker1; |
rkk | 19:655db88b045c | 70 | float amp; |
rkk | 11:8ec915eb70f6 | 71 | float frq; |
rkk | 11:8ec915eb70f6 | 72 | float dutyCycle; |
rkk | 11:8ec915eb70f6 | 73 | float curTime; |
rkk | 11:8ec915eb70f6 | 74 | float frqMin; |
rkk | 11:8ec915eb70f6 | 75 | float frqMax; |
rkk | 19:655db88b045c | 76 | float yaw; |
rkk | 17:6970aef8154b | 77 | float pitch; |
rkk | 17:6970aef8154b | 78 | |
rkk | 19:655db88b045c | 79 | bool fullCycle; |
rkk | 19:655db88b045c | 80 | float volume; |
rkk | 19:655db88b045c | 81 | float volChg; |
rkk | 19:655db88b045c | 82 | float volMax; |
rkk | 19:655db88b045c | 83 | float frqCmd; |
rkk | 19:655db88b045c | 84 | float timeAdd; |
rkk | 19:655db88b045c | 85 | float ampNew; |
rkk | 19:655db88b045c | 86 | float ampCmd; |
rkk | 19:655db88b045c | 87 | //int state; |
rkk | 19:655db88b045c | 88 | //int change; |
rkk | 17:6970aef8154b | 89 | //float goofftime; |
rkk | 17:6970aef8154b | 90 | //bool switched; |
rkk | 11:8ec915eb70f6 | 91 | }; |
rkk | 11:8ec915eb70f6 | 92 | |
rkk | 11:8ec915eb70f6 | 93 | #endif |
rkk | 11:8ec915eb70f6 | 94 | |
rkk | 11:8ec915eb70f6 | 95 |