![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
tbi fiat com controle feedforward PID
Dependencies: mbed reScale TextLCD
main.cpp@2:3c69c0772709, 2018-04-25 (annotated)
- Committer:
- Marcelocostanzo
- Date:
- Wed Apr 25 12:06:39 2018 +0000
- Revision:
- 2:3c69c0772709
- Parent:
- 0:b5a9e0614efd
- Child:
- 3:9d22aa32b223
Primeiro prototipo, n?o testado
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 0:b5a9e0614efd | 1 | #include "mbed.h" |
Marcelocostanzo | 2:3c69c0772709 | 2 | |
Marcelocostanzo | 2:3c69c0772709 | 3 | InterruptIn motora(D0); |
Marcelocostanzo | 2:3c69c0772709 | 4 | InterruptIn movida(D1); |
Marcelocostanzo | 2:3c69c0772709 | 5 | |
Marcelocostanzo | 2:3c69c0772709 | 6 | DigitalOut ign(LED1); |
mbed_official | 0:b5a9e0614efd | 7 | |
Marcelocostanzo | 2:3c69c0772709 | 8 | |
Marcelocostanzo | 2:3c69c0772709 | 9 | Timer tbase; |
Marcelocostanzo | 2:3c69c0772709 | 10 | Ticker call; |
Marcelocostanzo | 2:3c69c0772709 | 11 | |
Marcelocostanzo | 2:3c69c0772709 | 12 | Serial pc(USBTX, USBRX); // tx, rx |
Marcelocostanzo | 2:3c69c0772709 | 13 | |
Marcelocostanzo | 2:3c69c0772709 | 14 | unsigned long int t_motora, t_movida; |
mbed_official | 0:b5a9e0614efd | 15 | |
Marcelocostanzo | 2:3c69c0772709 | 16 | void tracao() |
Marcelocostanzo | 2:3c69c0772709 | 17 | { |
Marcelocostanzo | 2:3c69c0772709 | 18 | tbase.stop(); |
Marcelocostanzo | 2:3c69c0772709 | 19 | t_motora = tbase.read_us(); |
Marcelocostanzo | 2:3c69c0772709 | 20 | tbase.reset(); |
Marcelocostanzo | 2:3c69c0772709 | 21 | tbase.start(); |
Marcelocostanzo | 2:3c69c0772709 | 22 | } |
Marcelocostanzo | 2:3c69c0772709 | 23 | |
Marcelocostanzo | 2:3c69c0772709 | 24 | void livre() |
Marcelocostanzo | 2:3c69c0772709 | 25 | { |
Marcelocostanzo | 2:3c69c0772709 | 26 | tbase.stop(); |
Marcelocostanzo | 2:3c69c0772709 | 27 | t_movida = tbase.read_us(); |
Marcelocostanzo | 2:3c69c0772709 | 28 | tbase.reset(); |
Marcelocostanzo | 2:3c69c0772709 | 29 | tbase.start(); |
Marcelocostanzo | 2:3c69c0772709 | 30 | } |
Marcelocostanzo | 2:3c69c0772709 | 31 | |
Marcelocostanzo | 2:3c69c0772709 | 32 | void send() |
Marcelocostanzo | 2:3c69c0772709 | 33 | { |
Marcelocostanzo | 2:3c69c0772709 | 34 | pc.printf("Tempo: %.3f Hz \n\r"); |
Marcelocostanzo | 2:3c69c0772709 | 35 | } |
Marcelocostanzo | 2:3c69c0772709 | 36 | |
Marcelocostanzo | 2:3c69c0772709 | 37 | int main() |
Marcelocostanzo | 2:3c69c0772709 | 38 | { |
Marcelocostanzo | 2:3c69c0772709 | 39 | |
Marcelocostanzo | 2:3c69c0772709 | 40 | motora.fall(&tracao); // attach the address of the measure function to the rising edge |
Marcelocostanzo | 2:3c69c0772709 | 41 | movida.fall(&livre); // attach the address of the measure function to the rising edge |
Marcelocostanzo | 2:3c69c0772709 | 42 | |
Marcelocostanzo | 2:3c69c0772709 | 43 | //call.attach(&send, 0.5); |
Marcelocostanzo | 2:3c69c0772709 | 44 | |
Marcelocostanzo | 2:3c69c0772709 | 45 | while(1) |
Marcelocostanzo | 2:3c69c0772709 | 46 | { |
Marcelocostanzo | 2:3c69c0772709 | 47 | |
Marcelocostanzo | 2:3c69c0772709 | 48 | if(t_movida < t_motora) |
Marcelocostanzo | 2:3c69c0772709 | 49 | { |
Marcelocostanzo | 2:3c69c0772709 | 50 | ign=0; |
Marcelocostanzo | 2:3c69c0772709 | 51 | wait(0.1); |
Marcelocostanzo | 2:3c69c0772709 | 52 | } |
Marcelocostanzo | 2:3c69c0772709 | 53 | |
Marcelocostanzo | 2:3c69c0772709 | 54 | else |
Marcelocostanzo | 2:3c69c0772709 | 55 | { |
Marcelocostanzo | 2:3c69c0772709 | 56 | ign=1; |
Marcelocostanzo | 2:3c69c0772709 | 57 | } |
mbed_official | 0:b5a9e0614efd | 58 | } |
Marcelocostanzo | 2:3c69c0772709 | 59 | } |