car using PID from centre line

Dependencies:   FRDM-TFC mbed CBuffer XBEE mbed_angular_speed motor2 MMA8451Q

Fork of KL25Z_Camera_Test by GDP 4

Committer:
maximusismax
Date:
Fri Oct 14 10:56:56 2016 +0000
Revision:
0:566127ca8048
Child:
1:a4883d9c75ec
Test

Who changed what in which revision?

UserRevisionLine numberNew contents of line
maximusismax 0:566127ca8048 1 #include "mbed.h"
maximusismax 0:566127ca8048 2 #include "TFC.h"
maximusismax 0:566127ca8048 3 #define CAM_THRESHOLD 3000
maximusismax 0:566127ca8048 4
maximusismax 0:566127ca8048 5
maximusismax 0:566127ca8048 6 DigitalOut myled(LED1);
maximusismax 0:566127ca8048 7
maximusismax 0:566127ca8048 8 int main() {
maximusismax 0:566127ca8048 9 TFC_Init();
maximusismax 0:566127ca8048 10
maximusismax 0:566127ca8048 11 uint32_t i,t = 0;
maximusismax 0:566127ca8048 12 //uint32_t width = 0;
maximusismax 0:566127ca8048 13 char curr_line[129];
maximusismax 0:566127ca8048 14
maximusismax 0:566127ca8048 15 /* Ensure string is null terminated */
maximusismax 0:566127ca8048 16 curr_line[128] = 0;
maximusismax 0:566127ca8048 17
maximusismax 0:566127ca8048 18
maximusismax 0:566127ca8048 19 printf("Starting camera test program\n");
maximusismax 0:566127ca8048 20
maximusismax 0:566127ca8048 21 while(1) {
maximusismax 0:566127ca8048 22 //If we have an image ready
maximusismax 0:566127ca8048 23 if(TFC_LineScanImageReady>0)
maximusismax 0:566127ca8048 24 {
maximusismax 0:566127ca8048 25 //Reset image ready flag
maximusismax 0:566127ca8048 26 TFC_LineScanImageReady=0;
maximusismax 0:566127ca8048 27 printf("\r\n");
maximusismax 0:566127ca8048 28 //printf("L:");
maximusismax 0:566127ca8048 29
maximusismax 0:566127ca8048 30 //Strange thing that cycles the battery indicator
maximusismax 0:566127ca8048 31 //Leaving in as this is a good indicator that the camera test program is running
maximusismax 0:566127ca8048 32 if(t==4)
maximusismax 0:566127ca8048 33 t=0;
maximusismax 0:566127ca8048 34 else
maximusismax 0:566127ca8048 35 t++;
maximusismax 0:566127ca8048 36 TFC_SetBatteryLED_Level(t);
maximusismax 0:566127ca8048 37
maximusismax 0:566127ca8048 38 for(i = 0; i < 128; i++) {
maximusismax 0:566127ca8048 39 curr_line[i] = (int8_t)(TFC_LineScanImage0[i] >> 4) & 0xFF;
maximusismax 0:566127ca8048 40 printf("%02x", curr_line[i]);
maximusismax 0:566127ca8048 41 }
maximusismax 0:566127ca8048 42 printf("\n");
maximusismax 0:566127ca8048 43 //printf("0x%x\n", curr_line);
maximusismax 0:566127ca8048 44 /*
maximusismax 0:566127ca8048 45 //Loop through camera pixels
maximusismax 0:566127ca8048 46 for(i=0;i<128;i++)
maximusismax 0:566127ca8048 47 {
maximusismax 0:566127ca8048 48 //If the pixel value exceeds our threshold, print a 1
maximusismax 0:566127ca8048 49 if (TFC_LineScanImage0[i] > CAM_THRESHOLD)
maximusismax 0:566127ca8048 50 {
maximusismax 0:566127ca8048 51 curr_line[i] = '1';
maximusismax 0:566127ca8048 52 width++; //Increment the width value
maximusismax 0:566127ca8048 53 }
maximusismax 0:566127ca8048 54 //Else, print a 0
maximusismax 0:566127ca8048 55 else
maximusismax 0:566127ca8048 56 {
maximusismax 0:566127ca8048 57 curr_line[i] = '0';
maximusismax 0:566127ca8048 58 }
maximusismax 0:566127ca8048 59 }
maximusismax 0:566127ca8048 60 printf("%s\n",curr_line);
maximusismax 0:566127ca8048 61
maximusismax 0:566127ca8048 62 printf("Width: %d\n", width);
maximusismax 0:566127ca8048 63 width = 0;
maximusismax 0:566127ca8048 64 */
maximusismax 0:566127ca8048 65
maximusismax 0:566127ca8048 66 }
maximusismax 0:566127ca8048 67 }
maximusismax 0:566127ca8048 68 }