![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
V0.1
Fork of motor_calibration by
Diff: main.cpp
- Revision:
- 3:d519ec330c31
- Parent:
- 2:ea985bb173f6
- Child:
- 4:2ee0d20f624b
--- a/main.cpp Fri Oct 26 07:51:43 2018 +0000 +++ b/main.cpp Fri Oct 26 09:42:46 2018 +0000 @@ -1,5 +1,5 @@ #include "mbed.h" - +#define SERIAL_BAUD 115200 //initial allocations DigitalOut dirpin(D4); @@ -8,41 +8,56 @@ PwmOut pwmpin2(D6); QEI Encoder(D12,D13,NC,64,QEI::X4_ENCODING); - +Serial pc(USBTX,USBRX); //volatiles volatile counts_prev=0; +volatile counts; //functions (2 functions not finished) int counts(){ + counts_prev=counts; int counts=Encoder.getPulses(); //MAAK NOG AF MET PREVIOUS COUNTS ONTHOUDEN. return counts; -int pos_store(a){} //store position in counts to know count location of the ends of bridge +void pos_store(a){} //store position in counts to know count location of the ends of bridge + static float pos1=0.1; + static float pos2=0.1; + static float pos3=0.1; + if (pos1 == 0.1){ + pos1=a; + else if (pos2 == 0.1){ + pos2=a; + else if (pos3 == 0.1){ + pos3=a; + else {} void translation_start(a,b); //start rail motor - dirpin.write(a); - pwmpin = b; + dirpin.write(a); + pwmpin = b; void translation_stop(); //stop rail motor - pwmpin = 0; + pwmpin = 0; void rotate_start(a,b){} //start rotation of disk - dirpin2.write(a); - pwmpin2 = b; + dirpin2.write(a); + pwmpin2 = b; void rotate_stop(){} //stop rotation of disk - pwmpin2 = 0; + pwmpin2 = 0; //main function int main(){ + pc.baud(115200); + pc.printf("start\r\n"); + pwmpin.period_us(60); //parameters int caltime=30; //calibration time until condition has been met, caltime=(time/0.1) float speed=0.50f; int dir=0; - int counts_end=; //amount of counts for 360 degrees rotation of main disk --> many revolutions of motor + int counts_end=10000; //amount of counts for 360 degrees rotation of main disk --> many revolutions of motor //move towards end for (m=1;2;m++){ @@ -50,11 +65,12 @@ //when motor counts do not change anymore, change direction int n=1; while(n=1){ - for (n=1;caltime;n++){ + /*for (n=1;caltime;n++){ if (counts()!=counts_prev){ n=0;} else {} - wait(0.1);} + wait(0.1);}*/ + wait(5); translation_stop(); int position=counts();} dir=dir+1; @@ -70,6 +86,8 @@ wait(0.01);} rotate_stop(); pos_store(counts2()); + printf("position 1 = %f, position 2 = %f, position 3 = %f /n",pos1,pos2,pos3); + printf("done"); //End sequence? }