![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Signa-bot code for project BioRobotics, at University of Twente.
Dependencies: mbed QEI MODSERIAL FastPWM ttmath Math
Diff: Motor_tryout.cpp
- Revision:
- 13:18dd7a15603f
- Parent:
- 12:2382468d36a4
- Child:
- 14:b813ddfbcd71
--- a/Motor_tryout.cpp Sat Oct 05 12:27:51 2019 +0000 +++ b/Motor_tryout.cpp Mon Oct 07 12:40:19 2019 +0000 @@ -13,59 +13,61 @@ MODSERIAL pc(USBTX, USBRX); QEI Encoder(D12,D13,NC,64,QEI::X4_ENCODING); +// Global variables +int quit; +int counts = 0; +int limit_pos = 8400; + + // DE TICKERS, deze ticker Ticker pulse; -int counts; void pulseget() - { +{ counts = Encoder.getPulses(); + if(counts > limit_pos) + { + quit = 1; + } } +Ticker signal; +void get_signal() +{ + int signal = 0; + } + + // DE MAIN FUNCTIE int main(void) - { +{ pc.baud(115200); - char cc = pc.getc(); - pc.printf("In de main, check\r\n"); - pc.putc(cc); - if (cc == 'm' or cc == 'm') + pc.printf("In main\r\n"); + + while(true) + { + quit = 0; + counts = 0; + char cc = pc.getc(); + while(cc == 'g') { - pc.printf("In de if, check\r\n"); - pc.baud(115200); - int frequency_pwm = 10000; //10 kHz PWM - PwmOut motor1_pwm(PTC2); - PwmOut motor2_pwm(PTA2); - motor1_pwm.period(1.0/(double)frequency_pwm); // T=1/f - motor2_pwm.period(1.0/(double)frequency_pwm); // T=1/f - while(true) - { - pc.printf("In de while, check\r\n"); - - // MOTOR 1 START - int limit = 20000; - for(int pct = 55 ; pct <= 70 ; pct ++) - { - motor1_pwm.write(pct/100.0); // write Duty Cycle - pulse.attach(pulseget,1.0/100); - pc.printf("Motor 1 speed %i and the count is %i\r\n", pct, counts); - wait(1.0f); - if(counts > limit) - { - break; - } + int frequency_pwm = 10000; //10 kHz PWM + PwmOut motor1_pwm(PTC2); + PwmOut motor2_pwm(PTA2); + motor1_pwm.period(1.0/(double)frequency_pwm); // T=1/f + motor1_dir.write(0); // positief + motor1_pwm.write(0.56); // write Duty Cycle + pulse.attach(pulseget,1.0/10000); + if(quit == 1) + { + pulse.detach(); + motor1_pwm.write(0); + pc.printf("The motor is off with counts is %i\n\r",counts); + break; } - motor1_pwm.write(0.0f); // motor 1 off again - pc.printf("Motor 1 off\r\n"); - - // MOTOR TWEE START - for(int pct = 0 ; pct <= 100 ; pct += 10) - { - pc.printf("Motor 2\r\n"); - motor2_pwm.write(pct/100.0); // write Duty Cycle - wait(1.0f); - } - motor2_pwm.write(0.0f); // motor 2 off again - pc.printf("Motor 2 off\r\n"); + wait(1.0/1000); } + cc = pc.getc(); + counts = 0; + pc.printf("The motor is in final state and counts is %i\n\r",counts); } } \ No newline at end of file