Testen #2
Dependencies: mbed
Revision 0:1fbaaa6da00a, committed 2016-01-11
- Comitter:
- heinrich_kevin
- Date:
- Mon Jan 11 11:58:37 2016 +0000
- Commit message:
- Test;
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r 1fbaaa6da00a main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Jan 11 11:58:37 2016 +0000 @@ -0,0 +1,96 @@ +// Kevin Heinrich, 3AHEL, 21.12.2015 +// engine-test PWM for engines +// BERTL14 + +//Aufgabenstellung: +//1) Schreiben Sie eine Funktion void bertl_engine (int left, int right); +// Wobei die Variablen left bzw. right den linken bzw. rechten engine ansteuern +// und Werte von -255 bis +255 einnehmen koennen.Der Wert 0 bedeutet ausgeschaltet. +// Ein positiver Wert bedeutet vorwaerts, negativer Wert rueckwaerts. + +//2) Schreiben Sie eine Funktion bertl_engine_test()zum Testen der Funktion bertl_engine(). +// Dreht sich das richtige Rad in die richtige Richtung? + +//3) Verwenden Sie die Funktion bertl_engine() um den BERTL einen 8er fahren zu lassen. + +//Anmerkung: + +//Ich konnte leider den letzten Teil(8 Fahrt Rueckwaerts) selber nicht mehr testen. Mein BERTL hat Hardwaretechnische +//Probleme. Er laesst sich nicht mehr ueber PWM ansteuern. Außerdem funktioniert das andere Programm mit den LEDs auch nicht mehr. +//Ich werde nach den Ferien versuchen, das Problem zu beheben. + +#include <mbed.h> +//#include "bertl.h" + +DigitalOut engineLR(P1_0); //IN1, EP10, MG1A => MG1 engine-Pin 2, left_Reverse +DigitalOut engineLF(P1_1); //IN2, EP11, MG1B => MG1 engine-Pin 1, left_Forward +PwmOut engineLEN(p34); //EN1, P34, left_ENABLE +DigitalOut engineRR(P1_4); //IN4, EP13, MG2A => MG2 engine-Pin 2, right_Reverse +DigitalOut engineRF(P1_3); //IN3, EP14, MG2B => MG2 engine-Pin 1, right_Forward +PwmOut engineREN(p36); //EN2, P36, right_ENABLE + +void bertl_engine(int left, int right) +{ + // If the left engines-value is greater than 0, the left engine turn FORWARD + if(left > 0) + { + engineLF=1; + engineLR=0; + } + // Or if the left engines-value is less than 0, the left engine turn REVERSE + else if(left < 0) + { + engineLF=0; + engineLR=1; + left = left * (-1); // For PWM the Value have to be positive + } + // If the right engines-value is greater than 0, the right engine turn FORWARD + if(right > 0) + { + engineRF=1; + engineRR=0; + } + // Or if the right engines-value is less than 0, the right engine turn REVERSE + else if(right < 0) + { + engineRF=0; + engineRR=1; + right = right * (-1); // For PWM the Value have to be positive + } + // Or if the right- or/and the left engines value equals 0, the ENABLE-Pin turn off (ENABLE Pin equals 0) + engineLEN=(left/255); // PWM Value : 0 ... 1 + engineREN=(right/255); // PWM Value : 0 ... 1 +} +/*Begin Testing bertl-engines +void bertl_engine_test() +{ + bertl_engine(100, 0); //The left engine must turn FORWARD for 2 seconds + wait(2); + bertl_engine(0, 100); //The right engine must turn FORWARD for 2 seconds + wait(2); + bertl_engine(-100, 0); //The left engine must turn REVERSE for 2 seconds + wait(2); + bertl_engine(0, -100); //The right engine must turn REVERSE for 2 seconds + wait(2); +} +*/ +//End Testing bertl-engines +int main() +{ + //bertl_engine_test(); // Test the engines + while(1) + { + //BEGIN "Drive the Number 8: FORWARD" + bertl_engine(255, 50); + wait_ms(4900); + bertl_engine(50, 255); + wait_ms(4900); + //END "Drive the Number 8: FORWARD" + //BEGIN "Drive the Number 8: REVERSE" + //bertl_engine(-255, -50); + //wait_ms(4900); + //bertl_engine(-50, -255); + //wait_ms(4900); + //END "Drive the Number 8: REVERSE" + } +}
diff -r 000000000000 -r 1fbaaa6da00a mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Mon Jan 11 11:58:37 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/4336505e4b1c \ No newline at end of file