Quadcopter control software
Dependencies: Pulse USBDevice mbed
main.cpp
- Committer:
- DanO21050
- Date:
- 2016-06-15
- Revision:
- 1:447dfa0477e9
- Parent:
- 0:28d8de532ed1
File content as of revision 1:447dfa0477e9:
#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 #define I2C_SDA_Pin PTB3 #define I2C_SCL_Pin PTB2 #define accelerometerAddress 0x6B DigitalOut Motor1(Motor1_Pin); AnalogIn MotorPowerLevel(AnalogIn_Pin); USBSerial serial; //Virtual serial port over USB I2C i2c(I2C_SDA_Pin,I2C_SCL_Pin); 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(); i2c.read serial.printf("I am a virtual serial port\r\n"); wait(1); //PWM_Motor1.pulsewidth(((1.0+currentPowerLevel)/1000.0)); } }