![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
control for robotic arm that can play chess using a granular gripper
Dependencies: Encoder mbed HIDScope Servo MODSERIAL
Fork of chessRobot by
Diff: emg.cpp
- Revision:
- 80:8f030bd5dd15
- Parent:
- 78:0cc7c64ba94c
- Child:
- 92:12e2e57e900a
- Child:
- 98:25528494287d
--- a/emg.cpp Tue Oct 20 13:21:29 2015 +0200 +++ b/emg.cpp Tue Oct 20 13:39:05 2015 +0200 @@ -1,20 +1,11 @@ #include "emg.h" #include "filter_constants.h" // All constants for EMG processing #include "mbed.h" +#include "buttons.h" -#define enableLed // Define objects AnalogIn emg1(A0); // Analog input 1 AnalogIn emg2(A1); // Analog input 2 -#ifdef enableLEd - DigitalOut ledred(LED_RED); // Red led - DigitalOut ledgreen(LED_GREEN); // Green led - DigitalOut ledblue(LED_BLUE); // Blue led -#else - DigitalOut ledred(d0); // Red led - DigitalOut ledgreen(d0); // Green led - DigitalOut ledblue(d0); // Blue led -#endif Ticker sample_tick; // Ticker for sampling Ticker output; // Ticker for PC output Timer normalizing_timer; // Timer for normalizing @@ -26,7 +17,7 @@ const int sample = 0; // Constant for mode switching for program readability const int normalize = 1; // Constant for mode switching for program readability - +bool ledsEnable = false; //********************************************************************************************** bool mode = normalize; // Set program mode //********************************************************************************************** @@ -248,20 +239,26 @@ // First normalizing step: channel 1 if (normalizing_timer.read_ms() <= normalize_time && channel == 1) { - ledred.write(off); - ledgreen.write(on); + if (ledsEnable){ + redLed.write(off); + greenLed.write(on); + } if (emg_filt_val1 > max_vol_cont1) { max_vol_cont1 = emg_filt_val1; } // Second normalizing step: wait time, switch channel } else if (normalizing_timer.read_ms() > normalize_time && channel == 1) { channel = 2; - ledgreen.write(off); - ledred.write(on); + if (ledsEnable){ + greenLed.write(off); + redLed.write(on); + } // Third normalizing step: channel 2 } else if (normalizing_timer.read_ms() >= (normalize_time + normalize_wait) && normalizing_timer.read_ms() <= (2*normalize_time + normalize_wait) && channel == 2) { - ledred.write(off); - ledgreen.write(on); + if (ledsEnable){ + redLed.write(off); + greenLed.write(on); + } if (emg_filt_val2 > max_vol_cont2) { max_vol_cont2 = emg_filt_val2; } @@ -269,9 +266,11 @@ } else if (normalizing_timer.read_ms() > (2*normalize_time + normalize_wait)) { normalizing_timer.stop(); normalizing_timer.reset(); - ledgreen.write(off); - ledred.write(off); - ledblue.write(on); + if (ledsEnable){ + greenLed.write(off); + redLed.write(off); + blueLed.write(on); + } mode = sample; } } @@ -304,9 +303,11 @@ EMG_check(thr_pass1, thr_pass2, x_velocity, y_velocity, z_velocity, emg_filt_val1, emg_filt_val2, EMG_timer.read_ms()); } else { - ledgreen.write(off); - ledred.write(on); - ledblue.write(off); + if (ledsEnable){ + greenLed.write(off); + redLed.write(on); + blueLed.write(off); + } } }