Austin Community College initial line follower program for Freescale car. This is based upon the FRDM-TFC code at mbed.org.

Dependencies:   mbed

Fork of FRDM-TFC by Eli Hughes

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.

Committer:
emh203
Date:
Thu Aug 15 23:26:19 2013 +0000
Revision:
3:23cce037011f
Parent:
2:ce4a273be708
Child:
4:8a4a3fc59e57
1.) Fixed issue with Servo duty cycle calculation
; 2.) Verified Case 0,1 2 of the test program (servo steering and drive). The Camera code is OK but there seems to be an issue on my machine with the KL25Z virtual MBED serial port.

Who changed what in which revision?

UserRevisionLine numberNew 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
emh203 3:23cce037011f 130 //Demo Mode 3 will be in Freescale Garage Mode. It will beam data from the Camera to the
emh203 3:23cce037011f 131 //Labview Application
emh203 3:23cce037011f 132
emh203 3:23cce037011f 133 //note that there are some issues
emh203 3:23cce037011f 134 if(TFC_Ticker[0]>1000 && TFC_LineScanImageReady>0)
emh203 3:23cce037011f 135 {
emh203 3:23cce037011f 136 TFC_Ticker[0] = 0;
emh203 3:23cce037011f 137 TFC_LineScanImageReady=0;
emh203 3:23cce037011f 138 TERMINAL_PRINTF("\r\n");
emh203 3:23cce037011f 139 TERMINAL_PRINTF("L:");
emh203 3:23cce037011f 140
emh203 3:23cce037011f 141 if(t==0)
emh203 3:23cce037011f 142 t=4;
emh203 3:23cce037011f 143 else
emh203 3:23cce037011f 144 t--;
emh203 3:23cce037011f 145
emh203 3:23cce037011f 146 TFC_SetBatteryLED_Level(t);
emh203 3:23cce037011f 147
emh203 3:23cce037011f 148 for(i=0;i<8;i++)
emh203 3:23cce037011f 149 {
emh203 3:23cce037011f 150 for(j=0;j<16;j++)
emh203 3:23cce037011f 151 {
emh203 3:23cce037011f 152 TERMINAL_PRINTF("%X,",TFC_LineScanImage0[(i*8)+j]);
emh203 3:23cce037011f 153
emh203 3:23cce037011f 154 }
emh203 3:23cce037011f 155 wait_ms(10);
emh203 3:23cce037011f 156 }
emh203 3:23cce037011f 157
emh203 3:23cce037011f 158 for(i=0;i<8;i++)
emh203 3:23cce037011f 159 {
emh203 3:23cce037011f 160 for(j=0;j<16;j++)
emh203 3:23cce037011f 161 {
emh203 3:23cce037011f 162 TERMINAL_PRINTF("%X",TFC_LineScanImage1[(i*8)+j]);
emh203 3:23cce037011f 163
emh203 3:23cce037011f 164 if((i*8)+j==127)
emh203 3:23cce037011f 165 TERMINAL_PRINTF("\r\n",TFC_LineScanImage1[(i*8)+j]);
emh203 3:23cce037011f 166 else
emh203 3:23cce037011f 167 TERMINAL_PRINTF(",",TFC_LineScanImage1[(i*8)+j]);
emh203 3:23cce037011f 168 }
emh203 3:23cce037011f 169
emh203 3:23cce037011f 170 wait_ms(10);
emh203 3:23cce037011f 171 }
emh203 3:23cce037011f 172
emh203 3:23cce037011f 173 }
emh203 3:23cce037011f 174
emh203 3:23cce037011f 175
emh203 3:23cce037011f 176
emh203 3:23cce037011f 177 break;
emh203 3:23cce037011f 178 }
emh203 3:23cce037011f 179 }
emh203 3:23cce037011f 180
emh203 3:23cce037011f 181
emh203 3:23cce037011f 182 }
emh203 3:23cce037011f 183