TFC-Mentoring-Matters-Abstraction
main.cpp@0:0699eb71778e, 2014-07-16 (annotated)
- Committer:
- mrkeithcyr
- Date:
- Wed Jul 16 15:36:33 2014 +0000
- Revision:
- 0:0699eb71778e
First code commit.; Note known issue: in modes 1, 4, and 5 - The motor outputs are severely retarded by serial connection.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mrkeithcyr | 0:0699eb71778e | 1 | #include "mbed.h" // stuff for the program we used to write the code |
mrkeithcyr | 0:0699eb71778e | 2 | #include "TFC.h" // stuff for the board we're using on the car |
mrkeithcyr | 0:0699eb71778e | 3 | #include "Inits.h" // where to find the initialization directions |
mrkeithcyr | 0:0699eb71778e | 4 | #include "TheDetails.h" // this layer translates the lower level code to the |
mrkeithcyr | 0:0699eb71778e | 5 | // Freescale Mentoring Matters level of abstraction |
mrkeithcyr | 0:0699eb71778e | 6 | #include "Modes.h" // where to find our instructions for each mode |
mrkeithcyr | 0:0699eb71778e | 7 | |
mrkeithcyr | 0:0699eb71778e | 8 | /****** main() ***************************************************************** |
mrkeithcyr | 0:0699eb71778e | 9 | Purpose: This is the software engine that runs the race car. It is a set of |
mrkeithcyr | 0:0699eb71778e | 10 | commands that run from the beginning to the end and then start over each |
mrkeithcyr | 0:0699eb71778e | 11 | time for as long as the car is turned on. This is called an 'infinite loop'. |
mrkeithcyr | 0:0699eb71778e | 12 | Parameters: None |
mrkeithcyr | 0:0699eb71778e | 13 | Returns: The main function always returns an 'int'. |
mrkeithcyr | 0:0699eb71778e | 14 | *******************************************************************************/ |
mrkeithcyr | 0:0699eb71778e | 15 | int main() |
mrkeithcyr | 0:0699eb71778e | 16 | { |
mrkeithcyr | 0:0699eb71778e | 17 | // 'mode' will always equal a number to indicate the mode the code is using |
mrkeithcyr | 0:0699eb71778e | 18 | uint16_t mode; |
mrkeithcyr | 0:0699eb71778e | 19 | |
mrkeithcyr | 0:0699eb71778e | 20 | // First, we have to turn on the car and all of its motors and parts. |
mrkeithcyr | 0:0699eb71778e | 21 | WhatToTurnOn(); |
mrkeithcyr | 0:0699eb71778e | 22 | |
mrkeithcyr | 0:0699eb71778e | 23 | // This is the infinite loop for driving the race car starts here and runs |
mrkeithcyr | 0:0699eb71778e | 24 | // forever. |
mrkeithcyr | 0:0699eb71778e | 25 | for(;;) |
mrkeithcyr | 0:0699eb71778e | 26 | { |
mrkeithcyr | 0:0699eb71778e | 27 | // The loop determines what mode the car is in by reading the dip |
mrkeithcyr | 0:0699eb71778e | 28 | // switch number every time the loop starts over |
mrkeithcyr | 0:0699eb71778e | 29 | mode = DIP_SWITCH_SETTING; |
mrkeithcyr | 0:0699eb71778e | 30 | |
mrkeithcyr | 0:0699eb71778e | 31 | // Next, the loop runs the car in whichever mode the dip switches are |
mrkeithcyr | 0:0699eb71778e | 32 | // set for by 'switching' to that mode below. It only picks one mode |
mrkeithcyr | 0:0699eb71778e | 33 | // each time, runs that mode only once, and then starts the loop over |
mrkeithcyr | 0:0699eb71778e | 34 | // again by checking to see if the dip switches have been changed. |
mrkeithcyr | 0:0699eb71778e | 35 | |
mrkeithcyr | 0:0699eb71778e | 36 | // This code uses the files at the top of this page to find the |
mrkeithcyr | 0:0699eb71778e | 37 | // instructions for whichever mode it wants to go and run. |
mrkeithcyr | 0:0699eb71778e | 38 | switch(mode) |
mrkeithcyr | 0:0699eb71778e | 39 | { |
mrkeithcyr | 0:0699eb71778e | 40 | // Mode 0: Diagnostic that mode tests that the board is powered on. |
mrkeithcyr | 0:0699eb71778e | 41 | case 0: |
mrkeithcyr | 0:0699eb71778e | 42 | RunMode0(); |
mrkeithcyr | 0:0699eb71778e | 43 | break; |
mrkeithcyr | 0:0699eb71778e | 44 | |
mrkeithcyr | 0:0699eb71778e | 45 | // Mode 1: Garage mode that tests motor speed and direction. |
mrkeithcyr | 0:0699eb71778e | 46 | case 1: |
mrkeithcyr | 0:0699eb71778e | 47 | RunMode1(); |
mrkeithcyr | 0:0699eb71778e | 48 | break; |
mrkeithcyr | 0:0699eb71778e | 49 | |
mrkeithcyr | 0:0699eb71778e | 50 | // Mode 2: Garage mode that tests steering servo. |
mrkeithcyr | 0:0699eb71778e | 51 | case 2: |
mrkeithcyr | 0:0699eb71778e | 52 | RunMode2(); |
mrkeithcyr | 0:0699eb71778e | 53 | break; |
mrkeithcyr | 0:0699eb71778e | 54 | |
mrkeithcyr | 0:0699eb71778e | 55 | // Mode 3: Garage mode that tests the camera settings and input. |
mrkeithcyr | 0:0699eb71778e | 56 | case 3: |
mrkeithcyr | 0:0699eb71778e | 57 | RunMode3(); |
mrkeithcyr | 0:0699eb71778e | 58 | break; |
mrkeithcyr | 0:0699eb71778e | 59 | |
mrkeithcyr | 0:0699eb71778e | 60 | // Mode 4: Track mode with low speed settings for safer (slower) |
mrkeithcyr | 0:0699eb71778e | 61 | // initial track testing. |
mrkeithcyr | 0:0699eb71778e | 62 | case 4: |
mrkeithcyr | 0:0699eb71778e | 63 | RunMode4(); |
mrkeithcyr | 0:0699eb71778e | 64 | break; |
mrkeithcyr | 0:0699eb71778e | 65 | |
mrkeithcyr | 0:0699eb71778e | 66 | // Mode 5: Race mode with high speed settings used for faster actual |
mrkeithcyr | 0:0699eb71778e | 67 | // racing speeds. |
mrkeithcyr | 0:0699eb71778e | 68 | case 5: |
mrkeithcyr | 0:0699eb71778e | 69 | RunMode5(); |
mrkeithcyr | 0:0699eb71778e | 70 | break; |
mrkeithcyr | 0:0699eb71778e | 71 | |
mrkeithcyr | 0:0699eb71778e | 72 | // default mode activates diagnostic mode 0 to prevent unwanted |
mrkeithcyr | 0:0699eb71778e | 73 | // damage or corruption/loss of calibrated data. |
mrkeithcyr | 0:0699eb71778e | 74 | default: |
mrkeithcyr | 0:0699eb71778e | 75 | RunMode0(); |
mrkeithcyr | 0:0699eb71778e | 76 | break; |
mrkeithcyr | 0:0699eb71778e | 77 | } // end case |
mrkeithcyr | 0:0699eb71778e | 78 | } |
mrkeithcyr | 0:0699eb71778e | 79 | } |