![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Robot tryout
Dependencies: mbed QEI biquadFilter MODSERIAL FastPWM ttmath Math
Motor_tryout.cpp
- Committer:
- Feike
- Date:
- 2019-10-07
- Revision:
- 14:b813ddfbcd71
- Parent:
- 13:18dd7a15603f
- Child:
- 16:2ad161f709f6
File content as of revision 14:b813ddfbcd71:
#include "mbed.h" #include "MODSERIAL.h" #include "QEI.h" // ALLE INPUT EN OUTPUT SIGNALEN DigitalOut motor1_pwm(PTC2); // aansturen motor 1, via poort PTC2 DigitalOut motor1_dir(PTC3); // richting motor 1 DigitalOut motor2_pwm(PTA2); // aansturen motor 2, via poort PTA2 DigitalOut motor2_dir(PTB23); // richting motor 2 DigitalOut motor3_pwm(PTA0); // aansturen motor 3, via poort PTA2 DigitalOut motor3_dir(PTC4); // richting motor 3 DigitalIn motor1_1(PTD1); // data vanuit motor 1 DigitalIn motor1_2(PTD3); // data vanuit motor 1 AnalogIn input(PTB3); // input van ECG MODSERIAL pc(USBTX, USBRX); \\QEI Encoder(D12,D13,NC,64,QEI::X4_ENCODING); \\QEI Encoder(D12,D13,NC,64,QEI::X4_ENCODING); QEI Encoder(D2,D3,NC,64,QEI::X4_ENCODING); // Global variables int quit; int counts = 0; int limit_pos = 8400; // DE TICKERS, deze ticker Ticker pulse; 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); pc.printf("In main\r\n"); while(true) { quit = 0; counts = 0; char cc = pc.getc(); while(cc == 'g') { int frequency_pwm = 10000; //10 kHz PWM PwmOut motor3_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; } wait(1.0/1000); } cc = pc.getc(); counts = 0; pc.printf("The motor is in final state and counts is %i\n\r",counts); } }