Group 9 BioRobotics / Mbed 2 deprecated the_code

Dependencies:   HIDScope Servo mbed QEI biquadFilter

main.cpp

Committer:
s1725696
Date:
2018-10-22
Revision:
4:8183e7b228f0
Parent:
3:624051175fdd
Child:
5:3581013d4505

File content as of revision 4:8183e7b228f0:

#include "mbed.h"
#include "HIDScope" // For displaying data
#include "FastPWM" // For setting PWM for motor
#include "MODSERIAL" // For getting information from keyboard 
#include "QEI" // For encoder of motors 

// In- en outputs //
// -----------------------------------------------------------------------------

// EMG related
AnalogIn emg1(A0); // EMG signal 1
AnalogIn emg2(A1); // EMG signal 2
/* if needed
AnalogIn emg3(A0); // EMG signal 3
AnalogIn emg4(A1); // EMG signal 4
*/

// Motor related
DigitalOut dirpin_1(D4); // direction of motor 1
PwmOut pwmpin_1(D5); // PWM pin of motor 1
DigitalOut dirpin_2(D6); // direction of motor 2
PwmOut pwmpin_2(D7); // PWM pin of motor 2

// Extra stuff
// Like LED lights, buttons etc 
DigitalIn button_motorcal(SW1); // button for motor calibration
DigitalIn button_emergency(SW2); // button for emergency mode
DigitalIn button_start(SW3); // button for start mode (from demo mode)
DigitalIn button_demo(SW4); // button for demo mode 
DigitalIn led_red(LED_RED); // red led 
DigitalIn led_green(LED_GREEN); // green led
DigitalIn led_blue(LED_BLUE); // blue led

// Other stuff
// -----------------------------------------------------------------------------
// Define stuff like tickers etc

Ticker NAME; // 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)
MODSERIAL pc(USBTX,USBRX);

// Variables 
// ----------------------------------------------------------------------------- 
// Define here all variables needed throughout the whole code 

// Functions
// -----------------------------------------------------------------------------
 
// Encoder 
// Getting encoder information from motors
int encoder()
{
    counts = Encoder.getPulses();
    return counts;
    }

// 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

// Send EMG to HIDScope
void sample() // Attach this to a ticker! 
{
    scope.set(0, emg1.read()); // send EMG 1 to channel 1 (=0)
    scope.set(1, emg2.read()); // sent EMG 2 to channel 2 (=1)
    /* If needed
    scope.set(2, emg3.read()); // send EMG 3 to channel 3 (=2)
    scope.set(3, emg4.read()); // sent EMG 4 to channel 4 (=3)
    */
    // Ensure that enough channels are available (HIDScope scope(2))
    scope.send(); // Send all channels to the PC at once
}

// Start
// To move the robot to the starting position: middle
void start() 
{
    // move to middle
    }

// Operating mode
// To control the robot with EMG signals

// Processing EMG 
// To process the raw EMG to a usable value, with filters etc
// Simon en Kees mee bezig 

// Demo mode
// To control the robot with a written code and write 'HELLO'
// Voor het laatst bewaren

// Emergency mode
// To shut down the robot after an error etc 

// Main function
// -----------------------------------------------------------------------------
int main()
{
    pc.baud(115200); // For TeraTerm, the baudrate, set also in TeraTerm itself! 
    pc.printf("Start code\r\n"); // To check if the program starts 
    
    while(true){
        if (button_motorcal == true){
            // execute motor calibration
            }
        elseif {
            // remain in waiting mode 
            break;
            }
            
}