for Bertl2014 HTL-Graz-Göoesting

Committer:
hemmer_matthias
Date:
Mon Jan 18 10:36:13 2016 +0000
Revision:
2:738a1372c90a
K?ck;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hemmer_matthias 2:738a1372c90a 1 #include "mbed.h"
hemmer_matthias 2:738a1372c90a 2
hemmer_matthias 2:738a1372c90a 3 // decleration for left engine
hemmer_matthias 2:738a1372c90a 4 PwmOut MotorL_EN(P1_15);
hemmer_matthias 2:738a1372c90a 5 DigitalOut MotorL_FORWARD(P1_1);
hemmer_matthias 2:738a1372c90a 6 DigitalOut MotorL_REVERSE(P1_0);
hemmer_matthias 2:738a1372c90a 7
hemmer_matthias 2:738a1372c90a 8 // decleration for right engine
hemmer_matthias 2:738a1372c90a 9 PwmOut MotorR_EN(P0_21);
hemmer_matthias 2:738a1372c90a 10 DigitalOut MotorR_FORWARD(P1_3);
hemmer_matthias 2:738a1372c90a 11 DigitalOut MotorR_REVERSE(P1_4);
hemmer_matthias 2:738a1372c90a 12
hemmer_matthias 2:738a1372c90a 13 void period_us(int periode) // underprogramm fot the periode
hemmer_matthias 2:738a1372c90a 14 {
hemmer_matthias 2:738a1372c90a 15 MotorL_EN.period_us(periode); // declaration for the Periode of the left egngine
hemmer_matthias 2:738a1372c90a 16 MotorR_EN.period_us(periode); // declaration for the Periode of the right egngine
hemmer_matthias 2:738a1372c90a 17 }
hemmer_matthias 2:738a1372c90a 18
hemmer_matthias 2:738a1372c90a 19 void bertl_engine(int left, int right)
hemmer_matthias 2:738a1372c90a 20 {
hemmer_matthias 2:738a1372c90a 21 int index_Engine = 0; // agrument for the Switch
hemmer_matthias 2:738a1372c90a 22
hemmer_matthias 2:738a1372c90a 23 // decleration for left and right engine
hemmer_matthias 2:738a1372c90a 24 if (left > 0 && right > 0) // all arguments are positive
hemmer_matthias 2:738a1372c90a 25 index_Engine = 1;
hemmer_matthias 2:738a1372c90a 26
hemmer_matthias 2:738a1372c90a 27 else if (left < 0 && right > 0) // left argument is negative and right is positive
hemmer_matthias 2:738a1372c90a 28 index_Engine = 2;
hemmer_matthias 2:738a1372c90a 29
hemmer_matthias 2:738a1372c90a 30 else if (left > 0 && right < 0) // left argument is positive and right is negative
hemmer_matthias 2:738a1372c90a 31 index_Engine = 3;
hemmer_matthias 2:738a1372c90a 32
hemmer_matthias 2:738a1372c90a 33 else if (left < 0 && right < 0) // left argument is negative and right is negative
hemmer_matthias 2:738a1372c90a 34 index_Engine = 4;
hemmer_matthias 2:738a1372c90a 35
hemmer_matthias 2:738a1372c90a 36 else if (left == 0 && right < 0) // left argument is zero and right is negative
hemmer_matthias 2:738a1372c90a 37 index_Engine = 5;
hemmer_matthias 2:738a1372c90a 38
hemmer_matthias 2:738a1372c90a 39 else if (left == 0 && right > 0) // left argument is zero and right is positive
hemmer_matthias 2:738a1372c90a 40 index_Engine = 6;
hemmer_matthias 2:738a1372c90a 41
hemmer_matthias 2:738a1372c90a 42 else if (left < 0 && right == 0) // left argument is negative and right is is zero
hemmer_matthias 2:738a1372c90a 43 index_Engine = 7;
hemmer_matthias 2:738a1372c90a 44
hemmer_matthias 2:738a1372c90a 45 else if (left > 0 && right == 0) // left argument is positive and right is is zero
hemmer_matthias 2:738a1372c90a 46 index_Engine = 8;
hemmer_matthias 2:738a1372c90a 47 else // all egines are zero
hemmer_matthias 2:738a1372c90a 48 index_Engine = 9;
hemmer_matthias 2:738a1372c90a 49
hemmer_matthias 2:738a1372c90a 50 switch (index_Engine) //begin Switch
hemmer_matthias 2:738a1372c90a 51 {
hemmer_matthias 2:738a1372c90a 52 case 1:
hemmer_matthias 2:738a1372c90a 53 MotorR_EN.pulsewidth_us(right); // to declratate the speed of the right engine (-us - +us)
hemmer_matthias 2:738a1372c90a 54 MotorL_EN.pulsewidth_us(left); // to declratate the speed of the left engine (-us - +us)
hemmer_matthias 2:738a1372c90a 55 MotorL_REVERSE = 0;
hemmer_matthias 2:738a1372c90a 56 MotorR_REVERSE = 0;
hemmer_matthias 2:738a1372c90a 57 MotorL_FORWARD = 1;
hemmer_matthias 2:738a1372c90a 58 MotorR_FORWARD = 1;
hemmer_matthias 2:738a1372c90a 59
hemmer_matthias 2:738a1372c90a 60 break;
hemmer_matthias 2:738a1372c90a 61
hemmer_matthias 2:738a1372c90a 62 case 2:
hemmer_matthias 2:738a1372c90a 63 MotorR_EN.pulsewidth_us(right);
hemmer_matthias 2:738a1372c90a 64 MotorL_EN.pulsewidth_us(-left);
hemmer_matthias 2:738a1372c90a 65 MotorL_FORWARD = 0;
hemmer_matthias 2:738a1372c90a 66 MotorR_REVERSE = 0;
hemmer_matthias 2:738a1372c90a 67 MotorL_REVERSE = 1;
hemmer_matthias 2:738a1372c90a 68 MotorR_FORWARD = 1;
hemmer_matthias 2:738a1372c90a 69 break;
hemmer_matthias 2:738a1372c90a 70
hemmer_matthias 2:738a1372c90a 71 case 3:
hemmer_matthias 2:738a1372c90a 72 MotorR_EN.pulsewidth_us(-right);
hemmer_matthias 2:738a1372c90a 73 MotorL_EN.pulsewidth_us(left);
hemmer_matthias 2:738a1372c90a 74 MotorL_REVERSE = 0;
hemmer_matthias 2:738a1372c90a 75 MotorR_FORWARD = 0;
hemmer_matthias 2:738a1372c90a 76 MotorL_FORWARD = 1;
hemmer_matthias 2:738a1372c90a 77 MotorR_REVERSE = 1;
hemmer_matthias 2:738a1372c90a 78 break;
hemmer_matthias 2:738a1372c90a 79
hemmer_matthias 2:738a1372c90a 80 case 4:
hemmer_matthias 2:738a1372c90a 81 MotorR_EN.pulsewidth_us(-right);
hemmer_matthias 2:738a1372c90a 82 MotorL_EN.pulsewidth_us(-left);
hemmer_matthias 2:738a1372c90a 83 MotorL_FORWARD = 0;
hemmer_matthias 2:738a1372c90a 84 MotorR_FORWARD = 0;
hemmer_matthias 2:738a1372c90a 85 MotorL_REVERSE = 1;
hemmer_matthias 2:738a1372c90a 86 MotorR_REVERSE = 1;
hemmer_matthias 2:738a1372c90a 87 break;
hemmer_matthias 2:738a1372c90a 88
hemmer_matthias 2:738a1372c90a 89 case 5:
hemmer_matthias 2:738a1372c90a 90 MotorL_EN = 0;
hemmer_matthias 2:738a1372c90a 91 MotorR_EN.pulsewidth_us(-right);
hemmer_matthias 2:738a1372c90a 92 MotorR_FORWARD = 0;
hemmer_matthias 2:738a1372c90a 93 MotorR_REVERSE = 1;
hemmer_matthias 2:738a1372c90a 94 break;
hemmer_matthias 2:738a1372c90a 95
hemmer_matthias 2:738a1372c90a 96 case 6:
hemmer_matthias 2:738a1372c90a 97 MotorL_EN = 0;
hemmer_matthias 2:738a1372c90a 98 MotorR_EN.pulsewidth_us(right);
hemmer_matthias 2:738a1372c90a 99 MotorR_REVERSE = 0;
hemmer_matthias 2:738a1372c90a 100 MotorR_FORWARD = 1;
hemmer_matthias 2:738a1372c90a 101 break;
hemmer_matthias 2:738a1372c90a 102
hemmer_matthias 2:738a1372c90a 103 case 7:
hemmer_matthias 2:738a1372c90a 104 MotorR_EN = 0;
hemmer_matthias 2:738a1372c90a 105 MotorL_EN.pulsewidth_us(-left);
hemmer_matthias 2:738a1372c90a 106 MotorL_FORWARD = 0;
hemmer_matthias 2:738a1372c90a 107 MotorL_REVERSE = 1;
hemmer_matthias 2:738a1372c90a 108 break;
hemmer_matthias 2:738a1372c90a 109
hemmer_matthias 2:738a1372c90a 110 case 8:
hemmer_matthias 2:738a1372c90a 111 MotorR_EN = 0;
hemmer_matthias 2:738a1372c90a 112 MotorL_EN.pulsewidth_us(left);
hemmer_matthias 2:738a1372c90a 113 MotorL_REVERSE = 0;
hemmer_matthias 2:738a1372c90a 114 MotorL_FORWARD = 1;
hemmer_matthias 2:738a1372c90a 115 break;
hemmer_matthias 2:738a1372c90a 116
hemmer_matthias 2:738a1372c90a 117 case 9:
hemmer_matthias 2:738a1372c90a 118 MotorR_EN = 0;
hemmer_matthias 2:738a1372c90a 119 MotorL_EN = 0;
hemmer_matthias 2:738a1372c90a 120 break;
hemmer_matthias 2:738a1372c90a 121 }//end Switch
hemmer_matthias 2:738a1372c90a 122 }//end bertl_engine