![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
4 directional EMG control of the XY table. Made during my bachelor end assignment.
Dependencies: C12832_lcd HIDScope mbed-dsp mbed
main.cpp@11:74ae4e5e11ab, 2015-04-28 (annotated)
- Committer:
- jessekaiser
- Date:
- Tue Apr 28 12:28:53 2015 +0000
- Revision:
- 11:74ae4e5e11ab
- Parent:
- 10:7f94cd65c910
- Child:
- 12:5099e4897586
- Child:
- 13:c4e80f6e7113
Potmeter besturing voor op en neer. Stapgewijs acceleratie;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jessekaiser | 0:3acdd563582f | 1 | #include "mbed.h" |
jessekaiser | 10:7f94cd65c910 | 2 | #include "C12832_lcd.h" |
jessekaiser | 0:3acdd563582f | 3 | |
jessekaiser | 11:74ae4e5e11ab | 4 | #define P_GAIN 0.9999 |
jessekaiser | 11:74ae4e5e11ab | 5 | |
jessekaiser | 0:3acdd563582f | 6 | DigitalOut Dir(p21); |
jessekaiser | 0:3acdd563582f | 7 | PwmOut Step(p22); |
jessekaiser | 0:3acdd563582f | 8 | DigitalOut MS1(p27); |
jessekaiser | 0:3acdd563582f | 9 | DigitalOut MS2(p28); |
jessekaiser | 0:3acdd563582f | 10 | DigitalOut MS3(p29); |
jessekaiser | 10:7f94cd65c910 | 11 | AnalogIn Pot1(p19); |
jessekaiser | 10:7f94cd65c910 | 12 | C12832_LCD lcd; |
jessekaiser | 0:3acdd563582f | 13 | |
jessekaiser | 10:7f94cd65c910 | 14 | BusIn Joystick(p12,p13,p14,p15,p16); |
jessekaiser | 10:7f94cd65c910 | 15 | DigitalIn Up(p15); |
jessekaiser | 10:7f94cd65c910 | 16 | DigitalIn Down(p12); |
jessekaiser | 0:3acdd563582f | 17 | int main() |
jessekaiser | 0:3acdd563582f | 18 | { |
jessekaiser | 11:74ae4e5e11ab | 19 | float setpoint = 2000; //Frequentie |
jessekaiser | 9:649229691351 | 20 | float step_freq = 1; |
jessekaiser | 4:e4341e3524dc | 21 | MS1 = 1; |
jessekaiser | 2:92a63245d11c | 22 | MS2 = 0; |
jessekaiser | 2:92a63245d11c | 23 | MS3 = 0; |
jessekaiser | 10:7f94cd65c910 | 24 | int p1; |
jessekaiser | 0:3acdd563582f | 25 | |
jessekaiser | 9:649229691351 | 26 | Step.period(1./step_freq); // 1 kHz, vanaf 2,5 kHz doet de motor het niet meer. |
jessekaiser | 9:649229691351 | 27 | Step.write(0.5); // Duty cycle van 50% |
jessekaiser | 10:7f94cd65c910 | 28 | // Dir = Pot1; // Dir 1 is naar boven, Dir 0 naar onder. |
jessekaiser | 0:3acdd563582f | 29 | while (1) { |
jessekaiser | 10:7f94cd65c910 | 30 | p1 = Pot1.read(); |
jessekaiser | 10:7f94cd65c910 | 31 | Dir = Pot1; |
jessekaiser | 9:649229691351 | 32 | float new_step_freq; |
jessekaiser | 11:74ae4e5e11ab | 33 | new_step_freq = ((1-P_GAIN)*setpoint) + (P_GAIN*step_freq); |
jessekaiser | 9:649229691351 | 34 | step_freq = new_step_freq; |
jessekaiser | 9:649229691351 | 35 | Step.period(1.0/step_freq); |
jessekaiser | 10:7f94cd65c910 | 36 | lcd.printf("Pot1 : %d \n", p1); |
jessekaiser | 10:7f94cd65c910 | 37 | wait(0.01); //Hier nog ticker inbouwen |
jessekaiser | 10:7f94cd65c910 | 38 | |
jessekaiser | 0:3acdd563582f | 39 | } |
jessekaiser | 0:3acdd563582f | 40 | } |