Overzetten
Dependencies: HIDScope MODSERIAL mbed
main.cpp@4:a1691164d879, 2018-10-05 (annotated)
- Committer:
- ThomBMT
- Date:
- Fri Oct 05 11:42:05 2018 +0000
- Revision:
- 4:a1691164d879
- Parent:
- 3:4f5a67f4170b
- Child:
- 5:0ae4951e9b81
Problem, through testing, apperantly is in the HIDscope expression;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ThomBMT | 0:877f950fdfb5 | 1 | #include "mbed.h" |
ThomBMT | 0:877f950fdfb5 | 2 | #include "MODSERIAL.h" |
ThomBMT | 0:877f950fdfb5 | 3 | #include "HIDScope.h" |
ThomBMT | 0:877f950fdfb5 | 4 | MODSERIAL pc(USBTX, USBRX); |
ThomBMT | 0:877f950fdfb5 | 5 | |
ThomBMT | 0:877f950fdfb5 | 6 | DigitalOut DirectionPin1(D4); |
ThomBMT | 0:877f950fdfb5 | 7 | PwmOut PwmPin1(D5); |
ThomBMT | 0:877f950fdfb5 | 8 | DigitalOut DirectionPin2(D7); |
ThomBMT | 0:877f950fdfb5 | 9 | PwmOut PwmPin2(D6); |
ThomBMT | 0:877f950fdfb5 | 10 | DigitalIn Knop1(D3); |
ThomBMT | 0:877f950fdfb5 | 11 | DigitalIn Knop2(D2); |
ThomBMT | 0:877f950fdfb5 | 12 | DigitalIn Knop3(PTA4); |
ThomBMT | 0:877f950fdfb5 | 13 | DigitalIn Knop4(PTC6); |
ThomBMT | 0:877f950fdfb5 | 14 | |
ThomBMT | 0:877f950fdfb5 | 15 | //Define objects |
ThomBMT | 0:877f950fdfb5 | 16 | AnalogIn emg0( A0 ); |
ThomBMT | 0:877f950fdfb5 | 17 | AnalogIn emg1( A1 ); |
ThomBMT | 0:877f950fdfb5 | 18 | |
ThomBMT | 0:877f950fdfb5 | 19 | Ticker sample_timer; |
ThomBMT | 4:a1691164d879 | 20 | //HIDScope scope( 2 ); |
ThomBMT | 0:877f950fdfb5 | 21 | DigitalOut led(LED1); |
ThomBMT | 0:877f950fdfb5 | 22 | |
ThomBMT | 3:4f5a67f4170b | 23 | |
ThomBMT | 4:a1691164d879 | 24 | int Turn_Motor1() |
ThomBMT | 0:877f950fdfb5 | 25 | { |
ThomBMT | 4:a1691164d879 | 26 | if(Knop1==false) // Motor 1 rotates CW |
ThomBMT | 0:877f950fdfb5 | 27 | { |
ThomBMT | 0:877f950fdfb5 | 28 | float u = 0.8f; //determine useful value, this is not final |
ThomBMT | 0:877f950fdfb5 | 29 | DirectionPin1 = u > 0.0f; //either true or false |
ThomBMT | 0:877f950fdfb5 | 30 | // True = CW, for False = CW |
ThomBMT | 0:877f950fdfb5 | 31 | PwmPin1 = fabs(u); |
ThomBMT | 0:877f950fdfb5 | 32 | PwmPin2 = fabs(0.0); |
ThomBMT | 0:877f950fdfb5 | 33 | } |
ThomBMT | 0:877f950fdfb5 | 34 | |
ThomBMT | 4:a1691164d879 | 35 | else if (Knop3==false)// We see that Motor2 keeps rotating if we leave out the "else" statement, somehow the signal leaks |
ThomBMT | 0:877f950fdfb5 | 36 | { |
ThomBMT | 0:877f950fdfb5 | 37 | float u = 0.8f; |
ThomBMT | 0:877f950fdfb5 | 38 | DirectionPin1 = u < 0.0f; |
ThomBMT | 0:877f950fdfb5 | 39 | PwmPin1 = fabs(u); |
ThomBMT | 0:877f950fdfb5 | 40 | PwmPin2 = fabs(0.0); |
ThomBMT | 0:877f950fdfb5 | 41 | } |
ThomBMT | 0:877f950fdfb5 | 42 | |
ThomBMT | 4:a1691164d879 | 43 | else |
ThomBMT | 4:a1691164d879 | 44 | { |
ThomBMT | 4:a1691164d879 | 45 | float u = 0.0f; |
ThomBMT | 4:a1691164d879 | 46 | PwmPin1 = fabs(u); |
ThomBMT | 4:a1691164d879 | 47 | } |
ThomBMT | 4:a1691164d879 | 48 | return 0; |
ThomBMT | 4:a1691164d879 | 49 | } |
ThomBMT | 4:a1691164d879 | 50 | |
ThomBMT | 4:a1691164d879 | 51 | int Turn_Motor2() |
ThomBMT | 4:a1691164d879 | 52 | { |
ThomBMT | 4:a1691164d879 | 53 | if (Knop2==false) |
ThomBMT | 4:a1691164d879 | 54 | { |
ThomBMT | 4:a1691164d879 | 55 | float u = 0.8f; |
ThomBMT | 4:a1691164d879 | 56 | DirectionPin2 = u < 0.0f; |
ThomBMT | 4:a1691164d879 | 57 | PwmPin1 = fabs(0.0); |
ThomBMT | 4:a1691164d879 | 58 | PwmPin2 = fabs(u); |
ThomBMT | 4:a1691164d879 | 59 | } |
ThomBMT | 4:a1691164d879 | 60 | |
ThomBMT | 0:877f950fdfb5 | 61 | else if (Knop4==false) |
ThomBMT | 0:877f950fdfb5 | 62 | { |
ThomBMT | 0:877f950fdfb5 | 63 | float u = 0.8f; |
ThomBMT | 0:877f950fdfb5 | 64 | DirectionPin2 = u > 0.0f; |
ThomBMT | 0:877f950fdfb5 | 65 | PwmPin1 = fabs(0.0); |
ThomBMT | 0:877f950fdfb5 | 66 | PwmPin2 = fabs(u); |
ThomBMT | 0:877f950fdfb5 | 67 | |
ThomBMT | 0:877f950fdfb5 | 68 | } |
ThomBMT | 0:877f950fdfb5 | 69 | |
ThomBMT | 0:877f950fdfb5 | 70 | else |
ThomBMT | 0:877f950fdfb5 | 71 | { |
ThomBMT | 0:877f950fdfb5 | 72 | float u = 0.0f; |
ThomBMT | 4:a1691164d879 | 73 | PwmPin2 = fabs(u); |
ThomBMT | 0:877f950fdfb5 | 74 | } |
ThomBMT | 4:a1691164d879 | 75 | return 0; |
ThomBMT | 4:a1691164d879 | 76 | } |
ThomBMT | 4:a1691164d879 | 77 | /* |
ThomBMT | 4:a1691164d879 | 78 | void sample() |
ThomBMT | 4:a1691164d879 | 79 | { |
ThomBMT | 4:a1691164d879 | 80 | |
ThomBMT | 4:a1691164d879 | 81 | scope.set(0, emg0.read() ); |
ThomBMT | 4:a1691164d879 | 82 | scope.set(1, emg1.read() ); |
ThomBMT | 4:a1691164d879 | 83 | |
ThomBMT | 4:a1691164d879 | 84 | scope.send(); |
ThomBMT | 4:a1691164d879 | 85 | led = !led; |
ThomBMT | 4:a1691164d879 | 86 | } |
ThomBMT | 4:a1691164d879 | 87 | */ |
ThomBMT | 4:a1691164d879 | 88 | |
ThomBMT | 4:a1691164d879 | 89 | int main() |
ThomBMT | 4:a1691164d879 | 90 | { |
ThomBMT | 4:a1691164d879 | 91 | |
ThomBMT | 4:a1691164d879 | 92 | pc.baud(115200); |
ThomBMT | 4:a1691164d879 | 93 | // sample_timer.attach(&sample, 0.002); |
ThomBMT | 4:a1691164d879 | 94 | PwmPin1.period_us(120); //60 microseconds pwm period, 16.7 kHz |
ThomBMT | 4:a1691164d879 | 95 | |
ThomBMT | 4:a1691164d879 | 96 | for(;;) |
ThomBMT | 4:a1691164d879 | 97 | { |
ThomBMT | 4:a1691164d879 | 98 | Turn_Motor1(); |
ThomBMT | 4:a1691164d879 | 99 | Turn_Motor2(); |
ThomBMT | 0:877f950fdfb5 | 100 | } |
ThomBMT | 0:877f950fdfb5 | 101 | } |