TFC-Mentoring-Matters-Abstraction

Dependencies:   FRDM-TFC

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?

UserRevisionLine numberNew contents of line
mrkeithcyr 0:0699eb71778e 1 #include "mbed.h"
mrkeithcyr 0:0699eb71778e 2 #include "TFC.h"
mrkeithcyr 0:0699eb71778e 3
mrkeithcyr 0:0699eb71778e 4 /****** MENTORING MATTERS LAYER DEFINITIONS ******/
mrkeithcyr 0:0699eb71778e 5
mrkeithcyr 0:0699eb71778e 6 #define DIP_SWITCH_SETTING (TFC_GetDIP_Switch()&0x07)
mrkeithcyr 0:0699eb71778e 7 #define CHECK_POT_1_VALUE TFC_ReadPot(0);
mrkeithcyr 0:0699eb71778e 8 #define CHECK_POT_2_VALUE TFC_ReadPot(1);
mrkeithcyr 0:0699eb71778e 9
mrkeithcyr 0:0699eb71778e 10 #define DISABLE_THE_MOTORS TFC_HBRIDGE_DISABLE
mrkeithcyr 0:0699eb71778e 11 #define ENABLE_THE_MOTORS TFC_HBRIDGE_ENABLE
mrkeithcyr 0:0699eb71778e 12
mrkeithcyr 0:0699eb71778e 13 #define TURN_ON_LED_0 TFC_BAT_LED0_ON
mrkeithcyr 0:0699eb71778e 14 #define TURN_ON_LED_1 TFC_BAT_LED1_ON
mrkeithcyr 0:0699eb71778e 15 #define TURN_ON_LED_2 TFC_BAT_LED2_ON
mrkeithcyr 0:0699eb71778e 16 #define TURN_ON_LED_3 TFC_BAT_LED3_ON
mrkeithcyr 0:0699eb71778e 17
mrkeithcyr 0:0699eb71778e 18 #define TURN_OFF_LED_0 TFC_BAT_LED0_OFF
mrkeithcyr 0:0699eb71778e 19 #define TURN_OFF_LED_1 TFC_BAT_LED1_OFF
mrkeithcyr 0:0699eb71778e 20 #define TURN_OFF_LED_2 TFC_BAT_LED2_OFF
mrkeithcyr 0:0699eb71778e 21 #define TURN_OFF_LED_3 TFC_BAT_LED3_OFF
mrkeithcyr 0:0699eb71778e 22
mrkeithcyr 0:0699eb71778e 23 #define BUTTON_A_IS_PRESSED TFC_PUSH_BUTTON_0_PRESSED
mrkeithcyr 0:0699eb71778e 24 #define BUTTON_B_IS_PRESSED TFC_PUSH_BUTTON_1_PRESSED
mrkeithcyr 0:0699eb71778e 25
mrkeithcyr 0:0699eb71778e 26 #define CLOCK_NUMBER_1 TFC_Ticker[0]
mrkeithcyr 0:0699eb71778e 27
mrkeithcyr 0:0699eb71778e 28 #define SERVO_NUMBER_1 0
mrkeithcyr 0:0699eb71778e 29
mrkeithcyr 0:0699eb71778e 30 #define CAMERA_READY TFC_LineScanImageReady
mrkeithcyr 0:0699eb71778e 31 #define LINE_IMAGE terminalMode()
mrkeithcyr 0:0699eb71778e 32 #define DEPENDS_ON_DIP_SWITCH_4 terminalMode()
mrkeithcyr 0:0699eb71778e 33 #define THE_PIECE_OF_IMAGE TFC_LineScanImage0
mrkeithcyr 0:0699eb71778e 34 #define LOOKS_IMPORTANT (4096 / 20)
mrkeithcyr 0:0699eb71778e 35 #define USE_FAKE_IMAGES debugFakeMode
mrkeithcyr 0:0699eb71778e 36
mrkeithcyr 0:0699eb71778e 37 /*************************************************/
mrkeithcyr 0:0699eb71778e 38
mrkeithcyr 0:0699eb71778e 39 extern bool debugFakeMode;
mrkeithcyr 0:0699eb71778e 40
mrkeithcyr 0:0699eb71778e 41 /****** terminalMode() *********************************************************
mrkeithcyr 0:0699eb71778e 42 Purpose: Checks the current setting of dip switch 4.
mrkeithcyr 0:0699eb71778e 43 Parameters: None
mrkeithcyr 0:0699eb71778e 44 Returns: True if dip switch 4 is set.
mrkeithcyr 0:0699eb71778e 45 *******************************************************************************/
mrkeithcyr 0:0699eb71778e 46 bool terminalMode();
mrkeithcyr 0:0699eb71778e 47
mrkeithcyr 0:0699eb71778e 48 /****** GiveDriveSettingsToMotors() ********************************************
mrkeithcyr 0:0699eb71778e 49 Purpose: Simply passes parameters to TFC_SetMotorPWM().
mrkeithcyr 0:0699eb71778e 50 Parameters: The desired settings for each of the two motors
mrkeithcyr 0:0699eb71778e 51 Returns: None
mrkeithcyr 0:0699eb71778e 52 *******************************************************************************/
mrkeithcyr 0:0699eb71778e 53 void GiveDriveSettingsToMotors(float right_drive_setting,
mrkeithcyr 0:0699eb71778e 54 float left_drive_setting);
mrkeithcyr 0:0699eb71778e 55
mrkeithcyr 0:0699eb71778e 56 /****** GiveSteeringSettingTo() ************************************************
mrkeithcyr 0:0699eb71778e 57 Purpose: Simply passes parameters to TFC_SetServo().
mrkeithcyr 0:0699eb71778e 58 Parameters: The servo number and the steering setting.
mrkeithcyr 0:0699eb71778e 59 Returns: None
mrkeithcyr 0:0699eb71778e 60 *******************************************************************************/
mrkeithcyr 0:0699eb71778e 61 void GiveSteeringSettingTo(uint8_t ServoNumber, float Position);
mrkeithcyr 0:0699eb71778e 62
mrkeithcyr 0:0699eb71778e 63 /****** ResetCamera() **********************************************************
mrkeithcyr 0:0699eb71778e 64 Purpose: This function resets the camera after an image has been used.
mrkeithcyr 0:0699eb71778e 65 Parameters: None
mrkeithcyr 0:0699eb71778e 66 Returns: None
mrkeithcyr 0:0699eb71778e 67 *******************************************************************************/
mrkeithcyr 0:0699eb71778e 68 void ResetCamera();
mrkeithcyr 0:0699eb71778e 69
mrkeithcyr 0:0699eb71778e 70 /****** ResetMaximumLightReading() *********************************************
mrkeithcyr 0:0699eb71778e 71 Purpose: Resets the maximum light intensity variable
mrkeithcyr 0:0699eb71778e 72 Parameters: None
mrkeithcyr 0:0699eb71778e 73 Returns: None
mrkeithcyr 0:0699eb71778e 74 *******************************************************************************/
mrkeithcyr 0:0699eb71778e 75 void ResetMaximumLightReading();
mrkeithcyr 0:0699eb71778e 76
mrkeithcyr 0:0699eb71778e 77 /****** ResetMinimumLightReading() *********************************************
mrkeithcyr 0:0699eb71778e 78 Purpose: Resets the minimum light intensity variable
mrkeithcyr 0:0699eb71778e 79 Parameters: None
mrkeithcyr 0:0699eb71778e 80 Returns: None
mrkeithcyr 0:0699eb71778e 81 *******************************************************************************/
mrkeithcyr 0:0699eb71778e 82 void ResetMinimumLightReading();
mrkeithcyr 0:0699eb71778e 83
mrkeithcyr 0:0699eb71778e 84 /****** grabCameraFrame() ******************************************************
mrkeithcyr 0:0699eb71778e 85 Purpose: This function gets a scan from the camera or fakes a scan from the
mrkeithcyr 0:0699eb71778e 86 camera. There are different types of fake scans that can be used to test
mrkeithcyr 0:0699eb71778e 87 other parts of the car to see how the car reacts to certain types of line
mrkeithcyr 0:0699eb71778e 88 conditions.
mrkeithcyr 0:0699eb71778e 89 Parameters: None
mrkeithcyr 0:0699eb71778e 90 Returns: None
mrkeithcyr 0:0699eb71778e 91 *******************************************************************************/
mrkeithcyr 0:0699eb71778e 92 void grabCameraFrame();
mrkeithcyr 0:0699eb71778e 93
mrkeithcyr 0:0699eb71778e 94 /****** GetTheImageToUse() *****************************************************
mrkeithcyr 0:0699eb71778e 95 Purpose: Retrieves whichever image we are supposed to use.
mrkeithcyr 0:0699eb71778e 96 Parameters: None
mrkeithcyr 0:0699eb71778e 97 Returns: None
mrkeithcyr 0:0699eb71778e 98 *******************************************************************************/
mrkeithcyr 0:0699eb71778e 99 void GetTheImageToUse();
mrkeithcyr 0:0699eb71778e 100
mrkeithcyr 0:0699eb71778e 101 /****** GetCameraData() *****************************************************
mrkeithcyr 0:0699eb71778e 102 Purpose: Processes an image to get the camera's raw data.
mrkeithcyr 0:0699eb71778e 103 Parameters: None
mrkeithcyr 0:0699eb71778e 104 Returns: None
mrkeithcyr 0:0699eb71778e 105 *******************************************************************************/
mrkeithcyr 0:0699eb71778e 106 void GetCameraData();
mrkeithcyr 0:0699eb71778e 107
mrkeithcyr 0:0699eb71778e 108 /****** derivativeLineScan() ***************************************************
mrkeithcyr 0:0699eb71778e 109 Purpose: Calculates derivative of line scan data.
mrkeithcyr 0:0699eb71778e 110 Parameters: Pointer to current image scan data, and a pointer to where you want
mrkeithcyr 0:0699eb71778e 111 the derivative to be output.
mrkeithcyr 0:0699eb71778e 112 Returns: None
mrkeithcyr 0:0699eb71778e 113 *******************************************************************************/
mrkeithcyr 0:0699eb71778e 114 void derivativeLineScan(uint16_t* LineScanDataIn, float* DerivLineScanDataOut);
mrkeithcyr 0:0699eb71778e 115
mrkeithcyr 0:0699eb71778e 116 /****** printAdjustLightsData() ************************************************
mrkeithcyr 0:0699eb71778e 117 Purpose: Prints out light intensity data to the terminal.
mrkeithcyr 0:0699eb71778e 118 Parameters: None
mrkeithcyr 0:0699eb71778e 119 Returns: None
mrkeithcyr 0:0699eb71778e 120 *******************************************************************************/
mrkeithcyr 0:0699eb71778e 121 void printAdjustLightsData();
mrkeithcyr 0:0699eb71778e 122
mrkeithcyr 0:0699eb71778e 123 /****** adjustLights() *********************************************************
mrkeithcyr 0:0699eb71778e 124 Purpose: Adjusts the line found threshold for different lighting conditions.
mrkeithcyr 0:0699eb71778e 125 Parameters: None
mrkeithcyr 0:0699eb71778e 126 Returns: None
mrkeithcyr 0:0699eb71778e 127 *******************************************************************************/
mrkeithcyr 0:0699eb71778e 128 void adjustLights();
mrkeithcyr 0:0699eb71778e 129
mrkeithcyr 0:0699eb71778e 130 /****** FindTheLine() *********************************************************
mrkeithcyr 0:0699eb71778e 131 Purpose: Simply a link to whichever version of the edge-finding functions you
mrkeithcyr 0:0699eb71778e 132 choose.
mrkeithcyr 0:0699eb71778e 133 Parameters: None
mrkeithcyr 0:0699eb71778e 134 Returns: None
mrkeithcyr 0:0699eb71778e 135 *******************************************************************************/
mrkeithcyr 0:0699eb71778e 136 void FindTheLine();
mrkeithcyr 0:0699eb71778e 137
mrkeithcyr 0:0699eb71778e 138 /****** findEdges_v2() *********************************************************
mrkeithcyr 0:0699eb71778e 139 Purpose: This function is used to determine where the edges of the line are
mrkeithcyr 0:0699eb71778e 140 found in the camera image. The location of the line edges is printed out to
mrkeithcyr 0:0699eb71778e 141 the terminal if terminal output has been enabled.
mrkeithcyr 0:0699eb71778e 142 Parameters: Pointer to the array of line scan data derivatives
mrkeithcyr 0:0699eb71778e 143 Returns: None
mrkeithcyr 0:0699eb71778e 144 *******************************************************************************/
mrkeithcyr 0:0699eb71778e 145 void findEdges_v2(float* derivLineScanData);
mrkeithcyr 0:0699eb71778e 146
mrkeithcyr 0:0699eb71778e 147 /****** reviewEdges() **********************************************************
mrkeithcyr 0:0699eb71778e 148 Purpose: This function check which edges were found and decides whether or not
mrkeithcyr 0:0699eb71778e 149 the line has been found. Its results are printed out to the terminal if
mrkeithcyr 0:0699eb71778e 150 terminal output has been enabled.
mrkeithcyr 0:0699eb71778e 151 Parameters: None
mrkeithcyr 0:0699eb71778e 152 Returns: None
mrkeithcyr 0:0699eb71778e 153 *******************************************************************************/
mrkeithcyr 0:0699eb71778e 154 void reviewEdges();
mrkeithcyr 0:0699eb71778e 155
mrkeithcyr 0:0699eb71778e 156 /****** PrintOutSomeData() *****************************************************
mrkeithcyr 0:0699eb71778e 157 Purpose: Prints out a selection of Track mode data after image processing.
mrkeithcyr 0:0699eb71778e 158 Parameters: None
mrkeithcyr 0:0699eb71778e 159 Returns: None
mrkeithcyr 0:0699eb71778e 160 *******************************************************************************/
mrkeithcyr 0:0699eb71778e 161 void PrintOutSomeData();
mrkeithcyr 0:0699eb71778e 162
mrkeithcyr 0:0699eb71778e 163 /****** ActOnTrackStatus() *****************************************************
mrkeithcyr 0:0699eb71778e 164 Purpose: This function decides what to do next based on the current track
mrkeithcyr 0:0699eb71778e 165 status. Its results are printed out to the terminal if terminal output has
mrkeithcyr 0:0699eb71778e 166 been enabled.
mrkeithcyr 0:0699eb71778e 167 Parameters: None
mrkeithcyr 0:0699eb71778e 168 Returns: None
mrkeithcyr 0:0699eb71778e 169 *******************************************************************************/
mrkeithcyr 0:0699eb71778e 170 void ActOnTrackStatus();
mrkeithcyr 0:0699eb71778e 171
mrkeithcyr 0:0699eb71778e 172 /****** feedbackLights() *******************************************************
mrkeithcyr 0:0699eb71778e 173 Purpose: Turns on board LED's to indicate specific status for debugging
mrkeithcyr 0:0699eb71778e 174 purposes.
mrkeithcyr 0:0699eb71778e 175 Parameters: None
mrkeithcyr 0:0699eb71778e 176 Returns: None
mrkeithcyr 0:0699eb71778e 177 *******************************************************************************/
mrkeithcyr 0:0699eb71778e 178 void feedbackLights();
mrkeithcyr 0:0699eb71778e 179
mrkeithcyr 0:0699eb71778e 180 /****** SpeedControl() *********************************************************
mrkeithcyr 0:0699eb71778e 181 Purpose: This function determines the speed settings in the code and set on the
mrkeithcyr 0:0699eb71778e 182 board itself. It then offers multiple ways to apply those settings to the
mrkeithcyr 0:0699eb71778e 183 actual speed output to the wheels.
mrkeithcyr 0:0699eb71778e 184 Its results are printed out to the terminal if terminal output has been
mrkeithcyr 0:0699eb71778e 185 enabled.
mrkeithcyr 0:0699eb71778e 186 Parameters: None
mrkeithcyr 0:0699eb71778e 187 Returns: None
mrkeithcyr 0:0699eb71778e 188 *******************************************************************************/
mrkeithcyr 0:0699eb71778e 189 void SpeedControl();
mrkeithcyr 0:0699eb71778e 190
mrkeithcyr 0:0699eb71778e 191 /****** Drive() ****************************************************************
mrkeithcyr 0:0699eb71778e 192 Purpose: This is the function that enables the motors to run. It monitors the
mrkeithcyr 0:0699eb71778e 193 pressing of buttons A and B to start and stop the car. It also monitors for
mrkeithcyr 0:0699eb71778e 194 emergency stop conditions and will turn off the motors to stop the car if
mrkeithcyr 0:0699eb71778e 195 necessary.
mrkeithcyr 0:0699eb71778e 196 Parameters: None
mrkeithcyr 0:0699eb71778e 197 Returns: None
mrkeithcyr 0:0699eb71778e 198 *******************************************************************************/
mrkeithcyr 0:0699eb71778e 199 void Drive();
mrkeithcyr 0:0699eb71778e 200 /****** printLineScanData() ****************************************************
mrkeithcyr 0:0699eb71778e 201 Purpose: This function prints out the camera data to the terminal for use in
mrkeithcyr 0:0699eb71778e 202 testing and debugging.
mrkeithcyr 0:0699eb71778e 203 Parameters: Takes the most recent scan returned by the camera.
mrkeithcyr 0:0699eb71778e 204 Returns: None
mrkeithcyr 0:0699eb71778e 205 *******************************************************************************/
mrkeithcyr 0:0699eb71778e 206 void printLineScanData(uint16_t* LineScanData);
mrkeithcyr 0:0699eb71778e 207
mrkeithcyr 0:0699eb71778e 208 /****** printDerivLineScanData() ***********************************************
mrkeithcyr 0:0699eb71778e 209 Purpose: This function prints out the line scan derivative data to the terminal
mrkeithcyr 0:0699eb71778e 210 for use in testing and debugging.
mrkeithcyr 0:0699eb71778e 211 Parameters: Takes the array of line scan data derivatives.
mrkeithcyr 0:0699eb71778e 212 Returns: None
mrkeithcyr 0:0699eb71778e 213 *******************************************************************************/
mrkeithcyr 0:0699eb71778e 214 void printDerivLineScanData(float* derivLineScanData);
mrkeithcyr 0:0699eb71778e 215
mrkeithcyr 0:0699eb71778e 216 /****** printEdgesFound() ******************************************************
mrkeithcyr 0:0699eb71778e 217 Purpose: This function prints the line edge data to the terminal for line use in
mrkeithcyr 0:0699eb71778e 218 debugging.
mrkeithcyr 0:0699eb71778e 219 Parameters: None
mrkeithcyr 0:0699eb71778e 220 Returns: None
mrkeithcyr 0:0699eb71778e 221 *******************************************************************************/
mrkeithcyr 0:0699eb71778e 222 void printEdgesFound();
mrkeithcyr 0:0699eb71778e 223
mrkeithcyr 0:0699eb71778e 224 /****** SteeringControl() ******************************************************
mrkeithcyr 0:0699eb71778e 225 Purpose: This function decides how much to turn the front wheels to keep the car
mrkeithcyr 0:0699eb71778e 226 on course.
mrkeithcyr 0:0699eb71778e 227 The CurrentSteerSetting variable is set here.
mrkeithcyr 0:0699eb71778e 228 Its results are printed out to the terminal if terminal output has been
mrkeithcyr 0:0699eb71778e 229 enabled.
mrkeithcyr 0:0699eb71778e 230 Parameters: None
mrkeithcyr 0:0699eb71778e 231 Returns: None
mrkeithcyr 0:0699eb71778e 232 *******************************************************************************/
mrkeithcyr 0:0699eb71778e 233 void SteeringControl();
mrkeithcyr 0:0699eb71778e 234
mrkeithcyr 0:0699eb71778e 235 /****** Steer() ****************************************************************
mrkeithcyr 0:0699eb71778e 236 Purpose: Sets the steering servo output to the value necessary for the current
mrkeithcyr 0:0699eb71778e 237 steering needs. It also checks the value needed to make sure the board isn't
mrkeithcyr 0:0699eb71778e 238 trying to steer harder than the wheels can turn.
mrkeithcyr 0:0699eb71778e 239 Parameters: None
mrkeithcyr 0:0699eb71778e 240 Returns: None
mrkeithcyr 0:0699eb71778e 241 *******************************************************************************/
mrkeithcyr 0:0699eb71778e 242 void Steer();
mrkeithcyr 0:0699eb71778e 243
mrkeithcyr 0:0699eb71778e 244 /****** GoSlow() ***************************************************************
mrkeithcyr 0:0699eb71778e 245 Purpose: Sets the DoRisky variable to false
mrkeithcyr 0:0699eb71778e 246 Parameters: None
mrkeithcyr 0:0699eb71778e 247 Returns: None
mrkeithcyr 0:0699eb71778e 248 *******************************************************************************/
mrkeithcyr 0:0699eb71778e 249 void GoSlow();
mrkeithcyr 0:0699eb71778e 250
mrkeithcyr 0:0699eb71778e 251 /****** GoFast() ***************************************************************
mrkeithcyr 0:0699eb71778e 252 Purpose: Sets the doRisky variable to true
mrkeithcyr 0:0699eb71778e 253 Parameters: None
mrkeithcyr 0:0699eb71778e 254 Returns: None
mrkeithcyr 0:0699eb71778e 255 *******************************************************************************/
mrkeithcyr 0:0699eb71778e 256 void GoFast();