groep17besturenmotornaarpotmeter

Dependencies:   MODSERIAL QEI mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include <iostream>
00003 #include <string>
00004 #include <stdio.h>
00005 #include <math.h>
00006 #include "MODSERIAL.h"
00007 #include "QEI.h"
00008 Serial pc(USBTX,USBRX);
00009 
00010 DigitalIn button1(D2);//rigth button on biorobotics shield
00011 DigitalIn button2(D3);//left button on biorobotics shield
00012 
00013 DigitalOut motor2_direction(D7);// draairichting motor 1 (1 is CW encoder als je daar op kijkt en CW shaft als je daar op kijkt)
00014 PwmOut motor2_speed_control(D6);//aanstuursnelheid motor 1
00015 PwmOut motor1_speed_control(D5);//aanstuursnelheid motor 1
00016 DigitalOut motor1_direction(D4);//draairichting motor 1 
00017 
00018 AnalogIn pot1(A2);
00019 AnalogIn pot2(A3);
00020 
00021 
00022 int main() {
00023     motor2_speed_control.period_us(55);//Sets frequency to 60 microsecondes 16.4 Khz
00024     while(true)    {
00025     
00026      float u1 = -1 + (2*pot1);  //Changes the pot value from [ 0 1 ] to [-1 1]
00027         if(u1 < 0)
00028           {
00029         motor1_direction = 0; //Sets motor direction 
00030             }
00031         else{
00032             motor1_direction = 1;//Sets motor in oppposite direction
00033             }
00034         
00035         motor1_speed_control = fabs(u1);
00036         
00037         float u2 = -1 + (2*pot2);  //Changes the pot value from [ 0 1 ] to [-1 1]
00038         if(u2 < 0)
00039           {
00040         motor2_direction = 0; //Sets motor direction 
00041             }
00042         else{
00043             motor2_direction = 1;//Sets motor in oppposite direction
00044             }
00045         
00046         motor2_speed_control = fabs(u2);
00047         if (button2 == false){
00048         motor1_speed_control = 0;
00049         motor2_speed_control = 0;
00050         return 0;
00051         }
00052     } 
00053 }
00054