Subversion Repositories FlightCtrl

Compare Revisions

Ignore whitespace Rev 2087 → Rev 2088

/branches/dongfang_FC_rewrite/analog.c
644,5 → 644,13
}
 
int16_t analog_getDHeight(void) {
/*
int16_t result = 0;
for (int i=0; i<staticParams.airpressureDWindowLength; i++) {
result -= dAirPressureWindow[i]; // minus pressure is plus height.
}
// dHeight = -dPressure, so here it is the old pressure minus the current, not opposite.
return result;
*/
return dHeight;
}
/branches/dongfang_FC_rewrite/attitude.c
495,7 → 495,7
startAnalogConversionCycle();
 
#ifdef USE_MK3MAG
if (staticParams.bitConfig & (CFG_COMPASS_ENABLED | CFG_GPS_ENABLED)) {
if (staticParams.bitConfig & CFG_COMPASS_ENABLED) {
correctHeadingToMagnetic();
}
#endif
/branches/dongfang_FC_rewrite/commands.c
93,7 → 93,7
beepNumber(getActiveParamSet());
}
#ifdef USE_MK3MAG
else if (staticParams.bitConfig & (CFG_COMPASS_ENABLED | CFG_GPS_ENABLED) && argument == 7) {
else if ((staticParams.bitConfig & CFG_COMPASS_ENABLED) && argument == 7) {
// If right stick is centered and down
compassCalState = 1;
beep(1000);
/branches/dongfang_FC_rewrite/configuration.c
1,54 → 1,3
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + 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 <util/delay.h>
#include <stddef.h>
#include <string.h>
64,8 → 13,8
mixerMatrix_t mixerMatrix;
volatile DynamicParams_t dynamicParams;
 
uint8_t CPUType = ATMEGA644;
uint8_t boardRelease = 13;
uint8_t CPUType;
uint8_t boardRelease;
uint8_t requiredMotors;
 
VersionInfo_t versionInfo;
120,10 → 69,9
}
}
 
