// Create - Contruction of signal inlets and outlets void *autotune_new(t_symbol *s, int argc, t_atom *argv) { unsigned long sr; int fft_window = 0; int fft_hop = 0; t_autotune *x = (t_autotune *)pd_new(autotune_class); if (argc && argv->a_type == A_FLOAT) // got FFT window { fft_window = (int)atom_getint(argv); if (fft_window < 0) fft_window = 0; if (!autotune_power_of_two(fft_window)) fft_window = 0; argv++; argc--; } if (argc && argv->a_type == A_FLOAT) // got hop number { fft_hop = (int)atom_getint(argv); if (fft_hop < 2 || fft_hop > 32) fft_hop = 0; argv++; argc--; } if (fft_window != 0) x->cbsize = fft_window; if (fft_hop != 0) x->noverlap = fft_hop; if(sys_getsr()) sr = sys_getsr(); else sr = 44100; autotune_init(x , sr); // second argument = number of signal inlets //dsp_setup((t_object *)x, 1); //inlet_new(&x->x_obj, &x->x_obj.ob_pd,gensym("signal")); //inlet_new(&x->x_obj, &x->x_obj.ob_pd,gensym("signal"), gensym("signal")); //floatinlet_new (&x->x_obj, &x->fAmount); //inlet_new (&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("correct")); //floatinlet_new (&x->x_obj, &x->fGlide); //floatinlet_new (&x->x_obj, &x->fSmooth); //inlet_new (&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("smooth")); //floatinlet_new (&x->x_obj, &x->fMix); //inlet_new (&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("mix")); //floatinlet_new (&x->x_obj, &x->fShift); //inlet_new (&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("shift")); //floatinlet_new (&x->x_obj, &x->fTune); //inlet_new (&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("tune")); //floatinlet_new (&x->x_obj, &x->fPersist); //symbolinlet_new (&x->x_obj, &x->fAmount); outlet_new(&x->x_obj, gensym("signal")); //x->f_out = outlet_new(&x->x_obj, &s_float); x->confout = outlet_new(&x->x_obj, &s_float); x->periodout = outlet_new(&x->x_obj, &s_float); //x->confout = outlet_new(x, "float"); //x->periodout = outlet_new(x, "float"); x->clock = clock_new(x,(t_method)autotune_processclock); x->clockinterval = 10.; return (x); // Return the pointer }
// set_mode - change flight mode and perform any necessary initialisation // optional force parameter used to force the flight mode change (used only first time mode is set) // returns true if mode was successfully set // ACRO, STABILIZE, ALTHOLD, LAND, DRIFT and SPORT can always be set successfully but the return state of other flight modes should be checked and the caller should deal with failures appropriately bool Copter::set_mode(control_mode_t mode, mode_reason_t reason) { // boolean to record if flight mode could be set bool success = false; bool ignore_checks = !motors.armed(); // allow switching to any mode if disarmed. We rely on the arming check to perform // return immediately if we are already in the desired mode if (mode == control_mode) { prev_control_mode = control_mode; prev_control_mode_reason = control_mode_reason; control_mode_reason = reason; return true; } switch(mode) { case ACRO: #if FRAME_CONFIG == HELI_FRAME success = heli_acro_init(ignore_checks); #else success = acro_init(ignore_checks); #endif break; case STABILIZE: #if FRAME_CONFIG == HELI_FRAME success = heli_stabilize_init(ignore_checks); #else success = stabilize_init(ignore_checks); #endif break; case ALT_HOLD: success = althold_init(ignore_checks); break; case AUTO: success = auto_init(ignore_checks); break; case CIRCLE: success = circle_init(ignore_checks); break; case LOITER: success = loiter_init(ignore_checks); break; case GUIDED: success = guided_init(ignore_checks); break; case LAND: success = land_init(ignore_checks); break; case RTL: success = rtl_init(ignore_checks); break; case DRIFT: success = drift_init(ignore_checks); break; case SPORT: success = sport_init(ignore_checks); break; case ALT_POS: success = altpos_init(ignore_checks); break; case FLIP: success = flip_init(ignore_checks); break; #if AUTOTUNE_ENABLED == ENABLED case AUTOTUNE: success = autotune_init(ignore_checks); break; #endif #if POSHOLD_ENABLED == ENABLED case POSHOLD: success = poshold_init(ignore_checks); break; #endif case BRAKE: success = brake_init(ignore_checks); break; case THROW: success = throw_init(ignore_checks); break; case AVOID_ADSB: success = avoid_adsb_init(ignore_checks); break; case GUIDED_NOGPS: success = guided_nogps_init(ignore_checks); break; default: success = false; break; } // update flight mode if (success) { // perform any cleanup required by previous flight mode exit_mode(control_mode, mode); prev_control_mode = control_mode; prev_control_mode_reason = control_mode_reason; control_mode = mode; control_mode_reason = reason; DataFlash.Log_Write_Mode(control_mode, control_mode_reason); adsb.set_is_auto_mode((mode == AUTO) || (mode == RTL) || (mode == GUIDED)); #if AC_FENCE == ENABLED // pilot requested flight mode change during a fence breach indicates pilot is attempting to manually recover // this flight mode change could be automatic (i.e. fence, battery, GPS or GCS failsafe) // but it should be harmless to disable the fence temporarily in these situations as well fence.manual_recovery_start(); #endif }else{ // Log error that we failed to enter desired flight mode Log_Write_Error(ERROR_SUBSYSTEM_FLIGHT_MODE,mode); } // update notify object if (success) { notify_flight_mode(control_mode); } // return success or failure return success; }
// set_mode - change flight mode and perform any necessary initialisation // optional force parameter used to force the flight mode change (used only first time mode is set) // returns true if mode was succesfully set // ACRO, STABILIZE, ALTHOLD, LAND, DRIFT and SPORT can always be set successfully but the return state of other flight modes should be checked and the caller should deal with failures appropriately bool Sub::set_mode(control_mode_t mode, mode_reason_t reason) { // boolean to record if flight mode could be set bool success = false; bool ignore_checks = false; // Always check for now // return immediately if we are already in the desired mode if (mode == control_mode) { prev_control_mode = control_mode; prev_control_mode_reason = control_mode_reason; control_mode_reason = reason; return true; } switch (mode) { case ACRO: success = acro_init(ignore_checks); break; case STABILIZE: success = stabilize_init(ignore_checks); break; case ALT_HOLD: success = althold_init(ignore_checks); break; case AUTO: success = auto_init(ignore_checks); break; case CIRCLE: success = circle_init(ignore_checks); break; case VELHOLD: success = velhold_init(ignore_checks); break; case GUIDED: success = guided_init(ignore_checks); break; case SURFACE: success = surface_init(ignore_checks); break; #if AUTOTUNE_ENABLED == ENABLED case AUTOTUNE: success = autotune_init(ignore_checks); break; #endif #if POSHOLD_ENABLED == ENABLED case POSHOLD: success = poshold_init(ignore_checks); break; #endif case MANUAL: success = manual_init(ignore_checks); break; default: success = false; break; } // update flight mode if (success) { // perform any cleanup required by previous flight mode exit_mode(control_mode, mode); prev_control_mode = control_mode; prev_control_mode_reason = control_mode_reason; control_mode = mode; control_mode_reason = reason; DataFlash.Log_Write_Mode(control_mode, control_mode_reason); #if AC_FENCE == ENABLED // pilot requested flight mode change during a fence breach indicates pilot is attempting to manually recover // this flight mode change could be automatic (i.e. fence, battery, GPS or GCS failsafe) // but it should be harmless to disable the fence temporarily in these situations as well fence.manual_recovery_start(); #endif } else { // Log error that we failed to enter desired flight mode Log_Write_Error(ERROR_SUBSYSTEM_FLIGHT_MODE,mode); } // update notify object if (success) { notify_flight_mode(control_mode); } // return success or failure return success; }