Quadcopter control software
Dependencies: Pulse USBDevice mbed
Revision 0:28d8de532ed1, committed 2016-06-14
- Comitter:
- DanO21050
- Date:
- Tue Jun 14 19:39:40 2016 +0000
- Child:
- 1:447dfa0477e9
- Commit message:
- Basic serial working with 1 motor
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Pulse.lib Tue Jun 14 19:39:40 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/NickRyder/code/Pulse/#fb79a4637a64
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/USBDevice.lib Tue Jun 14 19:39:40 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/USBDevice/#01321bd6ff89
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Jun 14 19:39:40 2016 +0000 @@ -0,0 +1,67 @@ +#include "mbed.h" +#include "Pulse.h" +#include "USBSerial.h" +//#include "Servo.h" + +#define Motor1_Pin PTA12 //D3 PWM port + +#define AnalogIn_Pin PTD1 //A0 Port +DigitalOut Motor1(Motor1_Pin); +AnalogIn MotorPowerLevel(AnalogIn_Pin); + +//Virtual serial port over USB +USBSerial serial; + +Ticker ticker1; + +int motor1Status = 0; + +int frequency = 250; +float period = 1.0/frequency; + + +float currentPowerLevel = 0; + +void motor1Pulse(){ + ticker1.detach(); + if(motor1Status == 0){ + Motor1.write(1); + motor1Status = 1; + ticker1.attach(&motor1Pulse, (currentPowerLevel+1.0)/1000.0); + } + else{ + Motor1.write(0); + motor1Status = 0; + ticker1.attach(&motor1Pulse, period-(currentPowerLevel+1.0)/1000.0); + } + +} +/*void motor1Pulse(){ + ticker1.detach(); + Motor1.write(0); + ticker1.attach(&motor1OnPulse, currentPowerLevel/1000.0); +}*/ + + +int main() +{ + //PWM_Motor1.period(.004); //set motor PWM frequency to 250 Hz + //PWM_Motor1.period(.01); //set motor PWM frequency to 100 Hz + //PWM_Motor1 = .5; //any value from 0 to 1 + //PWM_Motor1.pulsewidth_ms(2.0); + //wait(4); + //PWM_Motor1.pulsewidth_ms(1.0); + + motor1Status = 1; + ticker1.attach(&motor1Pulse, (currentPowerLevel+1.0)/1000.0); + + + while(1){ + currentPowerLevel = MotorPowerLevel.read(); + + serial.printf("I am a virtual serial port\r\n"); + wait(1); + //PWM_Motor1.pulsewidth(((1.0+currentPowerLevel)/1000.0)); + + } +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Tue Jun 14 19:39:40 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/6c34061e7c34 \ No newline at end of file