Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: HIDScope MODSERIAL QEI biquadFilter mbed Servo
Diff: main.cpp
- Revision:
- 23:7d83af123c43
- Parent:
- 22:31065a83d9e8
- Child:
- 25:734a26538711
- Child:
- 27:eee900e0a47d
--- a/main.cpp Mon Oct 29 12:21:26 2018 +0000 +++ b/main.cpp Mon Oct 29 12:32:39 2018 +0000 @@ -38,43 +38,25 @@ //Global variables/objects States current_state; -<<<<<<< local -Ticker loop_ticker; //The Ticker object that will ensure perfect timing of our looping code -float e, u1, u2, emg_signal_raw_0, processed_emg_0, emg_signal_raw_1, processed_emg_1, robot_end_x, robot_end_y, reference_end_x, reference_end_y, motor_angle_1, motor_angle_2, motor_counts_1, motor_counts_2, q_ref_1, q_ref_2; //will be set by the motor_controller function -======= double des_vx, des_vy, x, y, q1, q2, qref1, qref2, e1, e2, u1, u2, raw_emg_0, process_emg_0, raw_emg_1, process_emg_1; //will be set by the motor_controller function double vxmax = 1.0, vymax = 1.0; ->>>>>>> other + int counts_per_rotation = 32; bool state_changed = false; -<<<<<<< local -double x; // Making the position (x,y) of the end effector global -double y; -======= const double T = 0.001; ->>>>>>> other + // Functions void measure_all() { -<<<<<<< local - motor_angle_1 = motor_counts_1*2.0f*3.1415926535f/counts_per_rotation; //do this here, and not in the encoder interrupt, to reduce computational load - motor_angle_2 = motor_counts_2*2.0f*3.1415926535f/counts_per_rotation; - forwardkinematics_function(motor_angle_1,motor_angle_2); //motor_angle is global, this function ne - - emg_signal_raw_0 = emg0.read(); //sample analog voltages (all sampling theory applies, you might get aliasing etc.) - emg_signal_raw_1 = emg1.read(); - processed_emg_0 = processing_chain_emg(0); // some function ‘float my_emg_processing_chain()’ that returns a float. The raw emg is global - processed_emg_1 = processing_chain_emg(1); -======= + q1 = motor_1_encoder.getPulses()*2.0f*3.1415926535f/counts_per_rotation; //do this here, and not in the encoder interrupt, to reduce computational load q2 = motor_2_encoder.getPulses()*2.0f*3.1415926535f/counts_per_rotation; forwardkinematics_function(q1,q2,x,y); //motor_angle is global, this function ne raw_emg_0 = emg0.read(); //sample analog voltages (all sampling theory applies, you might get aliasing etc.) raw_emg_1 = emg1.read(); processing_chain_emg(raw_emg_0, raw_emg_1, process_emg_0, process_emg_1); // processes the emg signals ->>>>>>> other } void output_all() { @@ -117,13 +99,7 @@ break; case operational: //interpreting emg-signals to move the end effector - if (state_changed==true) { int x = 5; } - // example - reference_end_x = robot_end_x + processed_emg_0; - reference_end_y = robot_end_y + processed_emg_0; - -<<<<<<< local -======= + // here we have to determine the desired velocity based on the processed emg signals and calibration if (process_emg_0 >= 0.16) { des_vx = vxmax; } else if(process_emg_0 >= 0.09) { des_vx = vxmax * 0.66; } @@ -135,7 +111,6 @@ else if(process_emg_1 >= 0.02) { des_vy = vymax * 0.33; } else { des_vy = 0; } ->>>>>>> other if (button.read() == true) { current_state = demo; } break;