Signa-bot code for project BioRobotics, at University of Twente.
Dependencies: mbed QEI MODSERIAL FastPWM ttmath Math
Motor_tryout.cpp@14:b813ddfbcd71, 2019-10-07 (annotated)
- Committer:
- Feike
- Date:
- Mon Oct 07 13:56:24 2019 +0000
- Revision:
- 14:b813ddfbcd71
- Parent:
- 13:18dd7a15603f
- Child:
- 16:2ad161f709f6
ok;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Feike | 4:bd21569250c7 | 1 | #include "mbed.h" |
Feike | 8:017b813c72bb | 2 | #include "MODSERIAL.h" |
Feike | 12:2382468d36a4 | 3 | #include "QEI.h" |
Feike | 4:bd21569250c7 | 4 | |
Feike | 12:2382468d36a4 | 5 | // ALLE INPUT EN OUTPUT SIGNALEN |
Feike | 8:017b813c72bb | 6 | DigitalOut motor1_pwm(PTC2); // aansturen motor 1, via poort PTC2 |
Feike | 12:2382468d36a4 | 7 | DigitalOut motor1_dir(PTC3); // richting motor 1 |
Feike | 12:2382468d36a4 | 8 | DigitalOut motor2_pwm(PTA2); // aansturen motor 2, via poort PTA2 |
Feike | 12:2382468d36a4 | 9 | DigitalOut motor2_dir(PTB23); // richting motor 2 |
Feike | 14:b813ddfbcd71 | 10 | DigitalOut motor3_pwm(PTA0); // aansturen motor 3, via poort PTA2 |
Feike | 14:b813ddfbcd71 | 11 | DigitalOut motor3_dir(PTC4); // richting motor 3 |
Feike | 8:017b813c72bb | 12 | DigitalIn motor1_1(PTD1); // data vanuit motor 1 |
Feike | 8:017b813c72bb | 13 | DigitalIn motor1_2(PTD3); // data vanuit motor 1 |
Feike | 8:017b813c72bb | 14 | AnalogIn input(PTB3); // input van ECG |
Feike | 8:017b813c72bb | 15 | MODSERIAL pc(USBTX, USBRX); |
Feike | 14:b813ddfbcd71 | 16 | \\QEI Encoder(D12,D13,NC,64,QEI::X4_ENCODING); |
Feike | 14:b813ddfbcd71 | 17 | \\QEI Encoder(D12,D13,NC,64,QEI::X4_ENCODING); |
Feike | 14:b813ddfbcd71 | 18 | QEI Encoder(D2,D3,NC,64,QEI::X4_ENCODING); |
Feike | 7:e119b12e5e7f | 19 | |
Feike | 13:18dd7a15603f | 20 | // Global variables |
Feike | 13:18dd7a15603f | 21 | int quit; |
Feike | 13:18dd7a15603f | 22 | int counts = 0; |
Feike | 13:18dd7a15603f | 23 | int limit_pos = 8400; |
Feike | 13:18dd7a15603f | 24 | |
Feike | 13:18dd7a15603f | 25 | |
Feike | 12:2382468d36a4 | 26 | // DE TICKERS, deze ticker |
Feike | 12:2382468d36a4 | 27 | Ticker pulse; |
Feike | 12:2382468d36a4 | 28 | void pulseget() |
Feike | 13:18dd7a15603f | 29 | { |
Feike | 12:2382468d36a4 | 30 | counts = Encoder.getPulses(); |
Feike | 13:18dd7a15603f | 31 | if(counts > limit_pos) |
Feike | 13:18dd7a15603f | 32 | { |
Feike | 13:18dd7a15603f | 33 | quit = 1; |
Feike | 13:18dd7a15603f | 34 | } |
Feike | 12:2382468d36a4 | 35 | } |
Feike | 12:2382468d36a4 | 36 | |
Feike | 13:18dd7a15603f | 37 | Ticker signal; |
Feike | 13:18dd7a15603f | 38 | void get_signal() |
Feike | 13:18dd7a15603f | 39 | { |
Feike | 13:18dd7a15603f | 40 | int signal = 0; |
Feike | 13:18dd7a15603f | 41 | } |
Feike | 13:18dd7a15603f | 42 | |
Feike | 13:18dd7a15603f | 43 | |
Feike | 12:2382468d36a4 | 44 | // DE MAIN FUNCTIE |
Feike | 4:bd21569250c7 | 45 | int main(void) |
Feike | 13:18dd7a15603f | 46 | { |
Feike | 8:017b813c72bb | 47 | pc.baud(115200); |
Feike | 13:18dd7a15603f | 48 | pc.printf("In main\r\n"); |
Feike | 13:18dd7a15603f | 49 | |
Feike | 13:18dd7a15603f | 50 | while(true) |
Feike | 13:18dd7a15603f | 51 | { |
Feike | 13:18dd7a15603f | 52 | quit = 0; |
Feike | 13:18dd7a15603f | 53 | counts = 0; |
Feike | 13:18dd7a15603f | 54 | char cc = pc.getc(); |
Feike | 13:18dd7a15603f | 55 | while(cc == 'g') |
Feike | 8:017b813c72bb | 56 | { |
Feike | 13:18dd7a15603f | 57 | int frequency_pwm = 10000; //10 kHz PWM |
Feike | 14:b813ddfbcd71 | 58 | PwmOut motor3_pwm(PTC2); |
Feike | 13:18dd7a15603f | 59 | PwmOut motor2_pwm(PTA2); |
Feike | 13:18dd7a15603f | 60 | motor1_pwm.period(1.0/(double)frequency_pwm); // T=1/f |
Feike | 13:18dd7a15603f | 61 | motor1_dir.write(0); // positief |
Feike | 13:18dd7a15603f | 62 | motor1_pwm.write(0.56); // write Duty Cycle |
Feike | 13:18dd7a15603f | 63 | pulse.attach(pulseget,1.0/10000); |
Feike | 13:18dd7a15603f | 64 | if(quit == 1) |
Feike | 13:18dd7a15603f | 65 | { |
Feike | 13:18dd7a15603f | 66 | pulse.detach(); |
Feike | 13:18dd7a15603f | 67 | motor1_pwm.write(0); |
Feike | 13:18dd7a15603f | 68 | pc.printf("The motor is off with counts is %i\n\r",counts); |
Feike | 13:18dd7a15603f | 69 | break; |
Feike | 8:017b813c72bb | 70 | } |
Feike | 13:18dd7a15603f | 71 | wait(1.0/1000); |
Feike | 8:017b813c72bb | 72 | } |
Feike | 13:18dd7a15603f | 73 | cc = pc.getc(); |
Feike | 13:18dd7a15603f | 74 | counts = 0; |
Feike | 13:18dd7a15603f | 75 | pc.printf("The motor is in final state and counts is %i\n\r",counts); |
Feike | 8:017b813c72bb | 76 | } |
Feike | 12:2382468d36a4 | 77 | } |