Académique Documents
Professionnel Documents
Culture Documents
ID:-02191916
[Here I have included Recitation 1-5, and all the source codes. For rest of the
recitations that were not updated , I have to send the scanned copy . ( Recitation 3 and
4 are missing) that I will include in another word document with my scanned copy with
your signature. Please grade these as Professor told me to submit. Thank you.]
printf("Hello, world\n");
printf("my name is Israt\n");
system("pause");
}
Code for recitation 5 :
#include<stdio.h>
#include<string.h>
#include <stdlib.h>
int main(void)
{
char v_source[size],r_source[size],c;
double v_src,r_src;
double ca[size];
double pa[size],r_load[size];
double max_power=0;
int max_index;
i=0;
printf("Enter source resistance: ");
gets(r_source);
r_src = atof(r_source);
printf("You entered %f Ohms as Rs. \n", r_src);
i=0;
printf("\n\nPlotting pa[] vs ca[] arrays:\n");
for(i=0;i<size;i++)
{
ca[i]=rand()%9+1;
r_load[i]=ca[i]*r_src;
temp1=v_src*v_src*r_load[i];
temp2=r_load[i]+r_src;
temp2*=temp2;
pa[i]=temp1/temp2;
printf("Power: %f
->
ca[%d] = %f\n",pa[i],i,r_load[i]);
if(pa[i]>max_power)
{
max_power=pa[i];
max_index=i;
}
}
}
Source code 1:
#include "derivative.h" /* include peripheral declarations */
#include "TFC\TFC.h"
#include <math.h>
vsum
+= vcomp[j]; // start the mean processing
}
vmean = vsum/((float)Nnotch); // compute the mean of the segment
//--------------------------// Subtract mean
//--------------------------vsum = 0;
for(j=0; j<Nnotch; j++){
vcomp[j] -= vmean;
vsum
+= (vcomp[j]*vcomp[j]); // start the L2 norm
processing
}
vdenom = sqrt(vsum); // compute L2 norm of segment
if(vdenom != 0){
vrecip = 1/vdenom; // take reciprocal so we minimize
expensive divisions
//--------------------------// Normalize (if not zero)
//--------------------------vsum = 0;
for(j=0; j<Nnotch; j++){
vcomp[j] *= vrecip;
vsum
+= vcomp[j]*notch[j]; // perform the
inner product for L2 norm
}
vnorm = vsum; // the L2 norm
}else{
vnorm = 0;
}
//-----------------------------------// Find the maximum cross-correlation
//-----------------------------------if(vpeak < vnorm){
vpeak = vnorm;
vpeak_index = i + Nnotch_center - 1; // add offset so that
the center is at index 64
}
}
//-----------------------------------// Calculate how much to turn....
//-----------------------------------offset_index = vpeak_index-64;
vturn1 = (float)offset_index*0.6;
vturn = vturn1/64 * steering_gain; // implement steering gain to control
how fast it turns to center
if(vturn > steering_limit_high){
// limit the turn angle so that the
wheels don't hit the car
vturn = steering_limit_high;
}
if(vturn < steering_limit_low){
// limit the turn angle so that the
wheels don't hit the car
vturn = steering_limit_low;
}
}
return vturn;
int main(void)
{
uint32_t t;
int i=0;
TFC_Init();
set_template_values();
finding the line....
for(;;)
{
This keeps
--------
Matlab
//-------------------------------------
--------
for(i=0;i<128;i++){
TERMINAL_PRINTF("%X",LineScanImage0[i]); // send raw binary....
}
TERMINAL_PRINTF("\r\n");
//------------------------------------// Compute and set steering angle
//------------------------------------TFC_SetServo(0,compute_steering_angle());
}
//-----------------------------------------------
TFC_SetMotorPWM(TFC_ReadPot0(),TFC_ReadPot0());
via potentiometer (constant speed)
// speed is set
}else{
motors are off
}
//put a pattern on the LEDs....
if(TFC_Ticker[1] >= 125)
{
TFC_Ticker[1] = 0;
t++;
if(t>4)
{
t=0;
}
TFC_SetBatteryLED_Level(t);
}
break;
case 1:
the on-board potentiometers
off
TFC_HBRIDGE_DISABLE;
break;
case 2 :
motors move
for(i=0;i<128;i++)
{
TERMINAL_PRINTF("%X",LineScanImage1[i]);
if(i==127)
TERMINAL_PRINTF("\r\n",LineScanImage1[i]);
else
TERMINAL_PRINTF(",",LineScanImage1[i]);
}
*/
break;
}
}
return 0;
Source code 2 :
#include "derivative.h" /* include peripheral declarations */
#include "TFC\TFC.h"
#include <math.h>
#define steering_gain 1.2
#define steering_limit_high 0.6
#define steering_limit_low -0.6
//---------------------------------------------------------// Load the Notch Template Values (global array)
// (Cut and paste the C code that Matlab generated below)
//---------------------------------------------------------#define Nnotch 18
// number of elements in the Notch Template
float notch[Nnotch]; // Notch Template (vector should be zero mean and
normalized....)
void set_template_values(){
notch[0] = 0.334462147117700;
notch[1] = 0.273556199704827;
notch[2] = 0.179854742146561;
notch[3] = 0.062727920198728;
notch[4] = -0.030973537359538;
notch[5] = -0.143415286429457;
notch[6] = -0.227746598231897;
notch[7] = -0.312077910034337;
notch[8] = -0.335503274423903;
notch[9] = -0.330818201545990;
notch[10] = -0.255857035499377;
notch[11] = -0.176210796574851;
notch[12] = -0.068454120382844;
notch[13] = 0.015877191419595;
notch[14] = 0.133004013367428;
notch[15] = 0.231390543803607;
notch[16] = 0.315721855606047;
notch[17] = 0.334462147117700;
}
//-------------------------------------------------------------------// Compute what the steering angle should be from the camera data
//-------------------------------------------------------------------float compute_steering_angle(){
float vcomp[Nnotch];
float vsum,vmean,vdenom,vrecip,vnorm,vpeak,vturn;
float vturn1;
int offset_index;
int vpeak_index;
int Nnotch_center;
int i,j;
Nnotch_center = round(Nnotch/2);
vpeak_index = -1;
vpeak
= -1000;
//---------------------------------// Go through camera line data
//---------------------------------for(i=0; i<128-Nnotch+1; i++){
//--------------------------// Grab segment of line data
//--------------------------vsum = 0;
for(j=0; j<Nnotch; j++){
vcomp[j] = LineScanImage0[i+j];
vsum
+= vcomp[j]; // start the mean processing
}
vmean = vsum/((float)Nnotch); // compute the mean of the segment
//--------------------------// Subtract mean
//--------------------------vsum = 0;
for(j=0; j<Nnotch; j++){
vcomp[j] -= vmean;
vsum
+= (vcomp[j]*vcomp[j]); // start the L2 norm
processing
}
vdenom = sqrt(vsum); // compute L2 norm of segment
if(vdenom != 0){
vrecip = 1/vdenom; // take reciprocal so we minimize
expensive divisions
//--------------------------// Normalize (if not zero)
//--------------------------vsum = 0;
for(j=0; j<Nnotch; j++){
vcomp[j] *= vrecip;
vsum
+= vcomp[j]*notch[j]; // perform the
inner product for L2 norm
}
vnorm = vsum; // the L2 norm
}else{
vnorm = 0;
}
//-----------------------------------// Find the maximum cross-correlation
//-----------------------------------if(vpeak < vnorm){
vpeak = vnorm;
vpeak_index = i + Nnotch_center - 1; // add offset so that
the center is at index 64
}
}
//-----------------------------------// Calculate how much to turn....
//-----------------------------------offset_index = vpeak_index-64;
vturn1 = (float)offset_index*0.6;
vturn = vturn1/64 * steering_gain;
how fast it turns to center
if(vturn > steering_limit_high){
wheels don't hit the car
vturn = steering_limit_high;
}
if(vturn < steering_limit_low){
wheels don't hit the car
vturn = steering_limit_low;
}
}
return vturn;
int main(void)
{
uint32_t t;
int i=0;
TFC_Init();
set_template_values();
finding the line....
for(;;)
{
//TFC_Task must be called in your main loop.
certain processing happy (I.E. Serial port queue check
TFC_Task();
This keeps
--------
for(i=0;i<128;i++){
//------------------------------------TFC_SetServo(0,compute_steering_angle());
}
//----------------------------------------------
--
if(TFC_GetDIP_Switch()&0x01){
TFC_HBRIDGE_ENABLE;
TFC_SetMotorPWM(TFC_ReadPot0(),TFC_ReadPot0());
// speed is set
via potentiometer (constant speed)
}else{
TFC_SetMotorPWM(0,0); //Make sure
motors are off
TFC_HBRIDGE_DISABLE;
}
//put a pattern on the LEDs....
if(TFC_Ticker[1] >= 125)
{
TFC_Ticker[1] = 0;
t++;
if(t>4)
{
t=0;
}
TFC_SetBatteryLED_Level(t);
}
break;
case 1:
//Demo mode 1 will just move the servos with
the on-board potentiometers
if(TFC_Ticker[0]>=1)
{
TFC_Ticker[0] = 0; //reset the Ticker
//Every 20 mSeconds, update the Servos
TFC_SetServo(0,TFC_ReadPot0());
TFC_SetServo(1,TFC_ReadPot1());
}
//Let's put a pattern on the LEDs
if(TFC_Ticker[1] >= 125)
{
TFC_Ticker[1] = 0;
t++;
if(t>4)
{
t=0;
}
TFC_SetBatteryLED_Level(t);
}
TFC_HBRIDGE_DISABLE;
break;
case 2 :
motors move
/*
}
TERMINAL_PRINTF("\r\n");
for(i=0;i<128;i++)
{
TERMINAL_PRINTF("%X",LineScanImage1[i]);
if(i==127)
TERMINAL_PRINTF("\r\n",LineScanImage1[i]);
else
TERMINAL_PRINTF(",",LineScanImage1[i]);
*/
break;
}
return 0;
}
Source code 3 :
#include "derivative.h" /* include peripheral declarations */
#include "TFC\TFC.h"
#include <math.h>
#define steering_gain 1.2
#define steering_limit_high 0.6
#define steering_limit_low -0.6
//---------------------------------------------------------// Load the Notch Template Values (global array)
// (Cut and paste the C code that Matlab generated below)
//---------------------------------------------------------#define Nnotch 18
// number of elements in the Notch Template
float notch[Nnotch]; // Notch Template (vector should be zero mean and
normalized....)
void set_template_values(){
notch[0] = 0.334462147117700;
notch[1] = 0.273556199704827;
notch[2] = 0.179854742146561;
notch[3] = 0.062727920198728;
notch[4] = -0.030973537359538;
notch[5] = -0.143415286429457;
notch[6] = -0.227746598231897;
notch[7] = -0.312077910034337;
notch[8] = -0.335503274423903;
notch[9] = -0.330818201545990;
notch[10] = -0.255857035499377;
notch[11] = -0.176210796574851;
notch[12] = -0.068454120382844;
notch[13] = 0.015877191419595;
notch[14]
notch[15]
notch[16]
notch[17]
=
=
=
=
0.133004013367428;
0.231390543803607;
0.315721855606047;
0.334462147117700;
}
//-------------------------------------------------------------------// Compute what the steering angle should be from the camera data
//-------------------------------------------------------------------float compute_steering_angle(){
float vcomp[Nnotch];
float vsum,vmean,vdenom,vrecip,vnorm,vpeak,vturn;
float vturn1;
int offset_index;
int vpeak_index;
int Nnotch_center;
int i,j;
Nnotch_center = round(Nnotch/2);
vpeak_index = -1;
vpeak
= -1000;
//---------------------------------// Go through camera line data
//---------------------------------for(i=0; i<128-Nnotch+1; i++){
//--------------------------// Grab segment of line data
//--------------------------vsum = 0;
for(j=0; j<Nnotch; j++){
vcomp[j] = LineScanImage0[i+j];
vsum
+= vcomp[j]; // start the mean processing
}
vmean = vsum/((float)Nnotch); // compute the mean of the segment
//--------------------------// Subtract mean
//--------------------------vsum = 0;
for(j=0; j<Nnotch; j++){
vcomp[j] -= vmean;
vsum
+= (vcomp[j]*vcomp[j]); // start the L2 norm
processing
}
vdenom = sqrt(vsum); // compute L2 norm of segment
if(vdenom != 0){
vrecip = 1/vdenom; // take reciprocal so we minimize
expensive divisions
//--------------------------// Normalize (if not zero)
//--------------------------vsum = 0;
for(j=0; j<Nnotch; j++){
vcomp[j] *= vrecip;
vsum
+= vcomp[j]*notch[j]; // perform the
inner product for L2 norm
}
vnorm = vsum; // the L2 norm
}else{
vnorm = 0;
}
//-----------------------------------// Find the maximum cross-correlation
//-----------------------------------if(vpeak < vnorm){
vpeak = vnorm;
vpeak_index = i + Nnotch_center - 1;
the center is at index 64
}
}
//-----------------------------------// Calculate how much to turn....
//-----------------------------------offset_index = vpeak_index-64;
vturn1 = (float)offset_index*0.6;
vturn = vturn1/64 * steering_gain; // implement
how fast it turns to center
if(vturn > steering_limit_high){
// limit the
wheels don't hit the car
vturn = steering_limit_high;
}
if(vturn < steering_limit_low){
// limit the
wheels don't hit the car
vturn = steering_limit_low;
}
}
return vturn;
int main(void)
{
uint32_t t;
int i=0;
TFC_Init();
set_template_values();
finding the line....
for(;;)
{
//TFC_Task must be called in your main loop.
certain processing happy (I.E. Serial port queue check
TFC_Task();
This keeps
LineScanImageReady=0;
//-------------------------------------
--------
Matlab
//-------------------------------------
--------
for(i=0;i<128;i++){
TERMINAL_PRINTF("%X",LineScanImage0[i]); // send raw binary....
}
TERMINAL_PRINTF("\r\n");
//------------------------------------// Compute and set steering angle
//------------------------------------TFC_SetServo(0,compute_steering_angle());
}
//----------------------------------------------
--
if(TFC_GetDIP_Switch()&0x01){
TFC_HBRIDGE_ENABLE;
TFC_SetMotorPWM(TFC_ReadPot0(),TFC_ReadPot(0));
// speed is set
via potentiometer (constant speed)
}else{
TFC_SetMotorPWM(0,0); //Make sure
motors are off
TFC_HBRIDGE_DISABLE;
}
//put a pattern on the LEDs....
if(TFC_Ticker[1] >= 125)
{
TFC_Ticker[1] = 0;
t++;
if(t>4)
{
t=0;
}
TFC_SetBatteryLED_Level(t);
}
break;
case 1:
//Demo mode 1 will just move the servos with
the on-board potentiometers
if(TFC_Ticker[0]>=1)
{
TFC_HBRIDGE_DISABLE;
break;
case 2 :
motors move
if(t==0)
t=3;
else
t--;
TFC_SetBatteryLED_Level(t);
for(i=0;i<128;i++)
{
TERMINAL_PRINTF("%X",LineScanImage0[i]);
}
TERMINAL_PRINTF("\r\n");
/*
for(i=0;i<128;i++)
{
TERMINAL_PRINTF("%X",LineScanImage1[i]);
if(i==127)
TERMINAL_PRINTF("\r\n",LineScanImage1[i]);
else
TERMINAL_PRINTF(",",LineScanImage1[i]);
*/
break;
}
return 0;
}
Source code 4:
#include "derivative.h" /* include peripheral declarations */
#include "TFC\TFC.h"
#include <math.h>
#define steering_gain 1.2
#define steering_limit_high 0.6
#define steering_limit_low -0.6
//---------------------------------------------------------// Load the Notch Template Values (global array)
// (Cut and paste the C code that Matlab generated below)
//---------------------------------------------------------#define Nnotch 18
// number of elements in the Notch Template
float notch[Nnotch]; // Notch Template (vector should be zero mean and
normalized....)
void set_template_values(){
notch[0] = 0.334462147117700;
notch[1] = 0.273556199704827;
notch[2] = 0.179854742146561;
notch[3] = 0.062727920198728;
notch[4] = -0.030973537359538;
notch[5] = -0.143415286429457;
notch[6] = -0.227746598231897;
notch[7] = -0.312077910034337;
notch[8] = -0.335503274423903;
notch[9] = -0.330818201545990;
notch[10] = -0.255857035499377;
notch[11] = -0.176210796574851;
notch[12] = -0.068454120382844;
notch[13] = 0.015877191419595;
notch[14] = 0.133004013367428;
notch[15] = 0.231390543803607;
notch[16] = 0.315721855606047;
notch[17] = 0.334462147117700;
//-------------------------------------------------------------------// Compute what the steering angle should be from the camera data
//-------------------------------------------------------------------float compute_steering_angle(){
float vcomp[Nnotch];
float vsum,vmean,vdenom,vrecip,vnorm,vpeak,vturn;
float vturn1;
int offset_index;
int vpeak_index;
int Nnotch_center;
int i,j;
Nnotch_center = round(Nnotch/2);
vpeak_index = -1;
vpeak
= -1000;
//---------------------------------// Go through camera line data
//---------------------------------for(i=0; i<128-Nnotch+1; i++){
//--------------------------// Grab segment of line data
//--------------------------vsum = 0;
for(j=0; j<Nnotch; j++){
vcomp[j] = LineScanImage0[i+j];
vsum
+= vcomp[j]; // start the mean processing
}
vmean = vsum/((float)Nnotch); // compute the mean of the segment
//--------------------------// Subtract mean
//--------------------------vsum = 0;
for(j=0; j<Nnotch; j++){
vcomp[j] -= vmean;
vsum
+= (vcomp[j]*vcomp[j]); // start the L2 norm
processing
}
vdenom = sqrt(vsum); // compute L2 norm of segment
if(vdenom != 0){
vrecip = 1/vdenom; // take reciprocal so we minimize
expensive divisions
//--------------------------// Normalize (if not zero)
//--------------------------vsum = 0;
for(j=0; j<Nnotch; j++){
vcomp[j] *= vrecip;
vsum
+= vcomp[j]*notch[j]; // perform the
inner product for L2 norm
}
vnorm = vsum; // the L2 norm
}else{
vnorm = 0;
}
//-----------------------------------// Find the maximum cross-correlation
//-----------------------------------if(vpeak < vnorm){
vpeak = vnorm;
vpeak_index = i + Nnotch_center - 1; // add offset so that
the center is at index 64
}
}
//-----------------------------------// Calculate how much to turn....
//-----------------------------------offset_index = vpeak_index-64;
vturn1 = (float)offset_index*0.6;
vturn = vturn1/64 * steering_gain; // implement steering gain to control
how fast it turns to center
if(vturn > steering_limit_high){
// limit the turn angle so that the
wheels don't hit the car
vturn = steering_limit_high;
}
if(vturn < steering_limit_low){
// limit the turn angle so that the
wheels don't hit the car
vturn = steering_limit_low;
}
return vturn;
}
int main(void)
{
uint32_t t;
int i=0;
TFC_Init();
set_template_values();
finding the line....
for(;;)
{
This keeps
Matlab
//-------------------------------------
--------
for(i=0;i<120;i++){
--
if(TFC_GetDIP_Switch()&0x01){
TFC_HBRIDGE_ENABLE;
TFC_SetMotorPWM(TFC_ReadPot0(),TFC_ReadPot(0));
// speed is set
via potentiometer (constant speed)
}else{
TFC_SetMotorPWM(0,0); //Make sure
motors are off
TFC_HBRIDGE_DISABLE;
}
//put a pattern on the LEDs....
if(TFC_Ticker[1] >= 125)
{
TFC_Ticker[1] = 0;
t++;
if(t>4)
{
t=0;
}
TFC_SetBatteryLED_Level(t);
break;
case 1:
//Demo mode 1 will just move the servos with
the on-board potentiometers
off
if(TFC_Ticker[0]>=1)
{
TFC_Ticker[0] = 0; //reset the Ticker
//Every 20 mSeconds, update the Servos
TFC_SetServo(0,TFC_ReadPot0());
TFC_SetServo(1,TFC_ReadPot1());
}
//Let's put a pattern on the LEDs
if(TFC_Ticker[1] >= 125)
{
TFC_Ticker[1] = 0;
t++;
if(t>4)
{
t=0;
}
TFC_SetBatteryLED_Level(t);
}
TFC_SetMotorPWM(0,0); //Make sure motors are
TFC_HBRIDGE_DISABLE;
break;
case 2 :
//Demo Mode 2 will use the Pots to make the
motors move
TFC_HBRIDGE_ENABLE;
TFC_SetMotorPWM(TFC_ReadPot(0),TFC_ReadPot(1));
//Let's put a pattern on the LEDs
if(TFC_Ticker[1] >= 125)
{
TFC_Ticker[1] = 0;
t++;
if(t>4)
{
t=0;
}
TFC_SetBatteryLED_Level(t);
}
break;
case 3 :
//Demo Mode 3 will be in Freescale Garage Mode.
It will beam data from the Camera to the
//Labview Application
if(TFC_Ticker[0]>100 && LineScanImageReady==1)
{
TFC_Ticker[0] = 0;
LineScanImageReady=0;
//TERMINAL_PRINTF("\r\n");
//TERMINAL_PRINTF("L:");
if(t==0)
t=3;
else
t--;
TFC_SetBatteryLED_Level(t);
for(i=0;i<128;i++)
{
TERMINAL_PRINTF("%X",LineScanImage0[i]);
}
TERMINAL_PRINTF("\r\n");
/*
for(i=0;i<128;i++)
{
TERMINAL_PRINTF("%X",LineScanImage1[i]);
if(i==127)
TERMINAL_PRINTF("\r\n",LineScanImage1[i]);
else
TERMINAL_PRINTF(",",LineScanImage1[i]);
}
*/
break;
}
}
return 0;
Source Code 5:
#include "derivative.h" /* include peripheral declarations */
#include "TFC\TFC.h"
#include <math.h>
#define steering_gain 1.2
#define steering_limit_high 0.6
#define steering_limit_low -0.6
//---------------------------------------------------------// Load the Notch Template Values (global array)
// (Cut and paste the C code that Matlab generated below)
//---------------------------------------------------------#define Nnotch 18
// number of elements in the Notch Template
float notch[Nnotch]; // Notch Template (vector should be zero mean and
normalized....)
void set_template_values(){
notch[0] = 0.334462147117700;
notch[1] = 0.273556199704827;
notch[2] = 0.179854742146561;
notch[3] = 0.062727920198728;
notch[4] = -0.030973537359538;
notch[5] = -0.143415286429457;
notch[6] = -0.227746598231897;
notch[7] = -0.312077910034337;
notch[8] = -0.335503274423903;
notch[9] = -0.330818201545990;
notch[10] = -0.255857035499377;
notch[11] = -0.176210796574851;
notch[12] = -0.068454120382844;
notch[13] = 0.015877191419595;
notch[14] = 0.133004013367428;
notch[15] = 0.231390543803607;
notch[16] = 0.315721855606047;
notch[17] = 0.334462147117700;
}
//-------------------------------------------------------------------// Compute what the steering angle should be from the camera data
//-------------------------------------------------------------------float compute_steering_angle(){
float vcomp[Nnotch];
float vsum,vmean,vdenom,vrecip,vnorm,vpeak,vturn;
float vturn1;
int offset_index;
int vpeak_index;
int Nnotch_center;
int i,j;
Nnotch_center = round(Nnotch/2);
vpeak_index = -1;
vpeak
= -1000;
//---------------------------------// Go through camera line data
//---------------------------------for(i=0; i<128-Nnotch+1; i++){
//--------------------------// Grab segment of line data
//---------------------------
vsum = 0;
for(j=0; j<Nnotch; j++){
vcomp[j] = LineScanImage0[i+j];
vsum
+= vcomp[j]; // start the mean processing
}
vmean = vsum/((float)Nnotch); // compute the mean of the segment
//--------------------------// Subtract mean
//--------------------------vsum = 0;
for(j=0; j<Nnotch; j++){
vcomp[j] -= vmean;
vsum
+= (vcomp[j]*vcomp[j]); // start the L2 norm
processing
}
vdenom = sqrt(vsum); // compute L2 norm of segment
if(vdenom != 0){
vrecip = 1/vdenom; // take reciprocal so we minimize
expensive divisions
//--------------------------// Normalize (if not zero)
//--------------------------vsum = 0;
for(j=0; j<Nnotch; j++){
vcomp[j] *= vrecip;
vsum
+= vcomp[j]*notch[j]; // perform the
inner product for L2 norm
}
vnorm = vsum; // the L2 norm
}else{
vnorm = 0;
}
//-----------------------------------// Find the maximum cross-correlation
//-----------------------------------if(vpeak < vnorm){
vpeak = vnorm;
vpeak_index = i + Nnotch_center - 1; // add offset so that
the center is at index 64
}
}
//-----------------------------------// Calculate how much to turn....
//-----------------------------------offset_index = vpeak_index-64;
vturn1 = (float)offset_index*0.6;
vturn = vturn1/64 * steering_gain; // implement steering gain to control
how fast it turns to center
if(vturn > steering_limit_high){
// limit the turn angle so that the
wheels don't hit the car
vturn = steering_limit_high;
}
if(vturn < steering_limit_low){
// limit the turn angle so that the
wheels don't hit the car
vturn = steering_limit_low;
}
return vturn;
int main(void)
{
uint32_t t;
int i=0;
TFC_Init();
set_template_values();
finding the line....
for(;;)
{
//TFC_Task must be called in your main loop.
certain processing happy (I.E. Serial port queue check
TFC_Task();
This keeps
Matlab
//-------------------------------------
--------
for(i=0;i<120;i++){
--
if(TFC_GetDIP_Switch()&0x01){
TFC_HBRIDGE_ENABLE;
TFC_SetMotorPWM(TFC_ReadPot0(),TFC_ReadPot(0));
// speed is set
via potentiometer (constant speed)
}else{
TFC_SetMotorPWM(0,0); //Make sure
motors are off
TFC_HBRIDGE_DISABLE;
}
//put a pattern on the LEDs....
if(TFC_Ticker[1] >= 125)
{
TFC_Ticker[1] = 0;
t++;
if(t>4)
{
t=0;
}
TFC_SetBatteryLED_Level(t);
}
break;
case 1:
//Demo mode 1 will just move the servos with
the on-board potentiometers
off
if(TFC_Ticker[0]>=1)
{
TFC_Ticker[0] = 0; //reset the Ticker
//Every 20 mSeconds, update the Servos
TFC_SetServo(0,TFC_ReadPot(0));
TFC_SetServo(1,TFC_ReadPot(1));
}
//Let's put a pattern on the LEDs
if(TFC_Ticker[1] >= 125)
{
TFC_Ticker[1] = 0;
t++;
if(t>4)
{
t=0;
}
TFC_SetBatteryLED_Level(t);
}
TFC_SetMotorPWM(0,0); //Make sure motors are
TFC_HBRIDGE_DISABLE;
break;
case 2 :
//Demo Mode 2 will use the Pots to make the
motors move
TFC_HBRIDGE_ENABLE;
TFC_SetMotorPWM(TFC_ReadPot(0),TFC_ReadPot(1));
//Let's put a pattern on the LEDs
if(TFC_Ticker[1] >= 125)
{
TFC_Ticker[1] = 0;
t++;
if(t>4)
{
t=0;
}
TFC_SetBatteryLED_Level(t);
}
break;
case 3 :
//Demo Mode 3 will be in Freescale Garage Mode.
It will beam data from the Camera to the
//Labview Application
if(TFC_Ticker[0]>100 && LineScanImageReady==1)
{
TFC_Ticker[0] = 0;
LineScanImageReady=0;
//TERMINAL_PRINTF("\r\n");
//TERMINAL_PRINTF("L:");
if(t==0)
t=3;
else
t--;
TFC_SetBatteryLED_Level(t);
for(i=0;i<128;i++)
{
TERMINAL_PRINTF("%X",LineScanImage0[i]);
}
TERMINAL_PRINTF("\r\n");
/*
for(i=0;i<128;i++)
{
TERMINAL_PRINTF("%X",LineScanImage1[i]);
if(i==127)
TERMINAL_PRINTF("\r\n",LineScanImage1[i]);
else
TERMINAL_PRINTF(",",LineScanImage1[i]);
}
}
*/
break;
}
return 0;
}
0.6
#define steering_limit_low
-0.6
float notch[Nnotch];
normalized....)
void set_template_values(){
notch[0] = 0.334462147117700;
notch[1] = 0.273556199704827;
notch[2] = 0.179854742146561;
notch[3] = 0.062727920198728;
notch[4] = -0.030973537359538;
notch[5] = -0.143415286429457;
notch[6] = -0.227746598231897;
notch[7] = -0.312077910034337;
notch[8] = -0.335503274423903;
notch[9] = -0.330818201545990;
notch[10] = -0.255857035499377;
notch[11] = -0.176210796574851;
notch[12] = -0.068454120382844;
notch[13] = 0.015877191419595;
notch[14] = 0.133004013367428;
notch[15] = 0.231390543803607;
notch[16] = 0.315721855606047;
notch[17] = 0.334462147117700;
}
//-------------------------------------------------------------------// Compute what the steering angle should be from the camera data
//-------------------------------------------------------------------float compute_steering_angle(){
float vcomp[Nnotch];
float vsum,vmean,vdenom,vrecip,vnorm,vpeak,vturn;
float vturn1;
int offset_index;
int vpeak_index;
int Nnotch_center;
int i,j;
Nnotch_center = round(Nnotch/2);
vpeak_index = -1;
vpeak
= -1000;
+= vcomp[j];
}
vmean = vsum/((float)Nnotch);
+= (vcomp[j]*vcomp[j]);
}
vdenom = sqrt(vsum);
if(vdenom != 0){
vrecip = 1/vdenom;
divisions
//--------------------------// Normalize (if not zero)
//---------------------------
vsum = 0;
for(j=0; j<Nnotch; j++){
vcomp[j] *= vrecip;
vsum
+= vcomp[j]*notch[j];
}
}
//-----------------------------------// Calculate how much to turn....
//-----------------------------------offset_index = vpeak_index-64;
vturn1 = (float)offset_index*0.6;
vturn = vturn1/64 * steering_gain;
how fast it turns to center
vturn = steering_limit_high;
}
vturn = steering_limit_low;
}
return vturn;
}
int main(void)
{
uint32_t t;
int i=0;
TFC_Init();
set_template_values();
the line....
for(;;)
{
//TFC_Task must be called in your main loop.
processing happy (I.E. Serial port queue check
TFC_Task();
default:
case 0 :
if(TFC_Ticker[0]>100 && LineScanImageReady==1){
TFC_Ticker[0] = 0;
LineScanImageReady=0;
TFC_SetMotorPWM(TFC_ReadPot(0),TFC_ReadPot(0));
// speed is set via potentiometer (constant speed)
}else{
TFC_SetMotorPWM(0,0); //Make sure motors are off
TFC_HBRIDGE_DISABLE;
}
break;
case 1:
//Demo mode 1 will just move the servos with the onboard potentiometers
if(TFC_Ticker[0]>=20)
{
TFC_Ticker[0] = 0; //reset the Ticker
//Every 20 mSeconds, update the Servos
TFC_SetServo(0,TFC_ReadPot(0));
TFC_SetServo(1,TFC_ReadPot(1));
}
//Let's put a pattern on the LEDs
if(TFC_Ticker[1] >= 125)
{
TFC_Ticker[1] = 0;
t++;
if(t>4)
{
t=0;
}
TFC_SetBatteryLED_Level(t);
}
break;
case 2 :
case 3 :
if(t==0)
t=3;
else
It
t--;
TFC_SetBatteryLED_Level(t);
for(i=0;i<128;i++)
{
TERMINAL_PRINTF("%X",LineScanImage0[i]);
}
TERMINAL_PRINTF("\r\n");
/*
for(i=0;i<128;i++)
{
TERMINAL_PRINTF("%X",LineScanImage1[i]);
if(i==127)
TERMINAL_PRINTF("\r\n",LineScanImage1[i]);
else
TERMINAL_PRINTF(",",LineScanImage1[i]);
}
break;
}
*/
return 0;
}