uint8_t getCPUType(void) { // works only after reset or power on when the registers have default values
uint8_t CPUType = ATMEGA644;
void setCPUType(void) { // works only after reset or power on when the registers have default values
if((UCSR1A == 0x20) && (UCSR1C == 0x06)) CPUType = ATMEGA644P; // initial Values for 644P after reset
return CPUType;
else CPUType = ATMEGA644;
}
 
/*
136,8 → 84,7
* tedious to have to modify the code for how to turn on and off LEDs when deploying
* on different HW version....
*/
uint8_t getBoardRelease(void) {
uint8_t boardRelease = 13;
void setBoardRelease(void) {
// the board release is coded via the pull up or down the 2 status LED
 
PORTB &= ~((1 << PORTB1)|(1 << PORTB0)); // set tristate
165,7 → 112,6
DDRB |= (1<<DDB1)|(1<<DDB0);
RED_OFF;
GRN_OFF;
return boardRelease;
}
 
void configuration_setNormalFlightParameters(void) {
/branches/dongfang_FC_rewrite/configuration.h
241,7 → 241,7
#define CFG_HEADING_HOLD (1<<2)
#define CFG_COMPASS_ENABLED (1<<3)
#define CFG_UNUSED (1<<4)
#define CFG_GPS_ENABLED (1<<5)
#define CFG_NAVI_ENABLED (1<<5)
#define CFG_AXIS_COUPLING_ENABLED (1<<6)
#define CFG_GYRO_SATURATION_PREVENTION (1<<7)
 
287,8 → 287,8
void configuration_setFailsafeFlightParameters(void);
void configuration_applyVariablesToParams(void);
 
uint8_t getCPUType(void);
uint8_t getBoardRelease(void);
void setCPUType(void);
void setBoardRelease(void);
 
// Called after a change in configuration parameters, as a hook for modules to take over changes.
void configuration_paramSetDidChange(void);
/branches/dongfang_FC_rewrite/controlMixer.c
154,7 → 154,7
EC_periodicTaskAndPRTY(tempPRTY);
 
#ifdef USE_DIRECT_GPS
if (staticParams.bitConfig & (CFG_COMPASS_ENABLED))
if (staticParams.bitConfig & (CFG_NAVI_ENABLED))
navigation_periodicTaskAndPRTY(tempPRTY);
#endif
 
/branches/dongfang_FC_rewrite/directGPSNaviControl.c
19,17 → 19,22
NAVI_FLIGHT_MODE_HOME,
} FlightMode_t;
 
/*
* This is not read from internally. It only serves to let a pilot/debugger
* know the status of the navigation system (thru a data connection).
*/
typedef enum {
NAVI_STATUS_NO_COMPASS=-1,
NAVI_STATUS_INVALID_GPS=-2,
NAVI_STATUS_BAD_GPS_SIGNAL=-3,
NAVI_STATUS_RTH_POSITION_INVALID=-4,
NAVI_STATUS_RTH_FALLBACK_ON_HOLD=-5,
NAVI_STATUS_GPS_TIMEOUT=-6,
NAVI_STATUS_FREEFLIGHT=0,
NAVI_STATUS_INVALID_GPS=1,
NAVI_STATUS_BAD_GPS_SIGNAL=2,
NAVI_STATUS_MANUAL_OVERRIDE=5,
NAVI_STATUS_POSITION_HOLD=7,
NAVI_STATUS_RTH=8,
NAVI_STATUS_HOLD_POSITION_INVALID=9,
NAVI_STATUS_RTH_FALLBACK_ON_HOLD=10,
NAVI_STATUS_RTH_POSITION_INVALID=11,
NAVI_STATUS_GPS_TIMEOUT=12
NAVI_STATUS_POSITION_HOLD=1,
NAVI_STATUS_RTH=2,
NAVI_STATUS_MANUAL_OVERRIDE=3,
NAVI_STATUS_HOLD_POSITION_INVALID=4,
} NaviStatus_t;
 
#define GPS_POSINTEGRAL_LIMIT 32000
51,7 → 56,7
FlightMode_t flightMode = NAVI_FLIGHT_MODE_UNDEF;
int16_t naviSticks[2] = {0,0};
 
uint8_t naviStatus;
int8_t naviStatus;
 
// ---------------------------------------------------------------------------------
void navi_updateFlightMode(void) {
266,30 → 271,35
void navigation_periodicTaskAndPRTY(int16_t* PRTY) {
static uint8_t GPS_P_Delay = 0;
static uint16_t beep_rythm = 0;
 
static uint16_t navi_testOscPrescaler = 0;
static uint8_t navi_testOscTimer = 0;
 
if (!(staticParams.bitConfig & CFG_COMPASS_ENABLED)) {
navi_setNeutral();
naviStatus = NAVI_STATUS_NO_COMPASS;
return;
}
 
navi_updateFlightMode();
 
navi_testOscPrescaler++;
if (navi_testOscPrescaler == 488) {
navi_testOscPrescaler = 0;
navi_testOscTimer++;
if (navi_testOscTimer == staticParams.naviTestOscPeriod) {
navi_testOscTimer = 0;
if (staticParams.naviTestOscAmplitude) {
holdPosition.status = NEWDATA;
holdPosition.latitude += staticParams.naviTestOscAmplitude * 90L;
}
} else if (navi_testOscTimer == staticParams.naviTestOscPeriod/2) {
if (staticParams.naviTestOscAmplitude) {
holdPosition.status = NEWDATA;
holdPosition.latitude -= staticParams.naviTestOscAmplitude * 90L;
}
}
navi_testOscPrescaler = 0;
navi_testOscTimer++;
if (navi_testOscTimer == staticParams.naviTestOscPeriod) {
navi_testOscTimer = 0;
if (staticParams.naviTestOscAmplitude) {
holdPosition.status = NEWDATA;
holdPosition.latitude += staticParams.naviTestOscAmplitude * 90L; // there are about 90 units per meter.
}
} else if (navi_testOscTimer == staticParams.naviTestOscPeriod/2) {
if (staticParams.naviTestOscAmplitude) {
holdPosition.status = NEWDATA;
holdPosition.latitude -= staticParams.naviTestOscAmplitude * 90L;
}
}
}
 
navi_updateFlightMode();
 
// store home position if start of flight flag is set
if (MKFlags & MKFLAG_CALIBRATE) {
MKFlags &= ~(MKFLAG_CALIBRATE);
/branches/dongfang_FC_rewrite/heightControl.c
3,7 → 3,6
#include "attitude.h"
#include "configuration.h"
#include "controlMixer.h"
 
// for digital / LED debug.
#include "output.h"
 
14,6 → 13,12
 
#define LATCH_TIME 3
 
// This will translate a height value to a target height in centimeters.
// Currently: One step is 50 cm and zero is 5 meters below the takeoff altitude. With max. 255 steps the max.
// target height is then about 120m.
#define HEIGHT_GAIN 50L
#define HEIGHT_FORMULA(x) ((x) * HEIGHT_GAIN - 500L)
 
int32_t setHeight;
int32_t targetHeight;
 
64,7 → 69,7
}
} else {
// Switch is not activated; take the "max-height" as the target height.
setHeight = (uint16_t) dynamicParams.heightSetting * 25L - 500L; // should be: 100 (or make a param out of it)
setHeight = (uint16_t) (HEIGHT_FORMULA(dynamicParams.heightSetting)); // should be: 100 (or make a param out of it)
}
/*
107,7 → 112,7
if (hc_testOscTimer < staticParams.heightControlTestOscPeriod/2)
targetHeight = setHeight;
else
targetHeight = setHeight + (uint16_t)staticParams.heightControlTestOscAmplitude * 25L;
targetHeight = setHeight + (uint16_t)staticParams.heightControlTestOscAmplitude * HEIGHT_GAIN;
 
//if (staticParams.)
// height, in meters (so the division factor is: 100)
/branches/dongfang_FC_rewrite/main.c
33,8 → 33,8
cli();
 
// analyze hardware environment
CPUType = getCPUType();
boardRelease = getBoardRelease();
setCPUType();
setBoardRelease();
 
// disable watchdog
MCUSR &= ~(1 << WDRF);
50,7 → 50,7
timer0_init();
timer2_init();
usart0_init();
if (CPUType == ATMEGA644P);// usart1_Init();
//if (CPUType == ATMEGA644P);// usart1_Init();
RC_Init();
analog_init();
I2C_init();
/branches/dongfang_FC_rewrite/spi.c
296,7 → 296,7
toNaviCtrl.Param.Byte[1] = SPI_VersionInfo.Minor;
toNaviCtrl.Param.Byte[2] = SPI_VersionInfo.Patch;
toNaviCtrl.Param.Byte[3] = SPI_VersionInfo.Compatible;
toNaviCtrl.Param.Byte[4] = BoardRelease;
toNaviCtrl.Param.Byte[4] = boardRelease;
break;
default:
break;
/branches/dongfang_FC_rewrite/timer0.c
83,7 → 83,6
cli();
 
// Configure speaker port as output.
 
if (boardRelease == 10) { // Speaker at PD2
DDRD |= (1 << DDD2);
PORTD &= ~(1 << PORTD2);
180,7 → 179,7
 
#ifdef USE_MK3MAG
// update compass value if this option is enabled in the settings
if (staticParams.bitConfig & (CFG_COMPASS_ENABLED | CFG_GPS_ENABLED)) {
if (staticParams.bitConfig & CFG_COMPASS_ENABLED) {
MK3MAG_periodicTask(); // read out mk3mag pwm
}
#endif
/branches/dongfang_FC_rewrite/uart0.c
118,7 → 118,7
"naviRoll ",
"i part contrib ",
"Acc Z ",
"Height D ", //30
"GPS altitude ", //30
"GPS vert accura "
};
 
/branches/dongfang_FC_rewrite/ubx.c
72,7 → 72,7
UBX_SOL_t ubxSol = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, INVALID };
UBX_POSLLH_t ubxPosLlh = { 0, 0, 0, 0, 0, 0, 0, INVALID };
UBX_VELNED_t ubxVelNed = { 0, 0, 0, 0, 0, 0, 0, 0, 0, INVALID };
GPS_INFO_t GPSInfo = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, INVALID };
GPS_INFO_t GPSInfo = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, INVALID };
 
volatile uint8_t GPSTimeout = 0;
volatile uint16_t GPSDatasetCounter = 0;
88,10 → 88,14
GPSInfo.flags = ubxSol.flags;
GPSInfo.satfix = ubxSol.GPSfix;
GPSInfo.satnum = ubxSol.numSV;
GPSInfo.PAcc = ubxSol.pAcc;
GPSInfo.VAcc = ubxSol.sAcc;
debugOut.analog[31] = GPSInfo.VAcc;
 
GPSInfo.position3DAcc = ubxSol.pAcc;
GPSInfo.verticalAcc = ubxPosLlh.vAacc;
GPSInfo.velocityAcc = ubxSol.sAcc;
 
debugOut.analog[30] = ubxPosLlh.HMSL/1000L;
debugOut.analog[31] = GPSInfo.verticalAcc/1000L;
 
// NAV POSLLH
GPSInfo.longitude = ubxPosLlh.lon;
GPSInfo.latitude = ubxPosLlh.lat;
/branches/dongfang_FC_rewrite/ubx.h
31,12 → 31,13
int32_t longitude; // in 1e-07 deg
int32_t latitude; // in 1e-07 deg
int32_t altitude; // in mm
uint32_t PAcc; // in cm 3d position accuracy
uint32_t position3DAcc; // in cm 3d position accuracy
uint32_t verticalAcc; // in bm vertical position accuracy
int32_t velnorth; // in cm/s
int32_t veleast; // in cm/s
int32_t veltop; // in cm/s
uint32_t velground; // 2D ground speed in cm/s
uint32_t VAcc; // in cm/s 3d velocity accuracy
uint32_t velocityAcc; // in cm/s 3d velocity accuracy
Status_t status; // status of data: invalid | valid
} GPS_INFO_t;