Završni rad NXP Cup
Dependencies: HBridgeDCMotor mbed FastPWM AutomationElements
main.cpp
- Committer:
- btomic
- Date:
- 2016-05-18
- Revision:
- 3:fc17c2ad6b81
- Parent:
- 2:25b8be806708
- Child:
- 4:d3c4924179f0
File content as of revision 3:fc17c2ad6b81:
#include "mbed.h" #include "HBridgeDCMotor.h" DigitalIn fault(PTE20); AnalogIn a_feedback(PTE23); AnalogIn b_feedback(PTE22); DigitalOut enable(PTE21); DigitalOut d1(PTB8); DigitalOut d2(PTB9); DigitalOut d3(PTB10); DigitalOut d4(PTB11); //DigitalOut red(PTB18); //DigitalOut green(PTB19); //DigitalOut blue(PTD1); //HBridgeDCMotor motor_a(PTC3, PTC4); //HBridgeDCMotor motor_b(PTC1, PTC2); PwmOut servo(PTB0); PwmOut motor1(PTC3); DigitalOut mot(PTC4); DigitalOut mot2(PTC1); DigitalOut mot22(PTC2); void steerServo(float angleDegrees){ float minPw = 0.00750, maxPw = 0.00125, minAng = -45, maxAng = 45, pulse = 0; pulse = minPw + ((maxPw - minPw)/(maxAng - minAng))*(angleDegrees - minAng); servo.pulsewidth(pulse); } int main() { float angleDegrees = 0; float sampleTime = 50e-3, switchingFrequency = 5000, rampTime = 3; servo.period(1.0/50); servo.pulsewidth(0.0010); motor1.period(0.0001); // motor_a.configure(sampleTime, switchingFrequency, rampTime, rampTime); // motor_b.configure(sampleTime, switchingFrequency, rampTime, rampTime); wait(5); enable = 1; while(1){ mot = 0; mot2 = 0; mot22 = 0; motor1.pulsewidth(0.00003); steerServo(angleDegrees); // motor_a.setDutyCycle(0.2); // motor_b.setDutyCycle(0.2); if(fault==1) {d1=1; d2=1; d3=1; d4=1;} else {d4=1;d1=1;} } enable = 0; // red = 1; }