Werkt

Dependencies:   Encoder HIDScope MODSERIAL QEI mbed

Fork of Inverse_kinematics_PIDController by Casper Kroon

main.cpp

Committer:
CasperK
Date:
2018-10-15
Revision:
0:dc2c63f663f8
Child:
1:fc216448bb57

File content as of revision 0:dc2c63f663f8:

#include "mbed.h"
#include "MODSERIAL.h"

DigitalIn button(SW2);
DigitalOut directionpin1(D7);
DigitalOut directionpin2(D8);
MODSERIAL pc(USBTX, USBRX);

volatile bool emg0;
volatile bool emg1;
volatile bool emg2;
volatile bool y_direction;
volatile int motor1_angle;
volatile int motor2_angle;
    
int main() {
    pc.printf(" ** program reset **\n\r");
    while (true) {
        
        //x direction
        if (emg0 || emg1){
            motor1_angle++;
            //cos function of motor1_angle
            motor2_angle++;
            //sin function of motor2_angle
            if (emg0 && !emg1) {
                directionpin1 = true;
            }
            else if (!emg0 && emg1) {
                directionpin1 = false;
            }
        }
              
        //y direction
        if (emg2) {
            motor2_angle++;
            if (y_direction) {
                directionpin2 = true;
            }
            else if (!y_direction) {
                directionpin2 = false;
            }
        }
        
        pc.printf("motor1 angle: %i\n\r", motor1_angle);
        pc.printf("motor2 angle: %i\n\r\n", motor2_angle);
        wait(0.5f);
    }
}