Naze32 in Airplane mode, How do i setup FLAPS?

Post Reply
timecop
Posts: 1880
Joined: Fri Sep 02, 2011 4:48 pm

Re: Naze32 in Airplane mode, How do i setup FLAPS?

Post by timecop »

I don't know if mag works upside down.
Airplane mixer can do 2 motors, all the stuff you're asking for is "doable" but none of it is "configurable".
So you'll have to understand and edit code and rebuild.

Michael van der hoek
Posts: 39
Joined: Fri Nov 29, 2013 1:33 pm

Re: Naze32 in Airplane mode, How do i setup FLAPS?

Post by Michael van der hoek »

Thanks for answering,

I guess i have to pass on editing the code. I dont even know where to start, what is what and what affects what.
Would be nice to use the naze as an flight stab. with rth capabilities.

EDIT: is there any way to learn how the code works? or is it just trail and error?

bmallory
Posts: 6
Joined: Tue Oct 08, 2013 6:19 pm

Re: Naze32 in Airplane mode, How do i setup FLAPS?

Post by bmallory »

Well I just cloned the git repo. I don't have a compiling environment and I don't think I'm good enough to contribute to this project but from what I'm seeing, you should have some kind of althold using pitch if you have a baro enabled. there's a line of code specific to a fixed wing.

there's also a lot of "rcCommand[THROTTLE]" all over the place so maybe it's a good thing to plug the motor channel directly to the receiver when testing this. My board is an accro board so I won't be able to test this as I don't have a baro.

Code: Select all

#ifdef BARO
        if (sensors(SENSOR_BARO)) {
            if (f.BARO_MODE) {
                static uint8_t isAltHoldChanged = 0;
                static int16_t AltHoldCorr = 0;
                if (!f.FIXED_WING) {
                    // multirotor alt hold
                    if (cfg.alt_hold_fast_change) {
                        // rapid alt changes
                        if (abs(rcCommand[THROTTLE] - initialThrottleHold) > cfg.alt_hold_throttle_neutral) {
                            errorAltitudeI = 0;
                            isAltHoldChanged = 1;
                            rcCommand[THROTTLE] += (rcCommand[THROTTLE] > initialThrottleHold) ? -cfg.alt_hold_throttle_neutral : cfg.alt_hold_throttle_neutral;
                        } else {
                            if (isAltHoldChanged) {
                                AltHold = EstAlt;
                                isAltHoldChanged = 0;
                            }
                            rcCommand[THROTTLE] = initialThrottleHold + BaroPID;
                        }
                    } else {
                        // slow alt changes for apfags
                        if (abs(rcCommand[THROTTLE] - initialThrottleHold) > cfg.alt_hold_throttle_neutral) {
                            // Slowly increase/decrease AltHold proportional to stick movement ( +100 throttle gives ~ +50 cm in 1 second with cycle time about 3-4ms)
                            AltHoldCorr += rcCommand[THROTTLE] - initialThrottleHold;
                            AltHold += AltHoldCorr / 2000;
                            AltHoldCorr %= 2000;
                            isAltHoldChanged = 1;
                        } else if (isAltHoldChanged) {
                            AltHold = EstAlt;
                            AltHoldCorr = 0;
                            isAltHoldChanged = 0;
                        }
                        rcCommand[THROTTLE] = initialThrottleHold + BaroPID;
                        rcCommand[THROTTLE] = constrain(rcCommand[THROTTLE], mcfg.minthrottle + 150, mcfg.maxthrottle);
                    }
                } else {
                    // handle fixedwing-related althold. UNTESTED! and probably wrong
                    // most likely need to check changes on pitch channel and 'reset' althold similar to
                    // how throttle does it on multirotor
                    rcCommand[PITCH] += BaroPID * mcfg.fixedwing_althold_dir;
                }
            }
        }
#endif

        if (cfg.throttle_angle_correction && (f.ANGLE_MODE || f.HORIZON_MODE)) {
            rcCommand[THROTTLE] += throttleAngleCorrection;
        }

        if (sensors(SENSOR_GPS)) {
            if ((f.GPS_HOME_MODE || f.GPS_HOLD_MODE) && f.GPS_FIX_HOME) {
                float sin_yaw_y = sinf(heading * 0.0174532925f);
                float cos_yaw_x = cosf(heading * 0.0174532925f);
                if (cfg.nav_slew_rate) {
                    nav_rated[LON] += constrain(wrap_18000(nav[LON] - nav_rated[LON]), -cfg.nav_slew_rate, cfg.nav_slew_rate); // TODO check this on uint8
                    nav_rated[LAT] += constrain(wrap_18000(nav[LAT] - nav_rated[LAT]), -cfg.nav_slew_rate, cfg.nav_slew_rate);
                    GPS_angle[ROLL] = (nav_rated[LON] * cos_yaw_x - nav_rated[LAT] * sin_yaw_y) / 10;
                    GPS_angle[PITCH] = (nav_rated[LON] * sin_yaw_y + nav_rated[LAT] * cos_yaw_x) / 10;
                } else {
                    GPS_angle[ROLL] = (nav[LON] * cos_yaw_x - nav[LAT] * sin_yaw_y) / 10;
                    GPS_angle[PITCH] = (nav[LON] * sin_yaw_y + nav[LAT] * cos_yaw_x) / 10;
                }
            }
        }

        // PID - note this is function pointer set by setPIDController()
        pid_controller();

        mixTable();
        writeServos();
        writeMotors();
    }
}

Michael van der hoek
Posts: 39
Joined: Fri Nov 29, 2013 1:33 pm

Re: Naze32 in Airplane mode, How do i setup FLAPS?

Post by Michael van der hoek »

Hey Bmallory,

thanks for the code! But, the althold thing was already changed by TC a while ago. Even so, many many thanks.
I dont know how to change the Original code, or, like i said in previouse post, what triggers what.
So i dont know what to do with your textline..

I like to see an naze with althold, stab flight and rth. Would love to make it myself but i just dont know how :)

Post Reply