Robot
Dependencies: HIDScope MODSERIAL Motordriver QEI Servo mbed
Fork of The_Claw_with_EMG_Control_PID by
Diff: main.cpp
- Revision:
- 10:31e4c3d71ee6
- Parent:
- 9:90227be52903
- Child:
- 11:97f824629da5
--- a/main.cpp Wed Nov 02 15:30:54 2016 +0000 +++ b/main.cpp Wed Nov 02 15:54:32 2016 +0000 @@ -4,6 +4,7 @@ #include "motordriver.h" #include "QEI.h" #include "Servo.h" +#include "HIDScope.h" //======== Serial Communication ================================================ MODSERIAL pc(USBTX,USBRX); @@ -23,6 +24,8 @@ // servo Servo servo(D9); +HIDScope scope(2); //scope has two ports for the two EMG signals + //======== Miscellaneous ======================================================= // button InterruptIn btn(SW2); @@ -47,7 +50,8 @@ // ticker Ticker tick_part; // ticker to switch parts Ticker tick_part_arm; -Ticker sampleTicker; +Ticker sampleTicker; +Ticker measureTicker; //======== Variables =========================================================== // counters @@ -276,11 +280,21 @@ rhf_y = biquad_rhf(rno2_y, rhf_v1, rhf_v2, rhf_a1, rhf_a2, rhf_b0, rhf_b1, rhf_b2); rrect_y = fabs(rhf_y); rlf_y = biquad_rlf(rrect_y, rlf_v1, rlf_v2, rlf_a1, rlf_a2, rlf_b0, rlf_b1, rlf_b2)/0.2; + scope.set(1, llf_y); + scope.set(0, rlf_y); + scope.send(); } //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> //======== Functions and main ============================================================== +void Measure(){ + // encoder + position_cart = (Encoder_Cart.getPulses()*factor_cart) ; + ain_cart = pot_cart.read(); + +} + // Switch between Cart, Arm and Claw @@ -342,10 +356,6 @@ led_g = not LedOn; led_b = not LedOn; - // encoder - position_cart = (Encoder_Cart.getPulses()*factor_cart) ; - ain_cart = pot_cart.read(); - wait(0.1); pc.baud(115200); pc.printf("Distance in mm: %i\n", position_cart); @@ -455,6 +465,7 @@ tick_part.attach(&SwitchCart,kTimeToggle); tick_part_arm.attach(&SwitchArm,kTimeToggle); sampleTicker.attach(scopeSend,0.01); + measureTicker.attach(Measure, 0.01); btn_cart.fall(&SetValue2); btn_arm.fall(&SetValue3);