Završni rad NXP Cup

Dependencies:   HBridgeDCMotor mbed FastPWM AutomationElements

main.cpp

Committer:
btomic
Date:
2016-05-06
Revision:
0:1b75c7a92a5e
Child:
1:50fc6689148e

File content as of revision 0:1b75c7a92a5e:

#include "mbed.h"
#include "HBridgeDCMotor.h"

DigitalIn fault(PTE20);

HBridgeDCMotor motor_a(PTC3, PTC4);
HBridgeDCMotor motor_b(PTC1, PTC2);

PwmOut servo(PTB0);
DigitalOut enable(PTE21);
Timer timer;

int main() {
    
    float sampleTime = 50e-3, switchingFrequency = 5000, rampTime = 3;    
    timer.start();
    motor_a.configure(sampleTime, switchingFrequency, rampTime, rampTime);
    motor_b.configure(sampleTime, switchingFrequency, rampTime, rampTime);
    servo.period(0.020);
    float pw=0,pw2=0;
    servo.pulsewidth(0.00100);
    wait(10);
    while(1){



        
 /**       if( timer.read()> 3 && timer.read()< 9 ){ **/
             motor_a.setDutyCycle(0.01);
             motor_b.setDutyCycle(0.01);       
      /**      }
        else if( timer.read()> 9 && timer.read()< 15){
            motor_a.setDutyCycle(-0.01);
            motor_b.setDutyCycle(-0.01);         
            }
        else if (timer.read()>5 && timer.read()<12){
**/ 
            for(pw=pw2; pw<0.00025; pw+=0.00001) {
                servo.pulsewidth(0.001+ pw);
                wait(0.1);
                }
                wait(3);
            for(pw2=pw; pw2>-0.00025; pw2-=0.00001) {
            servo.pulsewidth(0.001 + pw2);
            wait(0.1);
                }
                 wait(3);          
 /**           }
        else {
            motor_a.setDutyCycle(0);
            motor_b.setDutyCycle(0); 
       //     enable=0;
            } **/
        }



}