ESE350 project, Spring 2016, University of Pennsylvania

Dependencies:   Adafruit9-DOf Receiver mbed-rtos mbed

Revision:
38:14bf11115f9f
Parent:
37:a983eb9fd9c5
Child:
39:fff0a72633ee
--- a/quadcopter.cpp	Sun May 01 18:45:02 2016 +0000
+++ b/quadcopter.cpp	Sun May 01 21:59:10 2016 +0000
@@ -28,8 +28,8 @@
 //    kp_theta_ = 0;
 
     // derivative attitude control gains
-    kd_phi_   = 0.0 * (maxPwm - zeroVelPwm) * 2 / M_PI; //0.25 good
-    kd_theta_ = 0.0 * (maxPwm - zeroVelPwm) * 2 / M_PI;
+    kd_phi_   = 0.05 * (maxPwm - zeroVelPwm) * 2 / M_PI; //0.25 good
+    kd_theta_ = 0.05 * (maxPwm - zeroVelPwm) * 2 / M_PI;
     kd_psi_   = 0.1;
     // kd_phi_   = 0;
     //kd_theta_ = 0;
@@ -282,8 +282,9 @@
     //pc_->printf("%s\r\n", rxBuffer);
     if (receive > 10) {
         int written = sscanf(rxBuffer, "%lld,%f,%f,%f,%f", &id, &thrust, &yaw, &pitch, &roll);
-        pc_->printf("&d", written);
+        // pc_->printf("%d\r\n", written);
         if (written != 5) {
+            // pc_->printf("%s\r\n", rxBuffer);
             return;
         }
     } else {
@@ -304,12 +305,14 @@
 
 // TODO eliminate the zeros again after testing
     // convert to radians, range is = +-40° or +-0.698132 radians
-    desiredState_.phi = 1 * (-((roll - 0.5) * 80) * M_PI / 180); // minus, because joystick to right should result in positive moment
-    desiredState_.theta = 1 * ((pitch - 0.5) * 80) * M_PI / 180;
-    desiredState_.r = 1 * (yaw - 0.5); // number between 0 and 1 //((yaw - 0.5) * 80) * M_PI / 180;
-    F_des_ = thrust - 0.5; // number between 0 and 1 -> number between -0.5 and 0.5
+    desiredState_.phi = 1 * (-(roll * 80) * M_PI / 180); // minus, because joystick to right should result in positive moment
+    desiredState_.theta = 1 * (pitch * 80) * M_PI / 180;
+    desiredState_.r = 1 * yaw; // number between 0 and 1 //((yaw - 0.5) * 80) * M_PI / 180;
+    F_des_ = thrust; // number between 0 and 1 -> number between -0.5 and 0.5
     // print id with thrust, yaw, pitch, and roll
-    //pc_->printf("%lld: thrust: %f yaw: %f pitch: %f roll: %f outliers: %d\r\n", id, F_des_, desiredState_.psi, desiredState_.theta, desiredState_.phi, thrust_outliers);
-
+    
+    if (abs(F_des_) > 0.01 || abs(desiredState_.psi) > 0.01 || abs(desiredState_.theta) > 0.02 || abs(desiredState_.phi) > 0.01) {
+        pc_->printf("%lld: thrust: %f yaw: %f pitch: %f roll: %f\r\n", id, F_des_, desiredState_.psi, desiredState_.theta, desiredState_.phi); //, thrust_outliers);
+    }
 }