statemachine
Dependencies: mbed QEI HIDScope biquadFilter MODSERIAL FastPWM
main.cpp@19:1a3b61bd88c0, 2019-10-04 (annotated)
- Committer:
- boydmartherus
- Date:
- Fri Oct 04 08:08:55 2019 +0000
- Revision:
- 19:1a3b61bd88c0
- Parent:
- 18:3de4412d8b63
- Child:
- 20:184839c241a7
motorcontrol + print output met een ticker; werkend door mart op 3 okt
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
RobertoO | 0:67c50348f842 | 1 | #include "mbed.h" |
boydmartherus | 16:0ff43ed4d259 | 2 | #include "MODSERIAL.h" |
boydmartherus | 17:3751c2c685ca | 3 | #include "FastPWM.h" |
boydmartherus | 17:3751c2c685ca | 4 | #include "QEI.h" |
boydmartherus | 7:d5e07647dfea | 5 | |
boydmartherus | 7:d5e07647dfea | 6 | Serial pc(USBTX,USBRX); |
boydmartherus | 7:d5e07647dfea | 7 | |
boydmartherus | 17:3751c2c685ca | 8 | // functies aan PINs toevoegen |
boydmartherus | 9:cdcf30051100 | 9 | FastPWM led(PTA1); |
boydmartherus | 16:0ff43ed4d259 | 10 | FastPWM motor(D5); |
boydmartherus | 18:3de4412d8b63 | 11 | |
boydmartherus | 17:3751c2c685ca | 12 | AnalogIn pot(PTB2); |
boydmartherus | 17:3751c2c685ca | 13 | InterruptIn button(PTB3); |
boydmartherus | 9:cdcf30051100 | 14 | |
boydmartherus | 17:3751c2c685ca | 15 | // timer opzetten = ticker |
boydmartherus | 19:1a3b61bd88c0 | 16 | Ticker ticker; |
boydmartherus | 17:3751c2c685ca | 17 | |
boydmartherus | 17:3751c2c685ca | 18 | // opzetten van hoekbepaling |
boydmartherus | 16:0ff43ed4d259 | 19 | int pulses = 4200; |
boydmartherus | 18:3de4412d8b63 | 20 | QEI encoder (D13,D12,NC,pulses); |
MarliesWeggemans | 4:3e9a8f5d9a1a | 21 | |
boydmartherus | 17:3751c2c685ca | 22 | // aparte functies |
boydmartherus | 17:3751c2c685ca | 23 | // functie hoekbepaling |
boydmartherus | 17:3751c2c685ca | 24 | void hoek_bepaling() |
boydmartherus | 17:3751c2c685ca | 25 | { |
boydmartherus | 18:3de4412d8b63 | 26 | encoder.getPulses(); |
boydmartherus | 17:3751c2c685ca | 27 | } |
boydmartherus | 17:3751c2c685ca | 28 | |
boydmartherus | 17:3751c2c685ca | 29 | //functie motor aansturen met pot |
boydmartherus | 17:3751c2c685ca | 30 | void motor_running() |
boydmartherus | 17:3751c2c685ca | 31 | { |
boydmartherus | 17:3751c2c685ca | 32 | motor.write(pot); |
boydmartherus | 17:3751c2c685ca | 33 | led.write(pot); |
boydmartherus | 17:3751c2c685ca | 34 | } |
boydmartherus | 17:3751c2c685ca | 35 | |
boydmartherus | 17:3751c2c685ca | 36 | // functie print output |
boydmartherus | 18:3de4412d8b63 | 37 | void print_output() |
boydmartherus | 18:3de4412d8b63 | 38 | { |
boydmartherus | 19:1a3b61bd88c0 | 39 | pc.printf("motor speed is (%f)\r\n",pot.read()); |
boydmartherus | 18:3de4412d8b63 | 40 | pc.printf("pulse is (%i)\r\n",encoder.getPulses()); |
boydmartherus | 18:3de4412d8b63 | 41 | } |
boydmartherus | 17:3751c2c685ca | 42 | |
boydmartherus | 17:3751c2c685ca | 43 | void main_loop() |
boydmartherus | 17:3751c2c685ca | 44 | { |
boydmartherus | 17:3751c2c685ca | 45 | hoek_bepaling(); |
boydmartherus | 17:3751c2c685ca | 46 | motor_running(); |
boydmartherus | 19:1a3b61bd88c0 | 47 | } |
boydmartherus | 19:1a3b61bd88c0 | 48 | |
boydmartherus | 19:1a3b61bd88c0 | 49 | void print_loop() |
boydmartherus | 19:1a3b61bd88c0 | 50 | { |
boydmartherus | 18:3de4412d8b63 | 51 | print_output(); |
boydmartherus | 17:3751c2c685ca | 52 | } |
boydmartherus | 18:3de4412d8b63 | 53 | |
boydmartherus | 19:1a3b61bd88c0 | 54 | enum (start_wait, move) |
boydmartherus | 19:1a3b61bd88c0 | 55 | |
boydmartherus | 10:9101c7a4f219 | 56 | int main() |
boydmartherus | 10:9101c7a4f219 | 57 | { |
boydmartherus | 19:1a3b61bd88c0 | 58 | ticker.attach(&main_loop, 0.001f, &print_loop, 1f); |
boydmartherus | 17:3751c2c685ca | 59 | while(true){}; |
boydmartherus | 10:9101c7a4f219 | 60 | } |