Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed motorController2
Revision 3:e3b61eb0590b, committed 2016-12-09
- Comitter:
- BalB
- Date:
- Fri Dec 09 17:50:58 2016 +0000
- Parent:
- 2:50b081df251a
- Child:
- 4:6956b568c810
- Commit message:
- 1r programa con los 2 drivers
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Sun Dec 04 16:15:40 2016 +0000
+++ b/main.cpp Fri Dec 09 17:50:58 2016 +0000
@@ -3,7 +3,7 @@
#include "math.h"
//
-// By BalB
+// By BalB 9-12-16
//
#include "mbed.h"
AnalogIn top_left(A0); // Analog InPut
@@ -35,9 +35,11 @@
uint16_t measBR = 0;
int i=0; //iterator 1
int j=0; //iteerator 2
+int k=0; //iterator 3
char choice;
-int pos2;
+int pos2; // position of stepper2 (outside stepper)
+int pos1; // position of stepper1 (inside stepper)
int mitja_esquerra_adalt= 0; //Average of measures of PH
int mitja_dreta_adalt=0; //Average of measures of PH
@@ -89,82 +91,82 @@
stepper2.setCurrentPosition(0);
while(1)
{
- if(i==0)
- {
- pc.printf("Que vols fer, anar seguent grau?? (1)...Retrocedir ?? (2)");
- while(!pc.readable());
- choice=pc.getc();
- pc.printf("char= %d" ,choice-48);
- pc.printf(" ha leido");
- stepper2.moveTo(rint(-60*micro_steps2));//moveTo Sets target position
- stepper2.runToPosition();//Gives the order to go to that target position
- wait_ms(1500);
- }
- pos2=rint(micro_steps2*(i-60));
- stepper2.moveTo(pos2);//moveTo Sets target position
- stepper2.runToPosition();//Gives the order to go to that target position
- wait_ms(1000);
+ while (k<180){
+ pos1=rint(micro_steps1*k);
+ stepper1.moveTo(pos1);//moveTo Sets target position
+ stepper1.runToPosition();//Gives the order to go to that target position
+ i=0;
+ while(i<121){
+
+
+
+ if(i==0)
+ {
+ pc.printf("Que vols fer, anar seguent grau?? (1)...Retrocedir ?? (2)");
+ while(!pc.readable());
+ choice=pc.getc();
+ pc.printf("char= %d" ,choice-48);
+ pc.printf(": ha leido");
+ stepper2.moveTo(rint(-60*micro_steps2));//moveTo Sets target position
+ stepper2.runToPosition();//Gives the order to go to that target position
+ wait_ms(1500);
+ }
+ pos2=rint(micro_steps2*(i-60));
+ stepper2.moveTo(pos2);//moveTo Sets target position
+ stepper2.runToPosition();//Gives the order to go to that target position
+ wait_ms(1000);
- sum_top_left=0;
- sum_top_right=0;
- sum_bot_left=0;
- sum_bot_right=0;
+ sum_top_left=0;
+ sum_top_right=0;
+ sum_bot_left=0;
+ sum_bot_right=0;
- sum_var_top_left=0;
- sum_var_top_right=0;
- sum_var_bot_left=0;
- sum_var_bot_right=0;
+ sum_var_top_left=0;
+ sum_var_top_right=0;
+ sum_var_bot_left=0;
+ sum_var_bot_right=0;
- while(j<N)
- {
- val_top_left[j]=top_left.read_u16(); //Taking N measures
- val_top_right[j]=top_right.read_u16(); //Taking N measures
- val_bot_left[j]=bot_left.read_u16(); //Taking N measures
- val_bot_right[j]=bot_right.read_u16(); //Taking N measures
+ while(j<N)
+ {
+ val_top_left[j]=top_left.read_u16(); //Taking N measures
+ val_top_right[j]=top_right.read_u16(); //Taking N measures
+ val_bot_left[j]=bot_left.read_u16(); //Taking N measures
+ val_bot_right[j]=bot_right.read_u16(); //Taking N measures
- sum_top_left = sum_top_left + val_top_left[j]; //Making the sum of the measure for each PH
- sum_top_right = sum_top_right + val_top_right[j]; //Making the sum of the measure for each PH
- sum_bot_left = sum_bot_left + val_bot_left[j]; //Making the sum of the measure for each PH
- sum_bot_right = sum_bot_right + val_bot_right[j]; //Making the sum of the measure for each PH
+ sum_top_left = sum_top_left + val_top_left[j]; //Making the sum of the measure for each PH
+ sum_top_right = sum_top_right + val_top_right[j]; //Making the sum of the measure for each PH
+ sum_bot_left = sum_bot_left + val_bot_left[j]; //Making the sum of the measure for each PH
+ sum_bot_right = sum_bot_right + val_bot_right[j]; //Making the sum of the measure for each PH
- j++;
+ j++;
- }
+ }
- mitja_esquerra_adalt=double(rint((sum_top_left/N))); //Computiong the average
- mitja_dreta_adalt=double(rint((sum_top_right/N))); //Computiong the average
- mitja_esquerra_abaix=double(rint((sum_bot_left/N))); //Computiong the average
- mitja_dreta_abaix=double(rint((sum_bot_right/N))); //Computiong the average
+ mitja_esquerra_adalt=double(rint((sum_top_left/N))); //Computiong the average
+ mitja_dreta_adalt=double(rint((sum_top_right/N))); //Computiong the average
+ mitja_esquerra_abaix=double(rint((sum_bot_left/N))); //Computiong the average
+ mitja_dreta_abaix=double(rint((sum_bot_right/N))); //Computiong the average
- for (j=0;j<N;j++)
- {
- sum_var_top_left= ((val_top_left[j]-mitja_esquerra_adalt)*(val_top_left[j]-mitja_esquerra_adalt)) + sum_var_top_left; //Variance for each measure
- sum_var_top_right= ((val_top_right[j]-mitja_dreta_adalt)*(val_top_right[j]-mitja_dreta_adalt)) + sum_var_top_right; //Variance for each measure
- sum_var_bot_left= ((val_bot_left[j]-mitja_esquerra_abaix)*(val_bot_left[j]-mitja_esquerra_abaix)) + sum_var_bot_left; //Variance for each measure
- sum_var_bot_right= ((val_bot_right[j]-mitja_dreta_abaix)*(val_bot_right[j]-mitja_dreta_abaix)) + sum_var_bot_right; //Variance for each measure
-
- }
- val_var_top_left=double(rint(sqrt(sum_var_top_left/N))); //Obtaining Variance Value for this PH
- val_var_top_right=double(rint(sqrt(sum_var_top_right/N))); //Obtaining Variance Value for this PH
- val_var_bot_left=double(rint(sqrt(sum_var_bot_left/N))); //Obtaining Variance Value for this PH
- val_var_bot_right=double(rint(sqrt(sum_var_bot_right/N))); //Obtaining Variance Value for this PH
+ for (j=0;j<N;j++)
+ {
+ sum_var_top_left= ((val_top_left[j]-mitja_esquerra_adalt)*(val_top_left[j]-mitja_esquerra_adalt)) + sum_var_top_left; //Variance for each measure
+ sum_var_top_right= ((val_top_right[j]-mitja_dreta_adalt)*(val_top_right[j]-mitja_dreta_adalt)) + sum_var_top_right; //Variance for each measure
+ sum_var_bot_left= ((val_bot_left[j]-mitja_esquerra_abaix)*(val_bot_left[j]-mitja_esquerra_abaix)) + sum_var_bot_left; //Variance for each measure
+ sum_var_bot_right= ((val_bot_right[j]-mitja_dreta_abaix)*(val_bot_right[j]-mitja_dreta_abaix)) + sum_var_bot_right; //Variance for each measure
+
+ }
+ val_var_top_left=double(rint(sqrt(sum_var_top_left/N))); //Obtaining Variance Value for this PH
+ val_var_top_right=double(rint(sqrt(sum_var_top_right/N))); //Obtaining Variance Value for this PH
+ val_var_bot_left=double(rint(sqrt(sum_var_bot_left/N))); //Obtaining Variance Value for this PH
+ val_var_bot_right=double(rint(sqrt(sum_var_bot_right/N))); //Obtaining Variance Value for this PH
- //QUEDA PRINTEJAR RESULTATS
-
- if(i==121)
- {
- i=0;
- stepper2.moveTo (-60*micro_steps2);
- stepper2.runToPosition();
-
- }
- else if(i!=121)
- {
- i++;
- }
+ //QUEDA PRINTEJAR RESULTATS
+ i++;
+
+ }
/*
// Read the analog input value
@@ -178,8 +180,8 @@
wait_ms(800); // 800 ms
*/
-
-
+ k++;
+ }
}
}