ESE350 project, Spring 2016, University of Pennsylvania

Dependencies:   Adafruit9-DOf Receiver mbed-rtos mbed

Revision:
12:422963993df5
Parent:
11:5c54826d23a7
Child:
13:291ba30c7806
--- a/main.cpp	Sat Apr 02 18:01:36 2016 +0000
+++ b/main.cpp	Sat Apr 02 21:40:37 2016 +0000
@@ -7,14 +7,9 @@
 
 #include "quadcopter.h"
 
-DigitalOut myled(LED1);
-Adafruit_9DOF dof = Adafruit_9DOF();
-Adafruit_LSM303_Accel_Unified accel = Adafruit_LSM303_Accel_Unified(30301);
-Adafruit_LSM303_Mag_Unified mag = Adafruit_LSM303_Mag_Unified(30302);
-Adafruit_L3GD20_Unified gyro = Adafruit_L3GD20_Unified(20);
-
+// initialze serial connection
 Serial pc(USBTX, USBRX);
-Serial *pcPntr=&pc;
+Serial *pcPntr=&pc; // pointer used to enable serial connection with print method in Quadcopter class
 
 // pwm outputs for the 4 motors (motor 1 points into x direction, 2 into y direction, 3 -x direction, -y direction
 PwmOut motor_1(p21);
@@ -22,48 +17,20 @@
 PwmOut motor_3(p23);
 PwmOut motor_4(p24);
 
-
-/*struct pwmOut {
-// pwmOut: this struct, PwmOut: class defined by mbed, _pwmOut: class memeber of quadcopter class
-// pwm outputs for the 4 motors (motor 1 points into x direction, 2 into y direction, 3 -x direction, -y direction
-PwmOut _motr;
-PwmOut b
-PwmOut c;
-PwmOut d;
-};
-*/
-
 int main()
 {
     Quadcopter myQuadcopter; // initialze Quadcopter object
     myQuadcopter.setSerial(pcPntr); // give Quadcopter object pc Pointer in order to print
     myQuadcopter.initAllSensors(); // initialize sensors
 
-// get desired values from joystick
+// get desired values from joystick (to be implemented)
 // myQuadcopter.setDes(...)
 
-
-//    control result;
-    //offset offset_gyro;
-
-    //initSensors(accel, mag, gyro,offset_gyro);
-
-    /*  sensors_event_t accel_event;
-      sensors_event_t mag_event;
-      sensors_event_t gyro_event;
-      sensors_vec_t   orientation;
-    */
     motor_1.period(0.002);          // motor requires a 2ms period
     motor_2.period(0.002);          // motor requires a 2ms period
     motor_3.period(0.002);          // motor requires a 2ms period
     motor_4.period(0.002);          // motor requires a 2ms period
 
-// pwm duty cycles for the 4 motors
-    motor_1 = 0;
-    motor_2 = 0;
-    motor_3 = 0;
-    motor_4 = 0;
-
     // startup procedure
     pc.printf("Type 's' to start up Motors, or anything else to abort.\n\r");
     char a= pc.getc();
@@ -71,6 +38,8 @@
         pc.printf("Aborting");
         return 0;
     };
+    
+    // Duty cycle at beginning must be  50%
     pc.printf("Starting up ESCs\n\r");
     motor_1 = 0.5;
     motor_2 = 0.5;
@@ -90,55 +59,16 @@
         myQuadcopter.readSensorValues();
 
         myQuadcopter.controller();
-        /*
-        accel.getEvent(&accel_event);
-        if (dof.accelGetOrientation(&accel_event, &orientation)) {
-            //s_com->print(("Roll: "));
-            //s_com->print(orientation.roll);
-            //s_com->print(("; "));
-            //s_com->print(("Pitch: "));
-            //s_com->print(orientation.pitch);
-            //s_com->print((";\t"));
-        }
-        */
-
-        /* Calculate the heading using the magnetometer */
-        /*mag.getEvent(&mag_event);
-        if (dof.magGetOrientation(SENSOR_AXIS_Z, &mag_event, &orientation)) {
-            //s_com->print(("Heading: "));
-            //s_com->print(orientation.heading);
-            //  s_com->print((";\r\n"));
-        }
-        /* Get angular rate data from gyroscope */
-
-        /*gyro.getEvent(&gyro_event);
-        gyro_event.gyro.x -= offset_gyro.x;
-        gyro_event.gyro.y -= offset_gyro.y;
-        gyro_event.gyro.z -= offset_gyro.z;
-        */
+       
+    
         wait(0.01);
 
-        // get sensor values
-
-        // call controller
-        //   controller(gyro_event, orientation, &result);
-
-        // compute PWM singals
-        // assumption for low angles the computed moments are between -10...10
-        // since I dont want to risk, i set PWM to 60% duty cycle if deflection =10.
-        // USB connection of quadcopter points into x direction.
-
-
         // Set duty cycle
-        // continue looking what pwm is.
         motors motorsPwm=myQuadcopter.getPwm();
 
         motor_2=motorsPwm.m2;
         motor_4=motorsPwm.m4;
 
-
-        // plot
-
         //pc.printf("F: %f M_x: %f M_y: %f M_z: %f\n\r",  F, M_x, M_y, M_z);
         //pc.printf("M_x: %f\tM_y: %f\tM_z: %f\tF: %f\n\r", result.M_x, result.M_y, result.M_z, result.F);
     }