An example program that uses FRDM-TFC library written by Eli Hughes.
Fork of TFC-TEST by
main.cpp
- Committer:
- SaverioF15
- Date:
- 2014-10-08
- Revision:
- 1:1dd8d5ffdd02
- Parent:
- 0:6432166d0781
File content as of revision 1:1dd8d5ffdd02:
#include "mbed.h" #include "TFC.h" //This macro is to maintain compatibility with Codewarrior version of the sample. This version uses the MBED libraries for serial port access Serial PC(USBTX,USBRX); #define ref_val 5 #define TERMINAL_PRINTF PC.printf //This ticker code is used to maintain compability with the Codewarrior version of the sample. This code uses an MBED Ticker for background timing. #define NUM_TFC_TICKERS 4 Ticker TFC_TickerObj; volatile uint32_t TFC_Ticker[NUM_TFC_TICKERS]; float servo_angle=0.0; float vision[129]; unsigned int n_izq=0; unsigned int n_der=0; int error=0; void TFC_TickerUpdate() { int i; for(i=0; i<NUM_TFC_TICKERS; i++) { if(TFC_Ticker[i]<0xFFFFFFFF) { TFC_Ticker[i]++; } } } int main() { uint32_t i,t = 0; PC.baud(115200); TFC_TickerObj.attach_us(&TFC_TickerUpdate,2000); TFC_Init(); for(;;) { //TFC_Task must be called in your main loop. This keeps certain processing happy (I.E. Serial port queue check) // TFC_Task(); //This Demo program will look at the middle 2 switch to select one of 4 demo modes. //Let's look at the middle 2 switches //Demo Mode 2 will use the Pots to make the motors move TFC_HBRIDGE_ENABLE; TFC_SetMotorPWM(TFC_ReadPot(1),TFC_ReadPot(1)); if(TFC_Ticker[0]>=20) { TFC_Ticker[0] = 0; //reset the Ticker //Every 20 mSeconds, update the Servos TFC_SetServo(0,servo_angle); n_der=0; } if(TFC_Ticker[1]>50 && TFC_LineScanImageReady>0) { TFC_Ticker[1] = 0; TFC_LineScanImageReady=0; if(t==0) t=4; else t--; TFC_SetBatteryLED_Level(t); // camera 1 for(i=0;i<128;i++) {if(TFC_LineScanImage0[i]<=1250) vision[i]=0; else vision[i]= 1; } } for(i=65;i<70;i++) {if(vision[i]==1) n_der++; else break; } //error= 5-n_der; //if(error>5) error=(error-5)*-1; //servo_angle=0.09*error; if(n_der<=7) servo_angle=0.30; else if(n_der<=12 && n_der>=8)servo_angle=0; else if (n_der>=13)servo_angle=-0.30; if(TFC_Ticker[1]>1000&&(vision[63]==0||vision[67])) servo_angle*=-1.0; /*if(n_der<3) servo_angle=0.25; else if(n_der<=7 && n_der>=3)servo_angle=0; else if (n_der>7)servo_angle=-0.25;*/ /*if(n_der<4 && n_der>0) servo_angle=-0.3; //else if(n_der<=6 && n_der>=4)servo_angle=0; else if(n_der==5)servo_angle=0; else if (n_der>6 && n_der<10)servo_angle=0.3;*/ } }