![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
code to fly a quadrocopter
PWM/pwmdeg.cpp
- Committer:
- DD1993
- Date:
- 2020-05-05
- Revision:
- 0:b0f9c5ac0305
File content as of revision 0:b0f9c5ac0305:
#include "pwmdeg.h" RawSerial pc2(USBTX, USBRX); //////////////////////PITCH FORWARD////////////////////////////////////////////////////////////// float pwmdeg::pitch_forward(int pitch_in) { int wert = pitch_in; //pc2.printf("ele_kalsse: %d \n", wert); float dPWM = 0; int pwm_mittel = 1479; float pitch_forwarddeg = 0; float grad = 0; dPWM = wert - pwm_mittel; grad = dPWM * 50/400; //pc2.printf("ele: %f | wert: %d\n", dPWM, wert); if(wert >= 1460 && wert <= 1500) { pitch_forwarddeg = 0; //pc2.printf("ele: %f | wert: %d\n", dPWM, wert); } else { pitch_forwarddeg = grad; } //pc2.printf("ele: %f | wert: %d\n", dPWM, wert); //pc2.printf("Grad von RC: %f| Wert ele: %d \n", pitch_forwarddeg, wert); return pitch_forwarddeg; } //////////////////////ROLL////////////////////////////////////////////////////////////// float pwmdeg::roll(int ail_in) { int wert = ail_in; float rolldeg = 0; int pwm_mittel = 1500; float grad = 0; float dPWM = 0; dPWM = wert - pwm_mittel; grad = dPWM * 50/400; if(wert >= 1480 && wert <= 1520) { rolldeg = 0; } else { rolldeg = grad; //pc2.printf("grad: %f", grad); } //pc2.printf("Grad von RC: %f| Wert ele: %d \n", rolldeg, wert); return rolldeg; } //////////////////////YAW////////////////////////////////////////////////////////////// float pwmdeg::yaw(int rud_in) { int wert = rud_in; int pwm_mittel = 1492; int grad = 0; int dPWM = 0; int yawaccel = 0; //pc2.printf("grad: %f\n", wert); dPWM = wert - pwm_mittel; grad = dPWM * 170/380; if(wert >= 1470 && wert <= 1500) { yawaccel = 0; } else { yawaccel = grad; } //pc2.printf("Grad/s von RC: %d| Wert yaw: %d \n", yawaccel, wert); return yawaccel; }