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 jetfishteam

Committer:
sandwich
Date:
Fri Jun 06 19:48:01 2014 +0000
Revision:
24:9d75ed1462d6
Parent:
23:ef1be367726e
Child:
25:4f2f441eceec
works again; pixy and controller are on different tickers; thread polls duty cycle and writes it

Who changed what in which revision?

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