Testen #2
Dependencies: mbed
main.cpp@0:1fbaaa6da00a, 2016-01-11 (annotated)
- Committer:
- heinrich_kevin
- Date:
- Mon Jan 11 11:58:37 2016 +0000
- Revision:
- 0:1fbaaa6da00a
Test;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
heinrich_kevin | 0:1fbaaa6da00a | 1 | // Kevin Heinrich, 3AHEL, 21.12.2015 |
heinrich_kevin | 0:1fbaaa6da00a | 2 | // engine-test PWM for engines |
heinrich_kevin | 0:1fbaaa6da00a | 3 | // BERTL14 |
heinrich_kevin | 0:1fbaaa6da00a | 4 | |
heinrich_kevin | 0:1fbaaa6da00a | 5 | //Aufgabenstellung: |
heinrich_kevin | 0:1fbaaa6da00a | 6 | //1) Schreiben Sie eine Funktion void bertl_engine (int left, int right); |
heinrich_kevin | 0:1fbaaa6da00a | 7 | // Wobei die Variablen left bzw. right den linken bzw. rechten engine ansteuern |
heinrich_kevin | 0:1fbaaa6da00a | 8 | // und Werte von -255 bis +255 einnehmen koennen.Der Wert 0 bedeutet ausgeschaltet. |
heinrich_kevin | 0:1fbaaa6da00a | 9 | // Ein positiver Wert bedeutet vorwaerts, negativer Wert rueckwaerts. |
heinrich_kevin | 0:1fbaaa6da00a | 10 | |
heinrich_kevin | 0:1fbaaa6da00a | 11 | //2) Schreiben Sie eine Funktion bertl_engine_test()zum Testen der Funktion bertl_engine(). |
heinrich_kevin | 0:1fbaaa6da00a | 12 | // Dreht sich das richtige Rad in die richtige Richtung? |
heinrich_kevin | 0:1fbaaa6da00a | 13 | |
heinrich_kevin | 0:1fbaaa6da00a | 14 | //3) Verwenden Sie die Funktion bertl_engine() um den BERTL einen 8er fahren zu lassen. |
heinrich_kevin | 0:1fbaaa6da00a | 15 | |
heinrich_kevin | 0:1fbaaa6da00a | 16 | //Anmerkung: |
heinrich_kevin | 0:1fbaaa6da00a | 17 | |
heinrich_kevin | 0:1fbaaa6da00a | 18 | //Ich konnte leider den letzten Teil(8 Fahrt Rueckwaerts) selber nicht mehr testen. Mein BERTL hat Hardwaretechnische |
heinrich_kevin | 0:1fbaaa6da00a | 19 | //Probleme. Er laesst sich nicht mehr ueber PWM ansteuern. Außerdem funktioniert das andere Programm mit den LEDs auch nicht mehr. |
heinrich_kevin | 0:1fbaaa6da00a | 20 | //Ich werde nach den Ferien versuchen, das Problem zu beheben. |
heinrich_kevin | 0:1fbaaa6da00a | 21 | |
heinrich_kevin | 0:1fbaaa6da00a | 22 | #include <mbed.h> |
heinrich_kevin | 0:1fbaaa6da00a | 23 | //#include "bertl.h" |
heinrich_kevin | 0:1fbaaa6da00a | 24 | |
heinrich_kevin | 0:1fbaaa6da00a | 25 | DigitalOut engineLR(P1_0); //IN1, EP10, MG1A => MG1 engine-Pin 2, left_Reverse |
heinrich_kevin | 0:1fbaaa6da00a | 26 | DigitalOut engineLF(P1_1); //IN2, EP11, MG1B => MG1 engine-Pin 1, left_Forward |
heinrich_kevin | 0:1fbaaa6da00a | 27 | PwmOut engineLEN(p34); //EN1, P34, left_ENABLE |
heinrich_kevin | 0:1fbaaa6da00a | 28 | DigitalOut engineRR(P1_4); //IN4, EP13, MG2A => MG2 engine-Pin 2, right_Reverse |
heinrich_kevin | 0:1fbaaa6da00a | 29 | DigitalOut engineRF(P1_3); //IN3, EP14, MG2B => MG2 engine-Pin 1, right_Forward |
heinrich_kevin | 0:1fbaaa6da00a | 30 | PwmOut engineREN(p36); //EN2, P36, right_ENABLE |
heinrich_kevin | 0:1fbaaa6da00a | 31 | |
heinrich_kevin | 0:1fbaaa6da00a | 32 | void bertl_engine(int left, int right) |
heinrich_kevin | 0:1fbaaa6da00a | 33 | { |
heinrich_kevin | 0:1fbaaa6da00a | 34 | // If the left engines-value is greater than 0, the left engine turn FORWARD |
heinrich_kevin | 0:1fbaaa6da00a | 35 | if(left > 0) |
heinrich_kevin | 0:1fbaaa6da00a | 36 | { |
heinrich_kevin | 0:1fbaaa6da00a | 37 | engineLF=1; |
heinrich_kevin | 0:1fbaaa6da00a | 38 | engineLR=0; |
heinrich_kevin | 0:1fbaaa6da00a | 39 | } |
heinrich_kevin | 0:1fbaaa6da00a | 40 | // Or if the left engines-value is less than 0, the left engine turn REVERSE |
heinrich_kevin | 0:1fbaaa6da00a | 41 | else if(left < 0) |
heinrich_kevin | 0:1fbaaa6da00a | 42 | { |
heinrich_kevin | 0:1fbaaa6da00a | 43 | engineLF=0; |
heinrich_kevin | 0:1fbaaa6da00a | 44 | engineLR=1; |
heinrich_kevin | 0:1fbaaa6da00a | 45 | left = left * (-1); // For PWM the Value have to be positive |
heinrich_kevin | 0:1fbaaa6da00a | 46 | } |
heinrich_kevin | 0:1fbaaa6da00a | 47 | // If the right engines-value is greater than 0, the right engine turn FORWARD |
heinrich_kevin | 0:1fbaaa6da00a | 48 | if(right > 0) |
heinrich_kevin | 0:1fbaaa6da00a | 49 | { |
heinrich_kevin | 0:1fbaaa6da00a | 50 | engineRF=1; |
heinrich_kevin | 0:1fbaaa6da00a | 51 | engineRR=0; |
heinrich_kevin | 0:1fbaaa6da00a | 52 | } |
heinrich_kevin | 0:1fbaaa6da00a | 53 | // Or if the right engines-value is less than 0, the right engine turn REVERSE |
heinrich_kevin | 0:1fbaaa6da00a | 54 | else if(right < 0) |
heinrich_kevin | 0:1fbaaa6da00a | 55 | { |
heinrich_kevin | 0:1fbaaa6da00a | 56 | engineRF=0; |
heinrich_kevin | 0:1fbaaa6da00a | 57 | engineRR=1; |
heinrich_kevin | 0:1fbaaa6da00a | 58 | right = right * (-1); // For PWM the Value have to be positive |
heinrich_kevin | 0:1fbaaa6da00a | 59 | } |
heinrich_kevin | 0:1fbaaa6da00a | 60 | // Or if the right- or/and the left engines value equals 0, the ENABLE-Pin turn off (ENABLE Pin equals 0) |
heinrich_kevin | 0:1fbaaa6da00a | 61 | engineLEN=(left/255); // PWM Value : 0 ... 1 |
heinrich_kevin | 0:1fbaaa6da00a | 62 | engineREN=(right/255); // PWM Value : 0 ... 1 |
heinrich_kevin | 0:1fbaaa6da00a | 63 | } |
heinrich_kevin | 0:1fbaaa6da00a | 64 | /*Begin Testing bertl-engines |
heinrich_kevin | 0:1fbaaa6da00a | 65 | void bertl_engine_test() |
heinrich_kevin | 0:1fbaaa6da00a | 66 | { |
heinrich_kevin | 0:1fbaaa6da00a | 67 | bertl_engine(100, 0); //The left engine must turn FORWARD for 2 seconds |
heinrich_kevin | 0:1fbaaa6da00a | 68 | wait(2); |
heinrich_kevin | 0:1fbaaa6da00a | 69 | bertl_engine(0, 100); //The right engine must turn FORWARD for 2 seconds |
heinrich_kevin | 0:1fbaaa6da00a | 70 | wait(2); |
heinrich_kevin | 0:1fbaaa6da00a | 71 | bertl_engine(-100, 0); //The left engine must turn REVERSE for 2 seconds |
heinrich_kevin | 0:1fbaaa6da00a | 72 | wait(2); |
heinrich_kevin | 0:1fbaaa6da00a | 73 | bertl_engine(0, -100); //The right engine must turn REVERSE for 2 seconds |
heinrich_kevin | 0:1fbaaa6da00a | 74 | wait(2); |
heinrich_kevin | 0:1fbaaa6da00a | 75 | } |
heinrich_kevin | 0:1fbaaa6da00a | 76 | */ |
heinrich_kevin | 0:1fbaaa6da00a | 77 | //End Testing bertl-engines |
heinrich_kevin | 0:1fbaaa6da00a | 78 | int main() |
heinrich_kevin | 0:1fbaaa6da00a | 79 | { |
heinrich_kevin | 0:1fbaaa6da00a | 80 | //bertl_engine_test(); // Test the engines |
heinrich_kevin | 0:1fbaaa6da00a | 81 | while(1) |
heinrich_kevin | 0:1fbaaa6da00a | 82 | { |
heinrich_kevin | 0:1fbaaa6da00a | 83 | //BEGIN "Drive the Number 8: FORWARD" |
heinrich_kevin | 0:1fbaaa6da00a | 84 | bertl_engine(255, 50); |
heinrich_kevin | 0:1fbaaa6da00a | 85 | wait_ms(4900); |
heinrich_kevin | 0:1fbaaa6da00a | 86 | bertl_engine(50, 255); |
heinrich_kevin | 0:1fbaaa6da00a | 87 | wait_ms(4900); |
heinrich_kevin | 0:1fbaaa6da00a | 88 | //END "Drive the Number 8: FORWARD" |
heinrich_kevin | 0:1fbaaa6da00a | 89 | //BEGIN "Drive the Number 8: REVERSE" |
heinrich_kevin | 0:1fbaaa6da00a | 90 | //bertl_engine(-255, -50); |
heinrich_kevin | 0:1fbaaa6da00a | 91 | //wait_ms(4900); |
heinrich_kevin | 0:1fbaaa6da00a | 92 | //bertl_engine(-50, -255); |
heinrich_kevin | 0:1fbaaa6da00a | 93 | //wait_ms(4900); |
heinrich_kevin | 0:1fbaaa6da00a | 94 | //END "Drive the Number 8: REVERSE" |
heinrich_kevin | 0:1fbaaa6da00a | 95 | } |
heinrich_kevin | 0:1fbaaa6da00a | 96 | } |