Subversion Repositories FlightCtrl

Rev

Rev 2055 | Rev 2097 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Copyright (c) 04.2007 Holger Buss
// + Nur für den privaten Gebrauch
// + www.MikroKopter.com
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation),
// + dass eine Nutzung (auch auszugsweise) nur f�r den privaten und nicht-kommerziellen Gebrauch zulässig ist.
// + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt
// + bzgl. der Nutzungsbedingungen aufzunehmen.
// + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen,
// + Verkauf von Luftbildaufnahmen, usw.
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht,
// + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts
// + auf anderen Webseiten oder Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de"
// + eindeutig als Ursprung verlinkt und genannt werden
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion
// + Benutzung auf eigene Gefahr
// + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Die Portierung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur
// + mit unserer Zustimmung zulässig
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Redistributions of source code (with or without modifications) must retain the above copyright notice,
// + this list of conditions and the following disclaimer.
// +   * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived
// +     from this software without specific prior written permission.
// +   * The use of this project (hardware, software, binary files, sources and documentation) is only permittet
// +     for non-commercial use (directly or indirectly)
// +     Commercial use (for example: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted
// +     with our written permission
// +   * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be
// +     clearly linked as origin
// +   * porting to systems other than hardware from www.mikrokopter.de is not allowed
// +  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// +  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// +  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// +  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// +  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// +  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// +  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// +  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// +  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// +  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// +  POSSIBILITY OF SUCH DAMAGE.
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#include <stdlib.h>
#include "commands.h"
#include "controlMixer.h"
#include "flight.h"
#include "eeprom.h"
#include "attitude.h"
#include "output.h"
#include "rc.h"

#ifdef USE_MK3MAG
// TODO: Kick that all outa here!
uint8_t compassCalState = 0;
#endif

void commands_handleCommands(void) {
        /*
         * Get the current command (start/stop motors, calibrate), if any.
         */

        uint8_t command = controlMixer_getCommand();
        uint8_t repeated = controlMixer_isCommandRepeated();
        uint8_t argument = controlMixer_getArgument();

        if (!(MKFlags & MKFLAG_MOTOR_RUN)) {
                if (command == COMMAND_GYROCAL && !repeated) {
                        // Run gyro calibration but do not repeat it.
                        // TODO: out of here. Anyway, MKFLAG_MOTOR_RUN is cleared. Not enough?
                        // isFlying = 0;
                        // check roll/pitch stick position
                        // if pitch stick is top or roll stick is left or right --> change parameter setting
                        // according to roll/pitch stick position

                        if (argument < 6) {
                                // Gyro calinbration, with or without selecting a new parameter-set.
                                if (argument > 0 && argument < 6) {
                                        // A valid parameter-set (1..5) was chosen - use it.
                                        setActiveParamSet(argument);
                                }
                                paramSet_readFromEEProm(getActiveParamSet());
                                analog_calibrateGyros();
                                attitude_setNeutral();
                                controlMixer_setNeutral();
                                beepNumber(getActiveParamSet());
                        }
#ifdef USE_MK3MAG
                        else if ((staticParams.bitConfig & CFG_COMPASS_ENABLED) && argument == 7) {
                                // If right stick is centered and down
                                compassCalState = 1;
                                beep(1000);
                        }
#endif
                }

                // save the ACC neutral setting to eeprom
                else {
                        if (command == COMMAND_ACCCAL && !repeated) {
                                // Run gyro and acc. meter calibration but do not repeat it.
                                analog_calibrateAcc();
                                attitude_setNeutral();
                                controlMixer_setNeutral();
                                beepNumber(getActiveParamSet());
                        }
                }
        } // end !MOTOR_RUN condition.
        if (command == COMMAND_START) {
                isFlying = 1; // TODO: Really????
                // if (!controlMixer_isCommandRepeated()) {
                // attitude_startDynamicCalibration(); // Try sense the effect of the motors on sensors.
                MKFlags |= (MKFLAG_MOTOR_RUN | MKFLAG_START); // set flag RUN and START. TODO: Is that START flag used at all???
                // } else { // Pilot is holding stick, ever after motor start. Continue to sense the effect of the motors on sensors.
                // attitude_continueDynamicCalibration();
                // setPointYaw = 0;
                // IPartPitch = 0;
                // IPartRoll = 0;
                // }
        } else if (command == COMMAND_STOP) {
                isFlying = 0;
                MKFlags &= ~(MKFLAG_MOTOR_RUN);
        }
}

/*
 *     if (controlMixer_testCompassCalState()) {
      compassCalState++;
      if (compassCalState < 5)
        beepNumber(compassCalState);
      else
        beep(1000);
    }
 *
 */


#ifdef USE_MK3MAG
uint8_t commands_isCalibratingCompass(void) {
  return RC_testCompassCalState();
}
#endif