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@25:4f2f441eceec, 2014-07-11 (annotated)
- Committer:
- sandwich
- Date:
- Fri Jul 11 14:30:36 2014 +0000
- Revision:
- 25:4f2f441eceec
- Parent:
- 24:9d75ed1462d6
latest revision
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 |
sandwich | 25:4f2f441eceec | 3 | |
rkk | 11:8ec915eb70f6 | 4 | #include "mbed.h" |
sandwich | 22:807d5467fbf6 | 5 | #include "rtos.h" |
rkk | 11:8ec915eb70f6 | 6 | #include "PwmIn.h" |
rkk | 11:8ec915eb70f6 | 7 | #include "motor_controller.h" |
rkk | 20:6ae16da1492a | 8 | //#include "guardian.h" |
rkk | 12:7eeb29892625 | 9 | //#include "IMU.h" |
rkk | 17:6970aef8154b | 10 | #include "Servo.h" |
sandwich | 22:807d5467fbf6 | 11 | #include "pixy.h" |
sandwich | 25:4f2f441eceec | 12 | #include "servoloop.h" |
rkk | 17:6970aef8154b | 13 | |
rkk | 12:7eeb29892625 | 14 | |
rkk | 11:8ec915eb70f6 | 15 | |
rkk | 11:8ec915eb70f6 | 16 | #define MATH_PI 3.14159265359 |
sandwich | 22:807d5467fbf6 | 17 | #define START_THREAD 1 |
sandwich | 25:4f2f441eceec | 18 | |
rkk | 11:8ec915eb70f6 | 19 | /** MainController class to get control inputs and place them onto the system |
sandwich | 25:4f2f441eceec | 20 | * |
sandwich | 25:4f2f441eceec | 21 | * |
rkk | 11:8ec915eb70f6 | 22 | */ |
sandwich | 25:4f2f441eceec | 23 | class MainController |
sandwich | 25:4f2f441eceec | 24 | { |
rkk | 11:8ec915eb70f6 | 25 | public: |
rkk | 11:8ec915eb70f6 | 26 | /** Create a MainController |
rkk | 11:8ec915eb70f6 | 27 | * |
sandwich | 25:4f2f441eceec | 28 | * @param |
sandwich | 25:4f2f441eceec | 29 | */ |
rkk | 11:8ec915eb70f6 | 30 | MainController() ; |
sandwich | 22:807d5467fbf6 | 31 | ~MainController(); |
sandwich | 25:4f2f441eceec | 32 | |
rkk | 11:8ec915eb70f6 | 33 | /** Start the main controller |
rkk | 11:8ec915eb70f6 | 34 | * |
sandwich | 25:4f2f441eceec | 35 | * @returns |
rkk | 11:8ec915eb70f6 | 36 | */ |
rkk | 11:8ec915eb70f6 | 37 | void start(); |
sandwich | 25:4f2f441eceec | 38 | |
rkk | 11:8ec915eb70f6 | 39 | float getDutyCycle(); |
rkk | 11:8ec915eb70f6 | 40 | float getFrequency(); |
rkk | 11:8ec915eb70f6 | 41 | float getVolume(); |
rkk | 11:8ec915eb70f6 | 42 | float getAmplitude(); |
rkk | 19:655db88b045c | 43 | float getYaw(); |
rkk | 17:6970aef8154b | 44 | float getPitch(); |
rkk | 20:6ae16da1492a | 45 | float getAdj(); |
sandwich | 22:807d5467fbf6 | 46 | bool getOpMode(); //returns true when in autonomous mode |
rkk | 20:6ae16da1492a | 47 | |
rkk | 11:8ec915eb70f6 | 48 | /** Stop the main controller |
rkk | 11:8ec915eb70f6 | 49 | * |
sandwich | 25:4f2f441eceec | 50 | * @returns |
rkk | 11:8ec915eb70f6 | 51 | */ |
rkk | 11:8ec915eb70f6 | 52 | void stop(); |
sandwich | 25:4f2f441eceec | 53 | |
sandwich | 25:4f2f441eceec | 54 | |
sandwich | 25:4f2f441eceec | 55 | protected: |
rkk | 11:8ec915eb70f6 | 56 | void control(); |
sandwich | 22:807d5467fbf6 | 57 | void trackTarget(); |
rkk | 11:8ec915eb70f6 | 58 | float calculateFrequency(); |
rkk | 19:655db88b045c | 59 | float calculateAmplitude(); |
rkk | 19:655db88b045c | 60 | float calculateYaw(); |
rkk | 17:6970aef8154b | 61 | float calculatePitch(); |
rkk | 20:6ae16da1492a | 62 | float calculateAdj(); |
rkk | 13:5ed8fd870723 | 63 | float signum(float input); |
rkk | 15:dc5753a5b83e | 64 | float saturate(float input); |
sandwich | 25:4f2f441eceec | 65 | |
rkk | 11:8ec915eb70f6 | 66 | private: |
rkk | 17:6970aef8154b | 67 | PwmIn ch1; |
rkk | 17:6970aef8154b | 68 | PwmIn ch2; |
rkk | 11:8ec915eb70f6 | 69 | PwmIn ch3; |
rkk | 12:7eeb29892625 | 70 | PwmIn ch4; |
rkk | 11:8ec915eb70f6 | 71 | PwmIn ch6; |
sandwich | 22:807d5467fbf6 | 72 | PwmIn ch5; |
sandwich | 22:807d5467fbf6 | 73 | Serial syren; //syren replaced the pololu controller |
rkk | 20:6ae16da1492a | 74 | //Guardian ap; |
rkk | 20:6ae16da1492a | 75 | Servo leftservo; |
rkk | 20:6ae16da1492a | 76 | Servo rightservo; |
sandwich | 25:4f2f441eceec | 77 | ServoLoop panLoop; |
sandwich | 25:4f2f441eceec | 78 | ServoLoop tiltLoop; |
sandwich | 25:4f2f441eceec | 79 | |
sandwich | 22:807d5467fbf6 | 80 | pixySPI pcam; |
sandwich | 25:4f2f441eceec | 81 | |
rkk | 11:8ec915eb70f6 | 82 | Timer timer1; |
sandwich | 24:9d75ed1462d6 | 83 | Ticker ticker1; |
sandwich | 24:9d75ed1462d6 | 84 | //RtosTimer controlTimer; |
sandwich | 24:9d75ed1462d6 | 85 | Ticker tracker; |
sandwich | 25:4f2f441eceec | 86 | Mutex trackMutex; |
sandwich | 25:4f2f441eceec | 87 | //Thread dutyThread; |
sandwich | 25:4f2f441eceec | 88 | //static void dutyThreadStarter(void const* p); |
sandwich | 25:4f2f441eceec | 89 | Thread controlThread; |
sandwich | 25:4f2f441eceec | 90 | static void controlThreadStarter(void const* p); |
sandwich | 24:9d75ed1462d6 | 91 | void updateDutyCycle(); |
sandwich | 25:4f2f441eceec | 92 | Thread trackerThread; |
sandwich | 25:4f2f441eceec | 93 | static void trackerThreadStarter(void const *p); |
rkk | 19:655db88b045c | 94 | float amp; |
sandwich | 23:ef1be367726e | 95 | float ampCmd; |
rkk | 11:8ec915eb70f6 | 96 | float frq; |
rkk | 11:8ec915eb70f6 | 97 | float dutyCycle; |
rkk | 11:8ec915eb70f6 | 98 | float curTime; |
rkk | 11:8ec915eb70f6 | 99 | float frqMin; |
rkk | 11:8ec915eb70f6 | 100 | float frqMax; |
rkk | 19:655db88b045c | 101 | float yaw; |
rkk | 17:6970aef8154b | 102 | float pitch; |
rkk | 20:6ae16da1492a | 103 | float adj; |
sandwich | 23:ef1be367726e | 104 | float yawAdjVal; |
rkk | 19:655db88b045c | 105 | bool fullCycle; |
rkk | 19:655db88b045c | 106 | float volume; |
rkk | 19:655db88b045c | 107 | float volMax; |
rkk | 19:655db88b045c | 108 | float frqCmd; |
rkk | 20:6ae16da1492a | 109 | float raiser; |
rkk | 20:6ae16da1492a | 110 | float pitAvg; |
rkk | 20:6ae16da1492a | 111 | float alPi; |
rkk | 11:8ec915eb70f6 | 112 | }; |
sandwich | 25:4f2f441eceec | 113 | |
sandwich | 25:4f2f441eceec | 114 | |
rkk | 11:8ec915eb70f6 | 115 | #endif |
rkk | 11:8ec915eb70f6 | 116 | |
rkk | 11:8ec915eb70f6 | 117 |