for Bertl2014 HTL-Graz-Göoesting
Steuerung.cpp@1:18c4a2bc1228, 2016-01-11 (annotated)
- Committer:
- hemmer_matthias
- Date:
- Mon Jan 11 12:16:19 2016 +0000
- Revision:
- 1:18c4a2bc1228
- Parent:
- 0:50c6cfc49ead
Motor_PWM
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 | 1:18c4a2bc1228 | 13 | void period_ms(int ms) |
hemmer_matthias | 1:18c4a2bc1228 | 14 | { |
hemmer_matthias | 1:18c4a2bc1228 | 15 | MotorL_EN.period_ms(ms); |
hemmer_matthias | 1:18c4a2bc1228 | 16 | MotorR_EN.period_ms(ms); |
hemmer_matthias | 1:18c4a2bc1228 | 17 | } |
hemmer_matthias | 1:18c4a2bc1228 | 18 | |
hemmer_matthias | 1:18c4a2bc1228 | 19 | void bertl_engine(int left, int right, int seconds) |
hemmer_matthias | 1:18c4a2bc1228 | 20 | { |
hemmer_matthias | 0:50c6cfc49ead | 21 | |
hemmer_matthias | 1:18c4a2bc1228 | 22 | /* int index_Engine = 0; |
hemmer_matthias | 1:18c4a2bc1228 | 23 | |
hemmer_matthias | 1:18c4a2bc1228 | 24 | // decleration for left and right engine |
hemmer_matthias | 1:18c4a2bc1228 | 25 | if (left > 0 && right > 0) |
hemmer_matthias | 0:50c6cfc49ead | 26 | index_Engine = 1; |
hemmer_matthias | 0:50c6cfc49ead | 27 | |
hemmer_matthias | 0:50c6cfc49ead | 28 | else if (left < 0 && right > 0) |
hemmer_matthias | 0:50c6cfc49ead | 29 | index_Engine = 2; |
hemmer_matthias | 0:50c6cfc49ead | 30 | |
hemmer_matthias | 0:50c6cfc49ead | 31 | else if (left > 0 && right < 0) |
hemmer_matthias | 0:50c6cfc49ead | 32 | index_Engine = 3; |
hemmer_matthias | 0:50c6cfc49ead | 33 | |
hemmer_matthias | 0:50c6cfc49ead | 34 | else if (left < 0 && right < 0) |
hemmer_matthias | 0:50c6cfc49ead | 35 | index_Engine = 4; |
hemmer_matthias | 0:50c6cfc49ead | 36 | |
hemmer_matthias | 0:50c6cfc49ead | 37 | else if (left == 0 && right < 0) |
hemmer_matthias | 0:50c6cfc49ead | 38 | index_Engine = 5; |
hemmer_matthias | 0:50c6cfc49ead | 39 | |
hemmer_matthias | 0:50c6cfc49ead | 40 | else if (left == 0 && right > 0) |
hemmer_matthias | 0:50c6cfc49ead | 41 | index_Engine = 6; |
hemmer_matthias | 0:50c6cfc49ead | 42 | |
hemmer_matthias | 0:50c6cfc49ead | 43 | else if (left < 0 && right == 0) |
hemmer_matthias | 0:50c6cfc49ead | 44 | index_Engine = 7; |
hemmer_matthias | 0:50c6cfc49ead | 45 | |
hemmer_matthias | 0:50c6cfc49ead | 46 | else if (left > 0 && right == 0) |
hemmer_matthias | 0:50c6cfc49ead | 47 | index_Engine = 8; |
hemmer_matthias | 0:50c6cfc49ead | 48 | else |
hemmer_matthias | 0:50c6cfc49ead | 49 | index_Engine = 9; |
hemmer_matthias | 0:50c6cfc49ead | 50 | |
hemmer_matthias | 0:50c6cfc49ead | 51 | switch (index_Engine) //begin Switch |
hemmer_matthias | 0:50c6cfc49ead | 52 | { |
hemmer_matthias | 0:50c6cfc49ead | 53 | case 1: |
hemmer_matthias | 1:18c4a2bc1228 | 54 | MotorR_EN.pulsewidth_ms(seconds); |
hemmer_matthias | 1:18c4a2bc1228 | 55 | MotorL_EN.pulsewidth_ms(seconds); |
hemmer_matthias | 1:18c4a2bc1228 | 56 | MotorL_REVERSE = 0; |
hemmer_matthias | 1:18c4a2bc1228 | 57 | MotorR_REVERSE = 0; |
hemmer_matthias | 0:50c6cfc49ead | 58 | MotorL_FORWARD = 1; |
hemmer_matthias | 1:18c4a2bc1228 | 59 | MotorR_FORWARD = 1; |
hemmer_matthias | 0:50c6cfc49ead | 60 | |
hemmer_matthias | 0:50c6cfc49ead | 61 | break; |
hemmer_matthias | 0:50c6cfc49ead | 62 | |
hemmer_matthias | 0:50c6cfc49ead | 63 | case 2: |
hemmer_matthias | 0:50c6cfc49ead | 64 | MotorR_EN = 1; |
hemmer_matthias | 0:50c6cfc49ead | 65 | MotorL_EN = 1; |
hemmer_matthias | 1:18c4a2bc1228 | 66 | MotorL_FORWARD = 0; |
hemmer_matthias | 1:18c4a2bc1228 | 67 | MotorR_REVERSE = 0; |
hemmer_matthias | 0:50c6cfc49ead | 68 | MotorL_REVERSE = 1; |
hemmer_matthias | 0:50c6cfc49ead | 69 | MotorR_FORWARD = 1; |
hemmer_matthias | 0:50c6cfc49ead | 70 | break; |
hemmer_matthias | 0:50c6cfc49ead | 71 | |
hemmer_matthias | 0:50c6cfc49ead | 72 | case 3: |
hemmer_matthias | 0:50c6cfc49ead | 73 | MotorR_EN = 1; |
hemmer_matthias | 0:50c6cfc49ead | 74 | MotorL_EN = 1; |
hemmer_matthias | 1:18c4a2bc1228 | 75 | MotorL_REVERSE = 0; |
hemmer_matthias | 1:18c4a2bc1228 | 76 | MotorR_FORWARD = 0; |
hemmer_matthias | 0:50c6cfc49ead | 77 | MotorL_FORWARD = 1; |
hemmer_matthias | 0:50c6cfc49ead | 78 | MotorR_REVERSE = 1; |
hemmer_matthias | 0:50c6cfc49ead | 79 | break; |
hemmer_matthias | 0:50c6cfc49ead | 80 | |
hemmer_matthias | 0:50c6cfc49ead | 81 | case 4: |
hemmer_matthias | 0:50c6cfc49ead | 82 | MotorR_EN = 1; |
hemmer_matthias | 0:50c6cfc49ead | 83 | MotorL_EN = 1; |
hemmer_matthias | 1:18c4a2bc1228 | 84 | MotorL_FORWARD = 0; |
hemmer_matthias | 1:18c4a2bc1228 | 85 | MotorR_FORWARD = 0; |
hemmer_matthias | 0:50c6cfc49ead | 86 | MotorL_REVERSE = 1; |
hemmer_matthias | 0:50c6cfc49ead | 87 | MotorR_REVERSE = 1; |
hemmer_matthias | 0:50c6cfc49ead | 88 | break; |
hemmer_matthias | 0:50c6cfc49ead | 89 | |
hemmer_matthias | 0:50c6cfc49ead | 90 | case 5: |
hemmer_matthias | 0:50c6cfc49ead | 91 | MotorL_EN = 0; |
hemmer_matthias | 0:50c6cfc49ead | 92 | MotorR_EN = 1; |
hemmer_matthias | 1:18c4a2bc1228 | 93 | MotorR_FORWARD = 0; |
hemmer_matthias | 0:50c6cfc49ead | 94 | MotorR_REVERSE = 1; |
hemmer_matthias | 0:50c6cfc49ead | 95 | break; |
hemmer_matthias | 0:50c6cfc49ead | 96 | |
hemmer_matthias | 0:50c6cfc49ead | 97 | case 6: |
hemmer_matthias | 0:50c6cfc49ead | 98 | MotorL_EN = 0; |
hemmer_matthias | 0:50c6cfc49ead | 99 | MotorR_EN = 1; |
hemmer_matthias | 1:18c4a2bc1228 | 100 | MotorR_REVERSE = 0; |
hemmer_matthias | 0:50c6cfc49ead | 101 | MotorR_FORWARD = 1; |
hemmer_matthias | 0:50c6cfc49ead | 102 | break; |
hemmer_matthias | 0:50c6cfc49ead | 103 | |
hemmer_matthias | 0:50c6cfc49ead | 104 | case 7: |
hemmer_matthias | 0:50c6cfc49ead | 105 | MotorR_EN = 0; |
hemmer_matthias | 1:18c4a2bc1228 | 106 | MotorL_EN = 1; |
hemmer_matthias | 1:18c4a2bc1228 | 107 | MotorL_FORWARD = 0; |
hemmer_matthias | 0:50c6cfc49ead | 108 | MotorL_REVERSE = 1; |
hemmer_matthias | 0:50c6cfc49ead | 109 | break; |
hemmer_matthias | 0:50c6cfc49ead | 110 | |
hemmer_matthias | 0:50c6cfc49ead | 111 | case 8: |
hemmer_matthias | 0:50c6cfc49ead | 112 | MotorR_EN = 0; |
hemmer_matthias | 0:50c6cfc49ead | 113 | MotorL_EN = 1; |
hemmer_matthias | 1:18c4a2bc1228 | 114 | MotorL_REVERSE = 0; |
hemmer_matthias | 0:50c6cfc49ead | 115 | MotorL_FORWARD = 1; |
hemmer_matthias | 0:50c6cfc49ead | 116 | break; |
hemmer_matthias | 0:50c6cfc49ead | 117 | |
hemmer_matthias | 0:50c6cfc49ead | 118 | case 9: |
hemmer_matthias | 0:50c6cfc49ead | 119 | MotorR_EN = 0; |
hemmer_matthias | 0:50c6cfc49ead | 120 | MotorL_EN = 0; |
hemmer_matthias | 0:50c6cfc49ead | 121 | break; |
hemmer_matthias | 1:18c4a2bc1228 | 122 | }//end Switch */ |
hemmer_matthias | 1:18c4a2bc1228 | 123 | }//end bertl_engine |