
motor aansturing moet lineair zijn is het niet
Dependencies: MODSERIAL Encoder mbed HIDScope
main.cpp@3:c9f9db6581bc, 2015-09-28 (annotated)
- Committer:
- Zeekat
- Date:
- Mon Sep 28 09:22:19 2015 +0000
- Revision:
- 3:c9f9db6581bc
- Parent:
- 2:bcd68150136c
- Child:
- 4:e171c9fa5447
left langzaam-snel right same
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Zeekat | 0:5ea1875b307a | 1 | #include "mbed.h" |
Zeekat | 0:5ea1875b307a | 2 | |
Zeekat | 0:5ea1875b307a | 3 | //MOTOR |
Zeekat | 0:5ea1875b307a | 4 | // motor 1 en 2 zijn omgedraait |
Zeekat | 0:5ea1875b307a | 5 | // pinnen motor 1 -> pinnen motor 2 |
Zeekat | 0:5ea1875b307a | 6 | |
Zeekat | 0:5ea1875b307a | 7 | //motor 1 gegevens |
Zeekat | 0:5ea1875b307a | 8 | PwmOut motor1_aan(D6); // PWM signaal motor 2 (uit sheets) |
Zeekat | 0:5ea1875b307a | 9 | DigitalOut motor1_rich(D7); // digitaal signaal voor richting |
Zeekat | 0:5ea1875b307a | 10 | // einde motor 1 |
Zeekat | 0:5ea1875b307a | 11 | |
Zeekat | 0:5ea1875b307a | 12 | //motor 2 gegevens |
Zeekat | 0:5ea1875b307a | 13 | PwmOut motor2_aan(D5); // PWM signaal motor 1 (uit sheets) |
Zeekat | 0:5ea1875b307a | 14 | DigitalOut motor2_rich(D4); // digitaal signaal voor richting |
Zeekat | 0:5ea1875b307a | 15 | // einde motor 1 |
Zeekat | 0:5ea1875b307a | 16 | //EINDE MOTOR |
Zeekat | 0:5ea1875b307a | 17 | |
Zeekat | 0:5ea1875b307a | 18 | |
Zeekat | 0:5ea1875b307a | 19 | //POTMETERS |
Zeekat | 0:5ea1875b307a | 20 | AnalogIn potleft(A1); |
Zeekat | 0:5ea1875b307a | 21 | AnalogIn potright(A0); |
Zeekat | 0:5ea1875b307a | 22 | |
Zeekat | 0:5ea1875b307a | 23 | void move_mot1(float left) |
Zeekat | 0:5ea1875b307a | 24 | { |
Zeekat | 0:5ea1875b307a | 25 | if(left < 0.4) |
Zeekat | 1:8918d924f625 | 26 | { |
Zeekat | 3:c9f9db6581bc | 27 | float calc1 = left - 1; |
Zeekat | 3:c9f9db6581bc | 28 | float calc2 = abs(calc1); |
Zeekat | 3:c9f9db6581bc | 29 | float leftin = (calc2-0.6)*2.5 ; |
Zeekat | 1:8918d924f625 | 30 | motor1_aan.write(leftin); |
Zeekat | 0:5ea1875b307a | 31 | motor1_rich.write(0); |
Zeekat | 0:5ea1875b307a | 32 | } |
Zeekat | 0:5ea1875b307a | 33 | else if(left > 0.4 && left < 0.6) |
Zeekat | 0:5ea1875b307a | 34 | { |
Zeekat | 0:5ea1875b307a | 35 | motor1_aan.write(0); |
Zeekat | 0:5ea1875b307a | 36 | } |
Zeekat | 0:5ea1875b307a | 37 | else if(left > 0.6) |
Zeekat | 0:5ea1875b307a | 38 | { |
Zeekat | 2:bcd68150136c | 39 | float leftin = (left-0.6)*2.5; |
Zeekat | 1:8918d924f625 | 40 | motor1_aan.write(leftin); |
Zeekat | 0:5ea1875b307a | 41 | motor1_rich.write(1); |
Zeekat | 0:5ea1875b307a | 42 | } |
Zeekat | 0:5ea1875b307a | 43 | } |
Zeekat | 0:5ea1875b307a | 44 | |
Zeekat | 0:5ea1875b307a | 45 | void move_mot2(float right) |
Zeekat | 0:5ea1875b307a | 46 | { |
Zeekat | 0:5ea1875b307a | 47 | if(right < 0.4) |
Zeekat | 0:5ea1875b307a | 48 | { |
Zeekat | 3:c9f9db6581bc | 49 | float calc3 = right - 1; |
Zeekat | 3:c9f9db6581bc | 50 | float calc4 = abs(calc3); |
Zeekat | 3:c9f9db6581bc | 51 | float rightin = (calc4-0.6)*2.5 ; |
Zeekat | 1:8918d924f625 | 52 | motor2_aan.write(rightin); |
Zeekat | 0:5ea1875b307a | 53 | motor2_rich.write(0); |
Zeekat | 0:5ea1875b307a | 54 | } |
Zeekat | 0:5ea1875b307a | 55 | else if(right > 0.4 && right < 0.6) |
Zeekat | 0:5ea1875b307a | 56 | { |
Zeekat | 0:5ea1875b307a | 57 | motor2_aan.write(0); |
Zeekat | 0:5ea1875b307a | 58 | } |
Zeekat | 0:5ea1875b307a | 59 | else if(right > 0.6) |
Zeekat | 0:5ea1875b307a | 60 | { |
Zeekat | 2:bcd68150136c | 61 | float rightin = (right-0.6)*2.5; |
Zeekat | 1:8918d924f625 | 62 | motor2_aan.write(rightin); |
Zeekat | 0:5ea1875b307a | 63 | motor2_rich.write(1); |
Zeekat | 0:5ea1875b307a | 64 | } |
Zeekat | 0:5ea1875b307a | 65 | } |
Zeekat | 0:5ea1875b307a | 66 | |
Zeekat | 0:5ea1875b307a | 67 | |
Zeekat | 0:5ea1875b307a | 68 | |
Zeekat | 0:5ea1875b307a | 69 | int main() |
Zeekat | 0:5ea1875b307a | 70 | { |
Zeekat | 0:5ea1875b307a | 71 | |
Zeekat | 0:5ea1875b307a | 72 | while(true) |
Zeekat | 0:5ea1875b307a | 73 | { |
Zeekat | 0:5ea1875b307a | 74 | float left = potleft.read(); |
Zeekat | 0:5ea1875b307a | 75 | float right = potright.read(); |
Zeekat | 0:5ea1875b307a | 76 | move_mot1(left); |
Zeekat | 0:5ea1875b307a | 77 | move_mot2(right); |
Zeekat | 0:5ea1875b307a | 78 | wait(0.01f); |
Zeekat | 0:5ea1875b307a | 79 | } |
Zeekat | 0:5ea1875b307a | 80 | } |