Chandan Siyag / Mbed 2 deprecated AlooMBED

Dependencies:   MCP23017 TCS3472_I2C WattBob_TextLCD mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers globals.h Source File

globals.h

00001 
00002 //
00003 // globals.h
00004 // Created by Chandan Siyag on 13/11/2015.
00005 //
00006 // Includes all the functions, variables, objects that need to be accessed accross the classes/files.
00007 #ifndef _globals_h_
00008 #define _globals_h_
00009 
00010 #include "Block.h"
00011 #include "mbed.h"
00012 
00013 // Forward declared classes
00014 class FPGA;
00015 class TCS3472_I2C;
00016 class MCP23017;
00017 class WattBob_TextLCD;
00018 
00019 // External global variables
00020 extern mbed::Serial pc;
00021 extern MCP23017 *i2cport;
00022 extern int kDefaultBaudRate;
00023 extern WattBob_TextLCD *lcd;
00024 //extern SerialBase gParity;
00025 extern int gStopBits;
00026 extern bool connectedToPC;
00027 extern bool runServoTest;
00028 extern bool runBreakBeamTest;
00029 extern bool runColourSensorTest;
00030 extern bool getColourSensorValue;
00031 extern bool getBlockColourValue;
00032 extern float gIntegrationTime;
00033 extern int gToggleServoNumber;
00034 extern int errorMultiplier;
00035 extern int hazReadingCount;
00036 extern bool setNewHazBlock;
00037 
00038 // Constants
00039 const int kCommandBufferSize = 80;
00040 const int kSmallBufferSize = 5;
00041 const float kServoWait = 0.20;
00042 
00043 // More external globals vars
00044 extern float currentMinError[3];
00045 extern float currentMaxError[3];
00046 extern bool pcModeChanged;
00047 #define FOREVER for(;;)
00048 
00049 // More constants and enums
00050 const char CommandTypeValue [3] = {'!', '?', ':'};
00051 const char kCommandTerminator = ';';
00052 enum CommandTypeRaw { InvalidType = -1, Set = 0, Query = 1, Reply = 2 };
00053 
00054 // Red block values
00055 const float kMinRedBlock[4] = {4.812, 2.286, 1.316, 1};
00056 const float kMaxRedBlock[4] = {5.474, 3.105, 1.429, 1};
00057 const float kAverageRedBlock[4] = {5.25134482758621, 2.85965517241379, 1.35858620689655, 1};
00058 const float kMinRedError[3] = { 0.389641483105392, 0.383777881434993, 0.0610744881279823};
00059 const float kMaxRedError[3] = { 0.238327377883225, 0.139481384106522, 0.0612648605358003};
00060 
00061 // Other colour blocks
00062 const float kMinError[7][3] = {
00063         { 0.389641483105392, 0.383777881434993, 0.0500744881279823}, // Red
00064         { 0.0359779720380292, 0.0461476412271348, 0.0391255334092747 }, // White
00065         { 0.050917996923305, 0.109422428771797, 0.0665409549163153 }, // Blue
00066         { 0.0880138969310943, 0.0743612766304789, 0.143658023826209 }, // Green
00067         { 0.517256339090836, 0.504177829914356, 0.0752212389380535 }, // Orange
00068         { 0.092903676196678, 0.125407698975651, 0.107444827572802 }, // Yellow
00069         { 0, 0, 0} // TODO: Add Black
00070 };
00071 
00072 const float kMaxError[7][3] = {
00073         { 0.238327377883225, 0.139481384106522, 0.0502648605358003},
00074         { 0.0231629905458534, 0.0382894017850168, 0.0244999380271382 }, // White
00075         { 0.312890306667189, 0.361950218761122, 0.307500801104292 }, // Blue
00076         { 0.532136653155761, 0.0508203411966372, 0.0469516468114928 }, // Green
00077         { 0.215383578992752, 0.114324911398194, 0.0350882137421786 }, // Orange
00078         { 0.055956916957788, 0.0732559590665169, 0.0515512811043425 }, // Yellow
00079         { 0, 0, 0} // TODO: Add black
00080 };
00081 
00082 const float kAverageValues[7][4] = {
00083         {5.25134482758621, 2.85965517241379, 1.35858620689655, 1},
00084         { 4.10882727272727, 1.39749090909091, 1.54026363636364, 1 },
00085         { 2.5782808988764, 0.536730337078651, 0.911662921348315, 1 },
00086         { 4.60533333333333, 1.13435185185185, 2.1405, 1 },
00087         { 6.51070175438596, 3.52949122807018, 1.86747368421053, 1 },
00088         { 6.81846, 2.96481, 2.57239, 1 },
00089         { 0, 0, 0, 1 }
00090 };
00091 
00092 // External global objects
00093 extern Block defaultHazBlock;
00094 extern Block _HazBlock;
00095 extern FPGA *fpga;
00096 
00097 extern TCS3472_I2C rgbSensor;
00098 
00099 // Enums to help make code more readable and easier to edit
00100 enum Servos {Stopping = 1, Sorting = 2};
00101 enum StoppingServoPositions {Stop = 0, Go = 1};
00102 enum SortingServoPositions {NonHaz = 0, Haz = 1};
00103 enum Controls { Start = 0, Pause = 1};
00104 enum PCModes { None = -1, Normal = 0, Maintanence = 1};
00105 
00106 // External variables
00107 extern PCModes currentMode;
00108 extern Controls currentState;
00109 
00110 // Global functions
00111 void DefaultHazBlock();
00112 
00113 int readSwitches();
00114 bool displayAbortDialog();
00115 void displayPCStatus();
00116 
00117 void connectToPC(CommandTypeRaw typeRaw=Set);
00118 void disconnectToPC(CommandTypeRaw typeRaw=Set);
00119 void hazBlock(CommandTypeRaw typeRaw);
00120 void getCurrentBlock(CommandTypeRaw typeRaw=Query);
00121 
00122 void setIntegrationTimeTo(float integrationTime);
00123 void previewOnPC(bool on);
00124 void testColourSensor(Controls state);
00125 
00126 void testServos(Controls state);
00127 void resetServos();
00128 
00129 void getPortInfo();
00130 void setPortBaudRate(int baudRate);
00131 void setPortParity(int parity);
00132 
00133 void testBreakBeams(Controls state);
00134 
00135 void printColourDescription(Colour colour);
00136 void printBlockDescription(Block block);
00137 #endif