Austin Community College initial line follower program for Freescale car. This is based upon the FRDM-TFC code at mbed.org.
Fork of FRDM-TFC by
Austin Community College - Initial Specs for FRDM-TFC line following car.
This uses the fine library by ELI HUGHES.
Our goal here is to provide the simplest line-follower as a quick car checkout.
First, we limit the run duration for the car, so that you can catch it, if necessary. Right DIP switch (4) sets run time. 0 => 5 sec, 1 => 10 sec.
We provide simple speed selection with the other three DIP switches. I recommend 001 as the slowest real speed, (000 is stop, of course). DIP switches 1 2 3 make a 3 bit speed. 1 is msb, 3 is lsb
The car won't start until you press and release the driver's side PB. Left PB (TFC_PUSH_BUTTON_1) is permissive GO on release using left 3 DIPs for speed 0-7.
The car will stop when the passenger side PB is pressed. Right PB is STOP - TFC_PUSH_BUTTON_0
TFC_Ticker[3] is our run time counter. Like the Code Warrior edition, we use msec tickers.
Left (Driver side) trim pot 1 can be used to trim static steering servo Right trim pot 0 can be used to offset line camera
Back LED reflects drive motor status. The top three are not currently used.
main.cpp@4:8a4a3fc59e57, 2013-09-04 (annotated)
- Committer:
- redxeth
- Date:
- Wed Sep 04 02:48:20 2013 +0000
- Revision:
- 4:8a4a3fc59e57
- Parent:
- 3:23cce037011f
- Child:
- 5:9d36b4c896e1
Made corrections to demo3 to parse linescandata in proper order.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
emh203 | 3:23cce037011f | 1 | #include "mbed.h" |
emh203 | 3:23cce037011f | 2 | #include "TFC.h" |
emh203 | 3:23cce037011f | 3 | |
emh203 | 3:23cce037011f | 4 | |
emh203 | 3:23cce037011f | 5 | //This macro is to maintain compatibility with Codewarrior version of the sample. This version uses the MBED libraries for serial port access |
emh203 | 3:23cce037011f | 6 | Serial PC(USBTX,USBRX); |
emh203 | 3:23cce037011f | 7 | |
emh203 | 3:23cce037011f | 8 | #define TERMINAL_PRINTF PC.printf |
emh203 | 3:23cce037011f | 9 | |
emh203 | 3:23cce037011f | 10 | |
emh203 | 3:23cce037011f | 11 | //This ticker code is used to maintain compability with the Codewarrior version of the sample. This code uses an MBED Ticker for background timing. |
emh203 | 3:23cce037011f | 12 | |
emh203 | 3:23cce037011f | 13 | #define NUM_TFC_TICKERS 4 |
emh203 | 3:23cce037011f | 14 | |
emh203 | 3:23cce037011f | 15 | Ticker TFC_TickerObj; |
emh203 | 3:23cce037011f | 16 | |
emh203 | 3:23cce037011f | 17 | volatile uint32_t TFC_Ticker[NUM_TFC_TICKERS]; |
emh203 | 3:23cce037011f | 18 | |
emh203 | 3:23cce037011f | 19 | void TFC_TickerUpdate() |
emh203 | 3:23cce037011f | 20 | { |
emh203 | 3:23cce037011f | 21 | int i; |
emh203 | 3:23cce037011f | 22 | |
emh203 | 3:23cce037011f | 23 | for(i=0; i<NUM_TFC_TICKERS; i++) |
emh203 | 3:23cce037011f | 24 | { |
emh203 | 3:23cce037011f | 25 | if(TFC_Ticker[i]<0xFFFFFFFF) |
emh203 | 3:23cce037011f | 26 | { |
emh203 | 3:23cce037011f | 27 | TFC_Ticker[i]++; |
emh203 | 3:23cce037011f | 28 | } |
emh203 | 3:23cce037011f | 29 | } |
emh203 | 3:23cce037011f | 30 | } |
emh203 | 3:23cce037011f | 31 | |
emh203 | 3:23cce037011f | 32 | |
emh203 | 3:23cce037011f | 33 | |
emh203 | 3:23cce037011f | 34 | |
emh203 | 3:23cce037011f | 35 | int main() |
emh203 | 3:23cce037011f | 36 | { |
emh203 | 3:23cce037011f | 37 | uint32_t i,j,t = 0; |
emh203 | 3:23cce037011f | 38 | |
emh203 | 3:23cce037011f | 39 | PC.baud(115200); |
emh203 | 3:23cce037011f | 40 | TFC_TickerObj.attach_us(&TFC_TickerUpdate,2000); |
emh203 | 3:23cce037011f | 41 | |
emh203 | 3:23cce037011f | 42 | TFC_Init(); |
emh203 | 3:23cce037011f | 43 | |
emh203 | 3:23cce037011f | 44 | for(;;) |
emh203 | 3:23cce037011f | 45 | { |
emh203 | 3:23cce037011f | 46 | //TFC_Task must be called in your main loop. This keeps certain processing happy (I.E. Serial port queue check) |
emh203 | 3:23cce037011f | 47 | // TFC_Task(); |
emh203 | 3:23cce037011f | 48 | |
emh203 | 3:23cce037011f | 49 | //This Demo program will look at the middle 2 switch to select one of 4 demo modes. |
emh203 | 3:23cce037011f | 50 | //Let's look at the middle 2 switches |
emh203 | 3:23cce037011f | 51 | switch((TFC_GetDIP_Switch()>>1)&0x03) |
emh203 | 3:23cce037011f | 52 | { |
emh203 | 3:23cce037011f | 53 | default: |
emh203 | 3:23cce037011f | 54 | case 0 : |
emh203 | 3:23cce037011f | 55 | //Demo mode 0 just tests the switches and LED's |
emh203 | 3:23cce037011f | 56 | if(TFC_PUSH_BUTTON_0_PRESSED) |
emh203 | 3:23cce037011f | 57 | TFC_BAT_LED0_ON; |
emh203 | 3:23cce037011f | 58 | else |
emh203 | 3:23cce037011f | 59 | TFC_BAT_LED0_OFF; |
emh203 | 3:23cce037011f | 60 | |
emh203 | 3:23cce037011f | 61 | if(TFC_PUSH_BUTTON_1_PRESSED) |
emh203 | 3:23cce037011f | 62 | TFC_BAT_LED3_ON; |
emh203 | 3:23cce037011f | 63 | else |
emh203 | 3:23cce037011f | 64 | TFC_BAT_LED3_OFF; |
emh203 | 3:23cce037011f | 65 | |
emh203 | 3:23cce037011f | 66 | |
emh203 | 3:23cce037011f | 67 | if(TFC_GetDIP_Switch()&0x01) |
emh203 | 3:23cce037011f | 68 | TFC_BAT_LED1_ON; |
emh203 | 3:23cce037011f | 69 | else |
emh203 | 3:23cce037011f | 70 | TFC_BAT_LED1_OFF; |
emh203 | 3:23cce037011f | 71 | |
emh203 | 3:23cce037011f | 72 | if(TFC_GetDIP_Switch()&0x08) |
emh203 | 3:23cce037011f | 73 | TFC_BAT_LED2_ON; |
emh203 | 3:23cce037011f | 74 | else |
emh203 | 3:23cce037011f | 75 | TFC_BAT_LED2_OFF; |
emh203 | 3:23cce037011f | 76 | |
emh203 | 3:23cce037011f | 77 | break; |
emh203 | 3:23cce037011f | 78 | |
emh203 | 3:23cce037011f | 79 | case 1: |
emh203 | 3:23cce037011f | 80 | |
emh203 | 3:23cce037011f | 81 | //Demo mode 1 will just move the servos with the on-board potentiometers |
emh203 | 3:23cce037011f | 82 | if(TFC_Ticker[0]>=20) |
emh203 | 3:23cce037011f | 83 | { |
emh203 | 3:23cce037011f | 84 | TFC_Ticker[0] = 0; //reset the Ticker |
emh203 | 3:23cce037011f | 85 | //Every 20 mSeconds, update the Servos |
emh203 | 3:23cce037011f | 86 | TFC_SetServo(0,TFC_ReadPot(0)); |
emh203 | 3:23cce037011f | 87 | TFC_SetServo(1,TFC_ReadPot(1)); |
emh203 | 3:23cce037011f | 88 | } |
emh203 | 3:23cce037011f | 89 | //Let's put a pattern on the LEDs |
emh203 | 3:23cce037011f | 90 | if(TFC_Ticker[1] >= 125) |
emh203 | 3:23cce037011f | 91 | { |
emh203 | 3:23cce037011f | 92 | TFC_Ticker[1] = 0; |
emh203 | 3:23cce037011f | 93 | t++; |
emh203 | 3:23cce037011f | 94 | if(t>4) |
emh203 | 3:23cce037011f | 95 | { |
emh203 | 3:23cce037011f | 96 | t=0; |
emh203 | 3:23cce037011f | 97 | } |
emh203 | 3:23cce037011f | 98 | TFC_SetBatteryLED_Level(t); |
emh203 | 3:23cce037011f | 99 | } |
emh203 | 3:23cce037011f | 100 | |
emh203 | 3:23cce037011f | 101 | TFC_SetMotorPWM(0,0); //Make sure motors are off |
emh203 | 3:23cce037011f | 102 | TFC_HBRIDGE_DISABLE; |
emh203 | 3:23cce037011f | 103 | |
emh203 | 3:23cce037011f | 104 | |
emh203 | 3:23cce037011f | 105 | break; |
emh203 | 3:23cce037011f | 106 | |
emh203 | 3:23cce037011f | 107 | case 2 : |
emh203 | 3:23cce037011f | 108 | |
emh203 | 3:23cce037011f | 109 | //Demo Mode 2 will use the Pots to make the motors move |
emh203 | 3:23cce037011f | 110 | TFC_HBRIDGE_ENABLE; |
emh203 | 3:23cce037011f | 111 | |
emh203 | 3:23cce037011f | 112 | TFC_SetMotorPWM(TFC_ReadPot(0),TFC_ReadPot(1)); |
emh203 | 3:23cce037011f | 113 | |
emh203 | 3:23cce037011f | 114 | |
emh203 | 3:23cce037011f | 115 | //Let's put a pattern on the LEDs |
emh203 | 3:23cce037011f | 116 | if(TFC_Ticker[1] >= 125) |
emh203 | 3:23cce037011f | 117 | { |
emh203 | 3:23cce037011f | 118 | TFC_Ticker[1] = 0; |
emh203 | 3:23cce037011f | 119 | t++; |
emh203 | 3:23cce037011f | 120 | if(t>4) |
emh203 | 3:23cce037011f | 121 | { |
emh203 | 3:23cce037011f | 122 | t=0; |
emh203 | 3:23cce037011f | 123 | } |
emh203 | 3:23cce037011f | 124 | TFC_SetBatteryLED_Level(t); |
emh203 | 3:23cce037011f | 125 | } |
emh203 | 3:23cce037011f | 126 | break; |
emh203 | 3:23cce037011f | 127 | |
emh203 | 3:23cce037011f | 128 | case 3 : |
emh203 | 3:23cce037011f | 129 | |
redxeth | 4:8a4a3fc59e57 | 130 | uint32_t NumCameras = 1; // Enter here how many line scan cameras hooked up |
redxeth | 4:8a4a3fc59e57 | 131 | |
emh203 | 3:23cce037011f | 132 | //Demo Mode 3 will be in Freescale Garage Mode. It will beam data from the Camera to the |
emh203 | 3:23cce037011f | 133 | //Labview Application |
emh203 | 3:23cce037011f | 134 | |
redxeth | 4:8a4a3fc59e57 | 135 | |
emh203 | 3:23cce037011f | 136 | if(TFC_Ticker[0]>1000 && TFC_LineScanImageReady>0) |
emh203 | 3:23cce037011f | 137 | { |
emh203 | 3:23cce037011f | 138 | TFC_Ticker[0] = 0; |
emh203 | 3:23cce037011f | 139 | TFC_LineScanImageReady=0; |
emh203 | 3:23cce037011f | 140 | TERMINAL_PRINTF("\r\n"); |
emh203 | 3:23cce037011f | 141 | TERMINAL_PRINTF("L:"); |
emh203 | 3:23cce037011f | 142 | |
emh203 | 3:23cce037011f | 143 | if(t==0) |
emh203 | 3:23cce037011f | 144 | t=4; |
emh203 | 3:23cce037011f | 145 | else |
emh203 | 3:23cce037011f | 146 | t--; |
emh203 | 3:23cce037011f | 147 | |
emh203 | 3:23cce037011f | 148 | TFC_SetBatteryLED_Level(t); |
emh203 | 3:23cce037011f | 149 | |
redxeth | 4:8a4a3fc59e57 | 150 | // camera 1 |
emh203 | 3:23cce037011f | 151 | for(i=0;i<8;i++) |
emh203 | 3:23cce037011f | 152 | { |
emh203 | 3:23cce037011f | 153 | for(j=0;j<16;j++) |
emh203 | 3:23cce037011f | 154 | { |
redxeth | 4:8a4a3fc59e57 | 155 | TERMINAL_PRINTF("%X",TFC_LineScanImage0[(i*16)+j]); |
redxeth | 4:8a4a3fc59e57 | 156 | |
redxeth | 4:8a4a3fc59e57 | 157 | if (NumCameras == 1) |
redxeth | 4:8a4a3fc59e57 | 158 | { |
redxeth | 4:8a4a3fc59e57 | 159 | if((i==7)&&(j==15)) |
redxeth | 4:8a4a3fc59e57 | 160 | TERMINAL_PRINTF("\r\n",TFC_LineScanImage0[(i*16)+j]); |
redxeth | 4:8a4a3fc59e57 | 161 | else |
redxeth | 4:8a4a3fc59e57 | 162 | TERMINAL_PRINTF(",",TFC_LineScanImage0[(i*16)+j]); |
redxeth | 4:8a4a3fc59e57 | 163 | } |
redxeth | 4:8a4a3fc59e57 | 164 | |
emh203 | 3:23cce037011f | 165 | } |
emh203 | 3:23cce037011f | 166 | wait_ms(10); |
emh203 | 3:23cce037011f | 167 | } |
redxeth | 4:8a4a3fc59e57 | 168 | |
redxeth | 4:8a4a3fc59e57 | 169 | // camera 2 |
redxeth | 4:8a4a3fc59e57 | 170 | if (NumCameras == 2) |
redxeth | 4:8a4a3fc59e57 | 171 | { |
redxeth | 4:8a4a3fc59e57 | 172 | for(i=0;i<8;i++) |
redxeth | 4:8a4a3fc59e57 | 173 | { |
redxeth | 4:8a4a3fc59e57 | 174 | for(j=0;j<16;j++) |
emh203 | 3:23cce037011f | 175 | { |
redxeth | 4:8a4a3fc59e57 | 176 | TERMINAL_PRINTF("%X",TFC_LineScanImage1[(i*16)+j]); |
emh203 | 3:23cce037011f | 177 | |
redxeth | 4:8a4a3fc59e57 | 178 | if((i==7)&&(j==15)) |
redxeth | 4:8a4a3fc59e57 | 179 | TERMINAL_PRINTF("\r\n",TFC_LineScanImage1[(i*16)+j]); |
redxeth | 4:8a4a3fc59e57 | 180 | else |
redxeth | 4:8a4a3fc59e57 | 181 | TERMINAL_PRINTF(",",TFC_LineScanImage1[(i*16)+j]); |
redxeth | 4:8a4a3fc59e57 | 182 | } |
redxeth | 4:8a4a3fc59e57 | 183 | wait_ms(10); |
redxeth | 4:8a4a3fc59e57 | 184 | } |
redxeth | 4:8a4a3fc59e57 | 185 | } |
emh203 | 3:23cce037011f | 186 | |
emh203 | 3:23cce037011f | 187 | } |
emh203 | 3:23cce037011f | 188 | |
emh203 | 3:23cce037011f | 189 | |
emh203 | 3:23cce037011f | 190 | |
emh203 | 3:23cce037011f | 191 | break; |
emh203 | 3:23cce037011f | 192 | } |
emh203 | 3:23cce037011f | 193 | } |
emh203 | 3:23cce037011f | 194 | |
emh203 | 3:23cce037011f | 195 | |
emh203 | 3:23cce037011f | 196 | } |
emh203 | 3:23cce037011f | 197 |