IoTT Quad Control

Dependencies:   mbed

Fork of frdm_rgbled by Freescale

Committer:
johnmc
Date:
Tue Oct 06 20:40:58 2015 +0000
Revision:
8:e282aa7c1fe9
Parent:
7:ad8295723268
IoTT Quad;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
chris 0:cf8a48b1fb23 1 #include "mbed.h"
chris 0:cf8a48b1fb23 2
johnmc 8:e282aa7c1fe9 3 Serial pc(USBTX,USBRX);
johnmc 8:e282aa7c1fe9 4
johnmc 8:e282aa7c1fe9 5 PwmOut M1(PTD0);
johnmc 8:e282aa7c1fe9 6 PwmOut M2(PTD1);
johnmc 8:e282aa7c1fe9 7 PwmOut M3(PTD2);
johnmc 8:e282aa7c1fe9 8 PwmOut M4(PTD3);
johnmc 8:e282aa7c1fe9 9
johnmc 8:e282aa7c1fe9 10 //LED Outs
johnmc 8:e282aa7c1fe9 11 DigitalOut led_red(LED_RED);
johnmc 8:e282aa7c1fe9 12 DigitalOut led_green(LED_GREEN);
johnmc 8:e282aa7c1fe9 13
johnmc 8:e282aa7c1fe9 14 DigitalIn motion(D2);
chris 0:cf8a48b1fb23 15
sam_grove 7:ad8295723268 16 int main()
sam_grove 7:ad8295723268 17 {
johnmc 8:e282aa7c1fe9 18 pc.printf("Loading...\n\r");
johnmc 8:e282aa7c1fe9 19 pc.printf("%c\n\r",motion);
johnmc 8:e282aa7c1fe9 20 M1.period(0.0025f);
johnmc 8:e282aa7c1fe9 21 M2.period(0.0025f);
johnmc 8:e282aa7c1fe9 22 M3.period(0.0025f);
johnmc 8:e282aa7c1fe9 23 M4.period(0.0025f);
johnmc 8:e282aa7c1fe9 24 //Motor Off
johnmc 8:e282aa7c1fe9 25 M1.write(0.0f);
johnmc 8:e282aa7c1fe9 26 M2.write(0.0f);
johnmc 8:e282aa7c1fe9 27 M3.write(0.0f);
johnmc 8:e282aa7c1fe9 28 M4.write(0.00f);
johnmc 8:e282aa7c1fe9 29 led_red = 1;
johnmc 8:e282aa7c1fe9 30 led_green = 0;
johnmc 8:e282aa7c1fe9 31 wait (2.0f);
johnmc 8:e282aa7c1fe9 32 //Wait for Motion
emilmont 2:03e5c29343d1 33 while (true) {
johnmc 8:e282aa7c1fe9 34 led_red = 1;
johnmc 8:e282aa7c1fe9 35 led_green = 0;
johnmc 8:e282aa7c1fe9 36 pc.printf("Motors off; Waiting for motion...\n\r");
johnmc 8:e282aa7c1fe9 37 //Motor Off
johnmc 8:e282aa7c1fe9 38 M1.write(0.0f);
johnmc 8:e282aa7c1fe9 39 M2.write(0.0f);
johnmc 8:e282aa7c1fe9 40 M3.write(0.0f);
johnmc 8:e282aa7c1fe9 41 M4.write(0.0f);
johnmc 8:e282aa7c1fe9 42 wait (.0025f);
johnmc 8:e282aa7c1fe9 43 if(motion){
johnmc 8:e282aa7c1fe9 44 pc.printf("Motors On");
johnmc 8:e282aa7c1fe9 45 led_red = 0;
johnmc 8:e282aa7c1fe9 46 led_green = 1;
johnmc 8:e282aa7c1fe9 47 M1.write(0.5f); //Anything less than 50% duty cycle did not spin my motors.
johnmc 8:e282aa7c1fe9 48 M2.write(0.5f);
johnmc 8:e282aa7c1fe9 49 M3.write(0.5f);
johnmc 8:e282aa7c1fe9 50 M4.write(0.5f);
johnmc 8:e282aa7c1fe9 51 wait (.0025f);
johnmc 8:e282aa7c1fe9 52 }
johnmc 8:e282aa7c1fe9 53 //RAMP DOWN SEQUENCE to avoid ESC protection
johnmc 8:e282aa7c1fe9 54 M1.write(0.25f);
johnmc 8:e282aa7c1fe9 55 M2.write(0.25f);
johnmc 8:e282aa7c1fe9 56 M3.write(0.25f);
johnmc 8:e282aa7c1fe9 57 M4.write(0.25f);
johnmc 8:e282aa7c1fe9 58 wait (.0025f);
johnmc 8:e282aa7c1fe9 59 M1.write(0.15f);
johnmc 8:e282aa7c1fe9 60 M2.write(0.15f);
johnmc 8:e282aa7c1fe9 61 M3.write(0.15f);
johnmc 8:e282aa7c1fe9 62 M4.write(0.15f);
johnmc 8:e282aa7c1fe9 63 wait (.0025f);
johnmc 8:e282aa7c1fe9 64 M1.write(0.0f);
johnmc 8:e282aa7c1fe9 65 M2.write(0.0f);
johnmc 8:e282aa7c1fe9 66 M3.write(0.0f);
johnmc 8:e282aa7c1fe9 67 M4.write(0.0f);
johnmc 8:e282aa7c1fe9 68 wait (.0025f);
johnmc 8:e282aa7c1fe9 69 }
chris 1:eabc6f5b51d6 70 }
johnmc 8:e282aa7c1fe9 71