Group 9 BioRobotics / Mbed 2 deprecated the_code

Dependencies:   HIDScope Servo mbed QEI biquadFilter

Committer:
kweisbeek
Date:
Fri Oct 19 12:41:03 2018 +0000
Revision:
3:624051175fdd
Parent:
2:4b9c67f44848
Parent:
1:1a8211e1f3f3
Child:
4:8183e7b228f0
ok

Who changed what in which revision?

UserRevisionLine numberNew contents of line
s1725696 0:cb8857cf3ea4 1 #include "mbed.h"
s1725696 0:cb8857cf3ea4 2 #include "HIDScope" // For displaying data
s1725696 0:cb8857cf3ea4 3 #include "FastPWM" // For setting PWM for motor
s1725696 0:cb8857cf3ea4 4 #include "MODSERIAL" // For getting information from keyboard
s1725696 0:cb8857cf3ea4 5 #include "QEI" // For encoder of motors
s1725696 0:cb8857cf3ea4 6
s1725696 0:cb8857cf3ea4 7 // In- en outputs //
s1725696 0:cb8857cf3ea4 8 //-------------------------------------------------------------
kweisbeek 2:4b9c67f44848 9 //Kenneth
s1725696 0:cb8857cf3ea4 10 // EMG related
s1725696 0:cb8857cf3ea4 11 AnalogIn emg1(A0); // EMG signal 1
s1725696 0:cb8857cf3ea4 12 AnalogIn emg2(A1); // EMG signal 2
s1725696 0:cb8857cf3ea4 13 /* if needed
s1725696 0:cb8857cf3ea4 14 AnalogIn emg3(A0); // EMG signal 3
s1725696 0:cb8857cf3ea4 15 AnalogIn emg4(A1); // EMG signal 4
s1725696 0:cb8857cf3ea4 16 */
s1725696 0:cb8857cf3ea4 17
s1725696 0:cb8857cf3ea4 18 // Motor related
s1725696 0:cb8857cf3ea4 19 DigitalOut dirpin_1(D4); // direction of motor 1
s1725696 0:cb8857cf3ea4 20 PwmOut pwmpin_1(D5); // PWM pin of motor 1
s1725696 0:cb8857cf3ea4 21 DigitalOut dirpin_2(D6); // direction of motor 2
s1725696 0:cb8857cf3ea4 22 PwmOut pwmpin_2(D7); // PWM pin of motor 2
s1725696 0:cb8857cf3ea4 23
s1725696 0:cb8857cf3ea4 24 // Extra stuff
s1725696 0:cb8857cf3ea4 25 // Like LED lights, buttons etc
s1725696 0:cb8857cf3ea4 26
s1725696 0:cb8857cf3ea4 27 // Other stuff
s1725696 0:cb8857cf3ea4 28 // ------------------------------------------------------------
s1725696 0:cb8857cf3ea4 29 // Define stuff like tickers etc
s1725696 0:cb8857cf3ea4 30
s1725696 0:cb8857cf3ea4 31 Ticker NAME; // Name a ticker, use each ticker only for 1 function!
s1725696 0:cb8857cf3ea4 32 HIDScope scope(2); // Number of channels in HIDScope
s1725696 0:cb8857cf3ea4 33 QEI Encoder(D13,D12,NC,64,QEI::X4_ENCODING); // Define the type of encoding: X4 encoding(default is X2)
s1725696 0:cb8857cf3ea4 34 MODSERIAL pc(USBTX,USBRX);
s1725696 0:cb8857cf3ea4 35
s1725696 0:cb8857cf3ea4 36 // Variables
s1725696 0:cb8857cf3ea4 37 // ------------------------------------------------------------
s1725696 0:cb8857cf3ea4 38 // Define here all variables needed throughout the whole code
s1725696 0:cb8857cf3ea4 39
s1725696 0:cb8857cf3ea4 40 // Functions
s1725696 0:cb8857cf3ea4 41 // ------------------------------------------------------------
s1725696 0:cb8857cf3ea4 42
s1725696 0:cb8857cf3ea4 43 // Motor calibration
s1725696 0:cb8857cf3ea4 44 // To calibrate the motor angle to some mechanical boundaries
s1725696 0:cb8857cf3ea4 45
s1725696 0:cb8857cf3ea4 46 // EMG calibration
s1725696 0:cb8857cf3ea4 47 // To calibrate the EMG signal to some boundary values
s1725696 0:cb8857cf3ea4 48
s1725696 0:cb8857cf3ea4 49 // Send EMG to HIDScope
s1725696 0:cb8857cf3ea4 50 void sample() // attach this to a ticker!
s1725696 0:cb8857cf3ea4 51 {
s1725696 0:cb8857cf3ea4 52 scope.set(0, emg1.read()); // send EMG 1 to channel 1 (=0)
s1725696 0:cb8857cf3ea4 53 scope.set(1, emg2.read()); // sent EMG 2 to channel 2 (=1)
s1725696 0:cb8857cf3ea4 54 /* If needed
s1725696 0:cb8857cf3ea4 55 scope.set(2, emg3.read()); // send EMG 3 to channel 3 (=2)
s1725696 0:cb8857cf3ea4 56 scope.set(3, emg4.read()); // sent EMG 4 to channel 4 (=3)
s1725696 0:cb8857cf3ea4 57 */
s1725696 1:1a8211e1f3f3 58 // Ensure that enough channels are available (HIDScope scope(2))
s1725696 0:cb8857cf3ea4 59 scope.send(); // Send all channels to the PC at once
s1725696 0:cb8857cf3ea4 60 }
s1725696 0:cb8857cf3ea4 61
s1725696 0:cb8857cf3ea4 62 // Start
s1725696 0:cb8857cf3ea4 63 // To move the robot to the starting position: middle
s1725696 0:cb8857cf3ea4 64
s1725696 0:cb8857cf3ea4 65 // Operating mode
s1725696 0:cb8857cf3ea4 66 // To control the robot with EMG signals
s1725696 0:cb8857cf3ea4 67
s1725696 0:cb8857cf3ea4 68 // Processing EMG
s1725696 0:cb8857cf3ea4 69 // To process the raw EMG to a usable value, with filters etc
s1725696 0:cb8857cf3ea4 70
s1725696 0:cb8857cf3ea4 71 // Demo mode
s1725696 0:cb8857cf3ea4 72 // To control the robot with a written code and write 'HELLO'
s1725696 0:cb8857cf3ea4 73
s1725696 0:cb8857cf3ea4 74 // Emergency mode
s1725696 0:cb8857cf3ea4 75 // To shut down the robot after an error etc
s1725696 0:cb8857cf3ea4 76
s1725696 0:cb8857cf3ea4 77 // Main function
s1725696 0:cb8857cf3ea4 78 // ------------------------------------------------------------
s1725696 0:cb8857cf3ea4 79 int main()
s1725696 0:cb8857cf3ea4 80 {
s1725696 0:cb8857cf3ea4 81 pc.baud(115200); // For TeraTerm, the baudrate, set also in TeraTerm itself!
s1725696 0:cb8857cf3ea4 82 pc.printf("Start code\r\n"); // To check if the program starts
s1725696 1:1a8211e1f3f3 83
s1725696 1:1a8211e1f3f3 84 while(true){
s1725696 1:1a8211e1f3f3 85 //Laura verandert iets
s1725696 0:cb8857cf3ea4 86 }