Juan Salazar / robotic_fish_7

Dependencies:   mbed ESC mbed MODDMA

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers BuoyancyControlUnit.h Source File

BuoyancyControlUnit.h

00001 
00002 /*
00003  * BuoyancyControlUnit.h
00004  *
00005  * Author: Cyndia Cao, Robert Katzschmann
00006  */
00007 
00008 #ifndef BUOYANCYCONTROLUNIT_H_
00009 #define BUOYANCYCONTROLUNIT_H_
00010 
00011 #include "mbed.h"
00012 #include "MS5837/MS5837.h"
00013 #include "QEI/QEI.h"
00014 
00015 
00016 //#define bcuPwmPin p25
00017 #define bcuDirAPin p24 //now serves as bcuPWMAPin
00018 #define bcuDirBPin p25 //now serves as bcuPWMBPin
00019 #define wiperPin p17   // BCU potentiometer wiper 
00020 //#define bcuCurrentPin p20
00021 
00022 #define encoderPinA p16
00023 #define encoderPinB p17
00024 #define count2rev 12 //https://www.pololu.com/product/3081/blog
00025 #define gearRatio 75 // need to check
00026 
00027 #define PIN_IMU_TX p28
00028 #define PIN_IMU_RX p27
00029 
00030 //#define maxBCUCurrent 0.5 // need to measure
00031 //#define minBCUCurrent 0.1 // need to measure
00032 
00033 #define KpDepth 5 // random dummy val
00034 #define KdDepth 0.0 // ignore for now; start with P control
00035 #define KiDepth 0.0
00036 
00037 #define KpEnc 0.0005
00038 #define KdEnc 0.00003
00039 #define KiEnc 0.000000000
00040 
00041 
00042 class BuoyancyControlUnit
00043 {
00044 public:
00045     // Initialization
00046     BuoyancyControlUnit();
00047     void start();
00048     void stop();
00049     void set(float depthDesIn);
00050     void setDepthFunc(float depthDesIn);
00051     void setEncoderPosition(float setPosIn);
00052     void setV(float Vin);
00053 
00054     void setDepthFuncVoid();
00055     void setEncoderPosVoid();
00056 
00057     void returnToZero();
00058     void runBackwards();
00059     void runForwards();
00060 
00061     bool getBCUdir();
00062     float getVset();
00063     float getSetPos();
00064     float getCurPos();
00065     float getCurDepth();
00066     float getSetDepth();
00067     float readPressure();
00068 
00069 private:
00070     volatile bool resetFlag;
00071     volatile bool inDepthLoop;
00072     volatile bool inPosLoop;
00073 
00074     volatile float setDepth;
00075     volatile float curDepth;
00076     volatile bool bcuDir;
00077 
00078     volatile float posRef;
00079     volatile float depthErr;
00080     volatile float prevDepthErr;
00081     volatile float depthDer;
00082     volatile float depthInt;
00083     volatile float depthLastTime;
00084 
00085     volatile float setPos;
00086     volatile float curPos;
00087 
00088     volatile float VRef;
00089     volatile float posErr;
00090     volatile float prevPosErr;
00091     volatile float posDer;
00092     volatile float posInt;
00093     volatile float posLastTime;
00094 
00095     Timer timer;
00096     //PwmOut bcuPWM;
00097     PwmOut bcuDirA;
00098     PwmOut bcuDirB;
00099     AnalogIn wiper;
00100 //  AnalogIn bcuCurrent; // actually is a voltage value proportional to current
00101 //  QEI bcuEncoder;
00102     MS5837 pressureSensor;
00103 
00104     Ticker depthControl;
00105     Ticker posControl;
00106 };
00107 
00108 // Create a static instance of BuoyancyControlUnit to be used by anyone controlling the Buoyancy Control Unit
00109 extern BuoyancyControlUnit buoyancyControlUnit;
00110 
00111 #endif /* BUOYANCYCONTROLUNIT_H_ */