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 Servo mbed QEI biquadFilter
Diff: main.cpp
- Revision:
- 10:56136a0da8c1
- Parent:
- 9:d7a6a3619576
--- a/main.cpp Fri Oct 26 09:40:09 2018 +0000 +++ b/main.cpp Fri Oct 26 10:09:13 2018 +0000 @@ -8,14 +8,13 @@ // In- en outputs // ----------------------------------------------------------------------------- -/* // EMG related AnalogIn emg1(); // EMG signal 1 AnalogIn emg2(); // EMG signal 2 // if needed AnalogIn emg3(); // EMG signal 3 AnalogIn emg4(); // EMG signal 4 -*/ + // Motor related DigitalOut dirpin_1(D4); // direction of motor 1 @@ -42,7 +41,7 @@ // ----------------------------------------------------------------------------- // Define stuff like tickers etc -Ticker NAME; // Name a ticker, use each ticker only for 1 function! +Ticker ticker; // Name a ticker, use each ticker only for 1 function! HIDScope scope(2); // Number of channels in HIDScope QEI Encoder(D13,D12,NC,64,QEI::X4_ENCODING); // Define the type of encoding: X4 encoding(default is X2) Serial pc(USBTX,USBRX); @@ -75,7 +74,7 @@ return counts; } -// potmeter +// Potmeter for contrlling motor float potmeter() { float out_1 = pot_1 * 2.0f; @@ -90,18 +89,6 @@ return out_2; } -// EMG filter -// To process the EMG signal before information can be caught from it -// Kees mee bezig - -// Motor calibration -// To calibrate the motor angle to some mechanical boundaries -// Kenneth mee bezig - -// EMG calibration -// To calibrate the EMG signal to some boundary values -// Simon mee bezig - // Send information to HIDScope void hidscope() // Attach this to a ticker! { @@ -112,27 +99,67 @@ scope.send(); // Send all channels to the PC at once } +// EMG filter +// To process the EMG signal before information can be caught from it +// Kees mee bezig + +// WAIT +// To do nothing +void wait_mode() +{ + // go back to the initial values + // Copy here the variables list with initial values + motor_velocity = 0; + } + +// MOTOR_CAL +// To calibrate the motor angle to some mechanical boundaries +// Kenneth mee bezig +void motor_calibration() +{ + // Kenneths code here + } + +// EMG_CAL +// To calibrate the EMG signal to some boundary values +void emg_calibration() +{ + // code + } + // PID controller // To control the input signal before it goes into the motor control // Simon mee bezig +void pid_controller() +{ + // Simons code here + } -// Start +// START // To move the robot to the starting position: middle -void start() +void start_mode() { // move to middle } -// Operating mode +// OPERATING // To control the robot with EMG signals // Gertjan bezig met motor aansturen -// Demo mode +// DEMO // To control the robot with a written code and write 'HELLO' // Voor het laatst bewaren +void demo_mode() +{ + // code here + } -// Emergency mode +// FAILURE // To shut down the robot after an error etc +void failure() +{ + // code here + } // Main function // ----------------------------------------------------------------------------- @@ -141,7 +168,7 @@ pc.baud(115200); // For TeraTerm, the baudrate, set also in TeraTerm itself! pc.printf("Start code\r\n"); // To check if the program starts pwmpin_1.period_us(60); // Setting period for PWM - NAME.attach(&hidscope,0.002f); // Send information to HIDScope + ticker.attach(&hidscope,0.002f); // Send information to HIDScope while(true){ // timer @@ -163,8 +190,11 @@ if(StateChanged) // so if StateChanged is true { + pc.printf("State is WAIT\r\n"); + // Execute WAIT mode - pc.printf("State is WAIT\r\n"); + wait_mode(); + StateChanged = false; // the state is still WAIT } @@ -190,10 +220,14 @@ { t.reset(); t.start(); + // Execute MOTOR_CAL mode + motor_calibration(); + t.stop(); time_in_state = t.read(); pc.printf("Time here = %f\r\n", time_in_state); + StateChanged = false; // the state is still MOTOR_CAL } @@ -219,10 +253,14 @@ { t.reset(); t.start(); + // Execute EMG_CAL mode + emg_calibration(); + t.stop(); time_in_state = t.read(); pc.printf("Time here = %f\r\n", time_in_state); + StateChanged = false; // state is still EMG_CAL } @@ -248,10 +286,14 @@ { t.reset(); t.start(); + // Execute START mode + start_mode(); + t.stop(); time_in_state = t.read(); pc.printf("Time here = %f\r\n", time_in_state); + StateChanged = false; // state is still START } @@ -276,7 +318,7 @@ if(StateChanged) // so if StateChanged is true { // Execute OPERATING mode - pc.printf("State is OPERATING\r\n"); + StateChanged = false; // state is still OPERATING } @@ -308,7 +350,8 @@ if(StateChanged) // so if StateChanged is true { // Execute FAILURE mode - pc.printf("State is FAILURE\r\n"); + failure_mode(); + StateChanged = false; // state is still FAILURE } @@ -326,7 +369,8 @@ if(StateChanged) // so if StateChanged is true { // Execute DEMO mode - pc.printf("State is DEMO\r\n"); + demo_mode(); + StateChanged = false; // state is still DEMO }