Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: N5110 SRF02 beep mbed
obstacle.h
00001 00002 /** 00003 @file main.h 00004 @brief header file containing function prototypes, defines and variables 00005 @brief shows the different applications of the ultrasonic distance sensor combined with a temperature sensor 00006 @brief Last Revision combining all of the previous trials 00007 @author Mahlet Shimellis 00008 @date April-March 2015 00009 */ 00010 00011 #ifndef MAIN_H 00012 #define MAIN_H 00013 00014 /** 00015 @brief Below is the list of temperature sensor register adresses used 00016 @brief the first two are read and write adresses when ADD0 is connected to GROUND 00017 @brief the last two are common temerature registers 00018 */ 00019 00020 #define TMP102_R_ADD 0x91 00021 #define TMP102_W_ADD 0x90 00022 #define TEMP_REG 0x00 00023 #define CONFIG_REG 0x01 00024 00025 #include "mbed.h" 00026 00027 /** 00028 @namespace leds 00029 @brief This defines the mbed leds taht will be useful to detect error messages 00030 */ 00031 BusOut leds(LED4,LED3,LED2,LED1); 00032 00033 /** 00034 @namespace lcd 00035 @brief LCD dispaly pin connections to the mbed 00036 @brief Format used N5110(PinName pwrPin, PinName scePin, PinName rstPin, PinName dcPin, PinName mosiPin, PinName sclkPin, PinName ledPin) 00037 */ 00038 N5110 lcd(p5,p6,p7,p8,p11,p13,p21); 00039 00040 /** 00041 @namespace buzzer 00042 @brief Buzzer connection to mbed 00043 */ 00044 Beep buzzer(p26); 00045 00046 /** 00047 @namespace button 00048 @brief anolog input to the mbed 00049 */ 00050 InterruptIn button(p16); 00051 00052 /** 00053 @namespace srf 00054 @brief SRF02 ultrasonic distance sensor I2C connection to mbed 00055 @brief Format srf(SDA pin, SCL pin) 00056 */ 00057 SRF02 srf(p28, p27); 00058 00059 /** 00060 @namespace tmp102 00061 @brief TMP102 temperature sensor I2C connection to mbed 00062 @brief format tmp102(SDA pin, SCL pin) 00063 */ 00064 //I2C tmp102(p9,p10); 00065 00066 /** 00067 @namespace red 00068 @brief Red LED PwmOut connection to mbed 00069 */ 00070 PwmOut red(p22); 00071 00072 /** 00073 @namespace yellow 00074 @brief Yellow LED PwmOut connection to mbed 00075 */ 00076 PwmOut yellow(p23); 00077 00078 /** 00079 @namespace green 00080 @brief Green LED PwmOut connection to mbed 00081 */ 00082 PwmOut green(p24); 00083 00084 00085 00086 Ticker timer; ///global timer 00087 Ticker measure_ticker; 00088 Timer measure; 00089 int measureFlag=0; /*!< measure flag set in ISR for intial temperature and distance measurements ??? ticker timer */ 00090 double distance; /*!< distance value updated from SRF02 measurements */ 00091 float temperature; /*!<temperature value updated from TMP102 measurements*/ 00092 float soundSpeed; /*!<float for speed of sound */ 00093 float soundTimeDelay; /*!<float time delay value for sending and receiving sound signal */ 00094 Ticker temperature_ticker; 00095 00096 /** 00097 @brief defines the high flag state for the measurement flag 00098 */ 00099 void measureExpired (); 00100 00101 /** 00102 @bSets the error signaling for the mbed connections mainly I2C when the acknowlegment bit is not received 00103 @param code - integer to classify error type 00104 */ 00105 void error(int code); 00106 00107 00108 00109 00110 /** 00111 Initialises the temperature sensor 00112 */ 00113 void initTMP102(); 00114 00115 /** 00116 Performs the temperature measurement 00117 @returns the temperature value with a 0.0625 resolution 00118 */ 00119 float getTemperature(); 00120 00121 00122 /** 00123 Calculates the speed of sound from the measured temperature 00124 @param temperature - float measured temperature value 00125 @returns the value of the speed of sound for each specific temeprature value 00126 */ 00127 float calcSoundSpeed (float temperature); 00128 00129 00130 /** 00131 Calculates the delay between transmission and emission of the sound from the ultrasonic distance sensor 00132 @param distance - integer measured distance value 00133 @param soundSpeed - float calculated speed of sound value 00134 @returns timeDelay - float delay between transmission and reception of the sound after reflecting on the object for which the distance has been measured 00135 */ 00136 float calcSoundTimeDelay (int distance, float soundSpeed); 00137 00138 00139 00140 /** 00141 ////////////////////PART 2 - Distance Update and Speed /////////////////////////////////// 00142 @brief in this section 00143 @ brief variables 00144 @brief ticker variable 00145 @brief timer expired function 00146 @brief distance update and storage function 00147 */ 00148 00149 00150 Ticker update_ticker; 00151 Ticker update_ticker_two; 00152 int updateFlag=0; 00153 int r=0; 00154 float newDistance; /*!< new distance value updated from SRF02 measurements after each timer delay */ 00155 float lastDistance;/*!< for eaxh new distance value updated from SRF02 measurements after each timer delay, this is the stored previous distance value */ 00156 float updateDelay=0; /*!< time delay between each distance value update */ 00157 00158 ///Ticker update_ticker; 00159 //Ticker timer; 00160 00161 /** 00162 Defines the high flag state for the distance measurement update flag 00163 */ 00164 void upadteExpired(); 00165 00166 /** 00167 Stores the previous distance in the lastDistance variable and updates the newDistance variable 00168 @returns the lastDistance value of the previous measurement 00169 @returns the newDistance value from the new measurement 00170 */ 00171 void update_distance_new(); 00172 00173 00174 00175 /** 00176 /////////////////////////////////////////PART 3 - Distance Range Alert/////////////////////////////////////////// 00177 @brief in this section 00178 @brief define min, max, maxState 00179 @brief define variables (state variables, buzzerFrequency) 00180 @brief define updateState function protoype 00181 */ 00182 00183 #define MAX 200 00184 #define MIN 20 00185 #define maxState 4 00186 00187 /** 00188 @brief Timing elements for the range differentiation module of the distance sensor 00189 */ 00190 Ticker range_ticker; 00191 Timer range; 00192 int rangeFlag =0; /*!< range flag set in ISR */ 00193 00194 int currentState =0; /*!<integer from 0 to 4 that defines the current state of the FSM*/ 00195 int rangeState =0; /*!<integer from 0 to 4 that defines the range to which belongs the measured distance between MIN and MAX*/ 00196 00197 float buzzerFrequency =0; /*!<float that defines the frequency of the buzzer depending on the distance range. higher frequencies as we get closer to the object. output of the FSM structure*/ 00198 00199 /** 00200 @brief defines the high flag state for the measurement flag 00201 */ 00202 void rangeExpired(); 00203 00204 /** 00205 function that defines the input of the FSM depending on the distance range from MAX to MIN 00206 @param distance - integer measured value by the SRF02 sensor and to be classified as part of a set of five ranges from MAX to MIN 00207 @returns rangeState - integer from 0 to 4. defined depending on the distance range in whcih the measured distance belongs 00208 @returns currentState - integer from 0 to 4. depending on the value of the rangeState, the actual current state and the FSM nextState from the structure definition 00209 */ 00210 void updateState(); 00211 00212 00213 00214 /** 00215 @brief PART 4 - Beam Pattern hard 00216 @brief in this section 00217 @brief define variables (angle related variables, counter, distance related variables) 00218 @brief define trigonometric function protoptypes 00219 @brief define drawing function prototypes 00220 */ 00221 00222 Ticker beam_ticker; 00223 Timer beam; 00224 int beamFlag=0; 00225 00226 /** 00227 @brief defines the high flag state for the beam flag 00228 */ 00229 void beamExpired(); 00230 00231 int radius =0; 00232 00233 double angleDegrees =0; /*!<initial angles in degrees*/ 00234 double angleRadians=0; /*!<angles in radians after conversion*/ 00235 double a=0; 00236 int z=0; ///counter 00237 double d=0; 00238 float lateralDistance=0; 00239 float h=0; ///hypothenuse 00240 00241 00242 /** 00243 @brief function that converts angle units 00244 @param angleDegrees - double 00245 @returns angleRadians 00246 */ 00247 double convertDegrees (double angleDegrees); 00248 00249 /** 00250 function that draws a semi-circle depending on the distance measured 00251 @param radius - equal to the disance measured 00252 @brief center at (WIDTH/2,1) on the LCD 00253 */ 00254 void drawSemiCircle(); 00255 00256 /** 00257 function that shifts through angles of the beam pattern 00258 @param l- lateral distance for angle a 00259 @param h - hypothenuse distance for angle a 00260 */ 00261 void drawBeamLines (float lateralDistance, float h); 00262 00263 /** 00264 function that calculates the lateral distance between the sensor center and object at angle a 00265 @param a - double angle between center if sensor and object detected 00266 @param d - double shortest right angle distance between center of center and object detected. this is the distance measured directly in front of the sensor 00267 @returns - value of the lateral distance between sensor center line and beam at angle a from center 00268 */ 00269 double lat(double a, double d); 00270 00271 /** 00272 @brief function that calculates the hypothenuse distance between the sensor center and object at angle a - this is the longest distance 00273 @param a - double angle between center if sensor and object detected 00274 @param d - double shortest right angle distance between center of center and object detected. this is the distance measured directly in front of the sensor 00275 @returns - value of the hypothenuse between sensor center line and beam at angle a from center 00276 */ 00277 double hyp(double a, double d); 00278 00279 00280 00281 /** 00282 ///////////////////////////////// PART 5 - the Wall Follower Simulation/////////////////////////// 00283 @brief in this section 00284 @brief buzzer and led tickers 00285 @brief buzzer functions prototype 00286 @brief led functions prototype 00287 @brief counter integer variables 00288 @breif movemetn and drawing functions prototype 00289 */ 00290 00291 00292 int wallFlag=0; 00293 Timer wall_timer; 00294 Ticker wall_ticker; 00295 /** 00296 Defines the high flag state for the beam flag 00297 */ 00298 void wallExpired(); 00299 00300 /** 00301 @brief set of buzzer tickers depending on the direction of movement and signal given 00302 @brief zero move forward 00303 @brief one turn left 00304 @brief two turn left and move forward 00305 @brief three turn right 00306 @brief four turn right and move forward 00307 @brief five stop, dead end 00308 */ 00309 Ticker beep_ticker_zero; 00310 Ticker beep_ticker_one; 00311 Ticker beep_ticker_two; 00312 Ticker beep_ticker_three; 00313 Ticker beep_ticker_four; 00314 Ticker beep_ticker_five; 00315 00316 00317 /** 00318 @brief set of LED tickers 00319 */ 00320 Ticker toggle_green_ticker; 00321 Ticker toggle_yellow_ticker; 00322 Ticker toggle_red_ticker; 00323 00324 00325 /** 00326 @brief Set of integer pixel counters to define and kepp track of the movement along the maze 00327 */ 00328 int k=0; /*!<integer for stage 0 move forward k from 0 to 22 pixel points*/ 00329 int l=0;/*!<integer for stage 1 turn left and move forward one l from 0 to 64 pixel points*/ 00330 int m=0;/*!<integer for stage 2 turn left and move forward two m from 0 to 16 pixel points*/ 00331 int n=0;/*!<integer for stage 3 turn right and move forward n from 0 to 78 pixel points*/ 00332 int pix=0;/*!<integer that keeps track of the sum of all the counter integers as the pixel moves along the maze. helps keep track of the location of the pixel */ 00333 00334 00335 int buttonCounter; /*!<integer 0 to 4 counts the number of times the button has been pressed*/ 00336 int buttonFlag = 0;/*!<button flag set in ISR*/ 00337 00338 /** 00339 Manages the order of displays on the screen and synchronises it to the number of button presses 00340 */ 00341 void manageScreen(); 00342 00343 /** 00344 Counts the pixel step in the forward movement 00345 @param k - integer counter from 0 to 22 00346 @returns pix - integer counter incremented stores values from 0 to k 00347 */ 00348 void moveForward(); 00349 00350 /** 00351 Counts the pixel step in the turnLeftForward_one movement 00352 @param l - integer counter from 0 to 64 00353 @returns pix - integer counter incremented stores values from k to k+l 00354 */ 00355 void turnLeftForward_one(); 00356 00357 /** 00358 Counts the pixel step in the turnLeftForward_two movement 00359 @param m - integer counter from 0 to 16 00360 @returns pix - integer counter incremented stores values from k+l to k+l+m 00361 */ 00362 void turnLeftForward_two(); 00363 00364 /** 00365 Counts the pixel step in the turnLeftForward_two movement 00366 @param n - integer counter from 0 to 78 00367 @returns pix - integer counter incremented stores values from k+l+m to k+l+m+n 00368 */ 00369 void turnRightForward(); 00370 00371 /** 00372 Controls intial beep zero move forward 00373 @param sound_zero - integer set frequency value, introduced as local variable for function 00374 @param time_zero - float set time value for each buzz, introduced as local variable for function 00375 */ 00376 void beep_zero(); 00377 00378 /** 00379 Turns on beep one Turn Left 00380 @param sound_one - integer set frequency value , local variable for function 00381 @param time_one - float set time value for each buzz , local variable for function 00382 */ 00383 void beep_one(); 00384 00385 /** 00386 Turns on beep two Trun Left and move Forward 00387 @param sound_two - integer set frequency value, local variable for function 00388 @param time_two - float set time value for each buzz, local variable for function 00389 */ 00390 void beep_two(); 00391 00392 /** 00393 Turns on beep three Turn Right 00394 @param sound_three - integer set frequency value, local variable for function 00395 @param time_three - float set time value for each buzz, local variable for function 00396 */ 00397 void beep_three(); 00398 00399 /** 00400 Turns on beep four Trun Right and move Forward 00401 @param sound_four - integer set frequency value, local variable for function 00402 @param time_four - float set time value for each buzz, local variable for function 00403 */ 00404 void beep_four(); 00405 00406 /** 00407 Turns on beep five Stop Dead End 00408 @param sound_five - integer set frequency value, local variable for function 00409 @param time_five - float set time value for each buzz, local variable for function 00410 */ 00411 void beep_five(); 00412 00413 00414 /** 00415 @brief funciton that toggles Red LED 00416 @brief controls PwmOut pin 00417 */ 00418 void toggle_red(); 00419 00420 /** 00421 @brief funciton that toggles Yellow LED 00422 @brief controls PwmOut pin 00423 */ 00424 void toggle_yellow(); 00425 00426 /** 00427 @brief funciton that toggles Green LED 00428 @brief controls PwmOut pin 00429 */ 00430 void toggle_green(); 00431 00432 /** 00433 Controls the pixel movement along the maze 00434 Combines all of the different stages/sub-movements 00435 Combines the buzzer and led tickers for appropriate and timely signaling 00436 @param pix - integer that sums the movement cnouters and gives an idea of the location of the pixel 00437 @returns buzzer sound - output sound signal with frequency depending on the location 00438 @returns LED light - output light signal with color dependent on message/location (go forward, stop etc.) 00439 */ 00440 void move(); 00441 00442 /** 00443 Draws the sample structure of the maze to reflect the wall follower movement technique 00444 Combines drawRect functions with pre-set dimensions 00445 @param x,y, width, height 00446 */ 00447 void drawMaze(); 00448 00449 00450 00451 #endif
Generated on Wed Jul 13 2022 21:28:43 by
1.7.2