for Bertl2014 HTL-Graz-Göoesting
Steuerung.cpp@0:50c6cfc49ead, 2015-12-29 (annotated)
- Committer:
- hemmer_matthias
- Date:
- Tue Dec 29 11:16:51 2015 +0000
- Revision:
- 0:50c6cfc49ead
- Child:
- 1:18c4a2bc1228
Motortest
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hemmer_matthias | 0:50c6cfc49ead | 1 | #include "mbed.h" |
hemmer_matthias | 0:50c6cfc49ead | 2 | |
hemmer_matthias | 0:50c6cfc49ead | 3 | // decleration for left engine |
hemmer_matthias | 0:50c6cfc49ead | 4 | PwmOut MotorL_EN(P1_15); |
hemmer_matthias | 0:50c6cfc49ead | 5 | DigitalOut MotorL_FORWARD(P1_1); |
hemmer_matthias | 0:50c6cfc49ead | 6 | DigitalOut MotorL_REVERSE(P1_0); |
hemmer_matthias | 0:50c6cfc49ead | 7 | |
hemmer_matthias | 0:50c6cfc49ead | 8 | // decleration for right engine |
hemmer_matthias | 0:50c6cfc49ead | 9 | PwmOut MotorR_EN(P0_21); |
hemmer_matthias | 0:50c6cfc49ead | 10 | DigitalOut MotorR_FORWARD(P1_3); |
hemmer_matthias | 0:50c6cfc49ead | 11 | DigitalOut MotorR_REVERSE(P1_4); |
hemmer_matthias | 0:50c6cfc49ead | 12 | |
hemmer_matthias | 0:50c6cfc49ead | 13 | void bertl_engine (int left, int right) |
hemmer_matthias | 0:50c6cfc49ead | 14 | { |
hemmer_matthias | 0:50c6cfc49ead | 15 | MotorL_EN = MotorR_EN = 1; |
hemmer_matthias | 0:50c6cfc49ead | 16 | |
hemmer_matthias | 0:50c6cfc49ead | 17 | int index_Engine = 0; |
hemmer_matthias | 0:50c6cfc49ead | 18 | |
hemmer_matthias | 0:50c6cfc49ead | 19 | if (left > 0 && right > 0) // decleration for left and right engine |
hemmer_matthias | 0:50c6cfc49ead | 20 | index_Engine = 1; |
hemmer_matthias | 0:50c6cfc49ead | 21 | |
hemmer_matthias | 0:50c6cfc49ead | 22 | else if (left < 0 && right > 0) |
hemmer_matthias | 0:50c6cfc49ead | 23 | index_Engine = 2; |
hemmer_matthias | 0:50c6cfc49ead | 24 | |
hemmer_matthias | 0:50c6cfc49ead | 25 | else if (left > 0 && right < 0) |
hemmer_matthias | 0:50c6cfc49ead | 26 | index_Engine = 3; |
hemmer_matthias | 0:50c6cfc49ead | 27 | |
hemmer_matthias | 0:50c6cfc49ead | 28 | else if (left < 0 && right < 0) |
hemmer_matthias | 0:50c6cfc49ead | 29 | index_Engine = 4; |
hemmer_matthias | 0:50c6cfc49ead | 30 | |
hemmer_matthias | 0:50c6cfc49ead | 31 | else if (left == 0 && right < 0) |
hemmer_matthias | 0:50c6cfc49ead | 32 | index_Engine = 5; |
hemmer_matthias | 0:50c6cfc49ead | 33 | |
hemmer_matthias | 0:50c6cfc49ead | 34 | else if (left == 0 && right > 0) |
hemmer_matthias | 0:50c6cfc49ead | 35 | index_Engine = 6; |
hemmer_matthias | 0:50c6cfc49ead | 36 | |
hemmer_matthias | 0:50c6cfc49ead | 37 | else if (left < 0 && right == 0) |
hemmer_matthias | 0:50c6cfc49ead | 38 | index_Engine = 7; |
hemmer_matthias | 0:50c6cfc49ead | 39 | |
hemmer_matthias | 0:50c6cfc49ead | 40 | else if (left > 0 && right == 0) |
hemmer_matthias | 0:50c6cfc49ead | 41 | index_Engine = 8; |
hemmer_matthias | 0:50c6cfc49ead | 42 | else |
hemmer_matthias | 0:50c6cfc49ead | 43 | index_Engine = 9; |
hemmer_matthias | 0:50c6cfc49ead | 44 | |
hemmer_matthias | 0:50c6cfc49ead | 45 | switch (index_Engine) //begin Switch |
hemmer_matthias | 0:50c6cfc49ead | 46 | { |
hemmer_matthias | 0:50c6cfc49ead | 47 | case 1: |
hemmer_matthias | 0:50c6cfc49ead | 48 | MotorR_EN = 1; |
hemmer_matthias | 0:50c6cfc49ead | 49 | MotorL_EN = 1; |
hemmer_matthias | 0:50c6cfc49ead | 50 | MotorL_FORWARD = 1; |
hemmer_matthias | 0:50c6cfc49ead | 51 | MotorR_FORWARD = 1; |
hemmer_matthias | 0:50c6cfc49ead | 52 | |
hemmer_matthias | 0:50c6cfc49ead | 53 | break; |
hemmer_matthias | 0:50c6cfc49ead | 54 | |
hemmer_matthias | 0:50c6cfc49ead | 55 | case 2: |
hemmer_matthias | 0:50c6cfc49ead | 56 | MotorR_EN = 1; |
hemmer_matthias | 0:50c6cfc49ead | 57 | MotorL_EN = 1; |
hemmer_matthias | 0:50c6cfc49ead | 58 | MotorL_REVERSE = 1; |
hemmer_matthias | 0:50c6cfc49ead | 59 | MotorR_FORWARD = 1; |
hemmer_matthias | 0:50c6cfc49ead | 60 | break; |
hemmer_matthias | 0:50c6cfc49ead | 61 | |
hemmer_matthias | 0:50c6cfc49ead | 62 | case 3: |
hemmer_matthias | 0:50c6cfc49ead | 63 | MotorR_EN = 1; |
hemmer_matthias | 0:50c6cfc49ead | 64 | MotorL_EN = 1; |
hemmer_matthias | 0:50c6cfc49ead | 65 | MotorL_FORWARD = 1; |
hemmer_matthias | 0:50c6cfc49ead | 66 | MotorR_REVERSE = 1; |
hemmer_matthias | 0:50c6cfc49ead | 67 | break; |
hemmer_matthias | 0:50c6cfc49ead | 68 | |
hemmer_matthias | 0:50c6cfc49ead | 69 | case 4: |
hemmer_matthias | 0:50c6cfc49ead | 70 | MotorR_EN = 1; |
hemmer_matthias | 0:50c6cfc49ead | 71 | MotorL_EN = 1; |
hemmer_matthias | 0:50c6cfc49ead | 72 | MotorL_REVERSE = 1; |
hemmer_matthias | 0:50c6cfc49ead | 73 | MotorR_REVERSE = 1; |
hemmer_matthias | 0:50c6cfc49ead | 74 | break; |
hemmer_matthias | 0:50c6cfc49ead | 75 | |
hemmer_matthias | 0:50c6cfc49ead | 76 | case 5: |
hemmer_matthias | 0:50c6cfc49ead | 77 | MotorL_EN = 0; |
hemmer_matthias | 0:50c6cfc49ead | 78 | MotorR_EN = 1; |
hemmer_matthias | 0:50c6cfc49ead | 79 | MotorR_REVERSE = 1; |
hemmer_matthias | 0:50c6cfc49ead | 80 | break; |
hemmer_matthias | 0:50c6cfc49ead | 81 | |
hemmer_matthias | 0:50c6cfc49ead | 82 | case 6: |
hemmer_matthias | 0:50c6cfc49ead | 83 | MotorL_EN = 0; |
hemmer_matthias | 0:50c6cfc49ead | 84 | MotorR_EN = 1; |
hemmer_matthias | 0:50c6cfc49ead | 85 | MotorR_FORWARD = 1; |
hemmer_matthias | 0:50c6cfc49ead | 86 | break; |
hemmer_matthias | 0:50c6cfc49ead | 87 | |
hemmer_matthias | 0:50c6cfc49ead | 88 | case 7: |
hemmer_matthias | 0:50c6cfc49ead | 89 | MotorR_EN = 0; |
hemmer_matthias | 0:50c6cfc49ead | 90 | MotorR_EN = 1; |
hemmer_matthias | 0:50c6cfc49ead | 91 | MotorL_REVERSE = 1; |
hemmer_matthias | 0:50c6cfc49ead | 92 | break; |
hemmer_matthias | 0:50c6cfc49ead | 93 | |
hemmer_matthias | 0:50c6cfc49ead | 94 | case 8: |
hemmer_matthias | 0:50c6cfc49ead | 95 | MotorR_EN = 0; |
hemmer_matthias | 0:50c6cfc49ead | 96 | MotorL_EN = 1; |
hemmer_matthias | 0:50c6cfc49ead | 97 | MotorL_FORWARD = 1; |
hemmer_matthias | 0:50c6cfc49ead | 98 | break; |
hemmer_matthias | 0:50c6cfc49ead | 99 | |
hemmer_matthias | 0:50c6cfc49ead | 100 | case 9: |
hemmer_matthias | 0:50c6cfc49ead | 101 | MotorR_EN = 0; |
hemmer_matthias | 0:50c6cfc49ead | 102 | MotorL_EN = 0; |
hemmer_matthias | 0:50c6cfc49ead | 103 | break; |
hemmer_matthias | 0:50c6cfc49ead | 104 | }//end Switch |
hemmer_matthias | 0:50c6cfc49ead | 105 | }//end bertl_engine |