/* Example of RC_Channel library. Code by James Goppert/ Jason Short. 2010 DIYDrones.com */ #include #include #include // ArduPilot Mega RC Library #include #include FastSerialPort0(Serial); // make sure this procees variable declarations // test settings uint8_t nChannels = 8; bool loadEEProm = false; bool saveEEProm = false; // channel configuration Vector< AP_EEPromVar * > scale; Vector< AP_EEPromVar * > pwmMin; Vector< AP_EEPromVar * > pwmNeutral; Vector< AP_EEPromVar * > pwmMax; Vector< AP_EEPromVar * > pwmDeadZone; Vector< AP_Var * > filter; Vector< AP_Var * > reverse; Vector< AP_RcChannel * > rc; void setup() { Serial.begin(115200); Serial.println("ArduPilot RC Channel test"); APM_RC.Init(); // APM Radio initialization // add channels for (int i=0;i(1.0,strcat("SCALE",num))); pwmMin.push_back(new AP_EEPromVar(1200,strcat("PWM_MIN",num))); pwmNeutral.push_back(new AP_EEPromVar(1500,strcat("PWM_NEUTRAL",num))); pwmMax.push_back(new AP_EEPromVar(1800,strcat("PWM_MAX",num))); pwmDeadZone.push_back(new AP_EEPromVar(10,strcat("PWM_DEADZONE",num))); filter.push_back(new AP_EEPromVar(false,strcat("FILTER",num))); reverse.push_back(new AP_EEPromVar(false,strcat("REVERSE",num))); // save if (saveEEProm) { scale[i]->save(); pwmMin[i]->save(); pwmNeutral[i]->save(); pwmMax[i]->save(); pwmDeadZone[i]->save(); filter[i]->save(); reverse[i]->save(); } // load if (loadEEProm) { scale[i]->load(); pwmMin[i]->load(); pwmNeutral[i]->load(); pwmMax[i]->load(); pwmDeadZone[i]->load(); filter[i]->load(); reverse[i]->load(); } // find neutral position AP_RcChannel * ch = new AP_RcChannel(APM_RC,i,scale[i]->get(), pwmMin[i]->get(),pwmNeutral[i]->get(),pwmMax[i]->get(), pwmDeadZone[i]->get(),filter[i]->get(),reverse[i]->get()); ch->readRadio(); pwmNeutral[i]->set(ch->getPwm()); // add rc channel rc.push_back(ch); } } void loop() { // read radio for (int i=0;ireadRadio(); // read test positions Serial.printf("\npwm :\t"); for (int i=0;igetPwm()); Serial.println(); Serial.printf("position :\t"); for (int i=0;igetPosition()); Serial.println(); delay(100); }