Baro Code Änderungen (Seite 1 Übersicht)
Aktuelles:
-Hier gibt es die "Final4" Version und die aktuelle Testversion:
http://fpv-community.de/showthread.php?14199-Baro-Code-%C4nderungen&p=224135&viewfull=1#post224135
- Hier ist die "Final4" Version mit Autolandung:
http://fpv-community.de/showthread.php?14199-Baro-Code-%C4nderungen&p=266928&viewfull=1#post266928
-Hier gibt es die "Final4" Version, verheiratet mit der MultiWii_2_1_new_serial1 von Ronco (für Bluetooth) von merlin4: http://fpv-community.de/showthread.php?14199-Baro-Code-%C4nderungen&p=224710&viewfull=1#post224710
-Hier ist die aktuelle 32Bit - Naze32 Variante:
http://fpv-community.de/showthread....ative-Software&p=239813&viewfull=1#post239813
=======================================================================
Älter Version
-Hier gibt es die "Final3" Version:http://fpv-community.de/showthread....o-vern%FCnftig&p=200133&viewfull=1#post200133
-Hier gibt es die "Final3" Version, verheiratet mit der MultiWii_2_1_new_serial1 von Ronco (für Bluetooth) von merlin4: http://fpv-community.de/showthread....o-vern%FCnftig&p=203335&viewfull=1#post203335
=======================================================================
- Wer Ärger mit der Programmgrösse auf ATmega32u4 (Pro Micro, z.B "Microwii") basierten FC hat, sollte sich den Tip von JinGej anschauen: http://fpv-community.de/showthread.php?14199-Baro-Code-%C4nderungen&p=210431&viewfull=1#post210431
Aber Vorsicht, das bringt auch Risiken mit sich: http://fpv-community.de/showthread.php?14199-Baro-Code-%C4nderungen&p=210486&viewfull=1#post210486
Codeänderungen MultiWii_2_1_NewBaroPIDVario3Final:
========================================
Änderungen im Hauptprogramm (Changes in mainprogram):
=====================================================
Zusätzliche Variablen / Additional variables:
---------------------------------------------
Gelöschte Variable / Deleted variable:
--------------------------------------
Eingefügt / Added line:
-----------------------
In setup() nach "initSensors();" einfügen:
Insert this in setup() after "initSensors();"
Bei Zeile 795 das löschen / Delete this at line 795:
----------------------------------------------------
Und durch das ersetzen / Replace with this:
Bei Zeile 849 das löschen / Delete this at line 849:
----------------------------------------------------
Und durch das ersetzen / Replace with this:
Bei Zeile 871 das löschen / Delete this at line 871:
----------------------------------------------------
Und durch das ersetzen / Replace with this:
Das einfügen vor / Insert this before "if (rcOptions[BOXPASSTHRU]) {f.PASSTHRU_MODE = 1;}
-----------------------------------------------------------------------------------------
Bei Zeile 892 das löschen / Delete this at line 892:
----------------------------------------------------
Und durch das ersetzen / Replace with this:
Bei Zeile 941 das löschen / Delete this at line 941:
----------------------------------------------------
Und durch das ersetzen / Replace with this:
Änderungen unter "IMU" (Changes in "IMU"):
==========================================
In Zeile 172 das hier/ Change this in line 172:
-----------------------------------------------
Ändern in / to this:
Bei Zeile 254 das löschen / Delete this at line 254:
----------------------------------------------------
Und durch das ersetzen / Replace with this:
Das waren die Hauptneuerungen. Die Änderungen bei "Sensors" sind die gleichen wie in diesem Link beschrieben / The changes in "Sensors" have been already shown here: http://fpv-community.de/showthread.php?14199-Baro-Code-%C4nderungen&p=189823&viewfull=1#post189823 Both Baro readoutroutines (BMP&MS) are tuned to put out new values every 30ms! (Beide Baro Ausleseprogramme geben jetzt alle 30ms einen neuen Wert aus!)
Hier die Änderung in def.h / Changes in def.h:
==============================================
Hinzugefügt /Added:
-------------------
Hier die Änderung in config.h / Changes in config.h:
====================================================
Entsprechend geändert/hinzugefügt // Accordingly changed/added:
In EEPROM.ino wurden nur die AltPID Ausgangswerte geändert. / In EEPROM.ino only the deflaultvalues for ALTPID were changed.
Das wars ! / That was it!
So long
Rob
Aktuelles:
-Hier gibt es die "Final4" Version und die aktuelle Testversion:
http://fpv-community.de/showthread.php?14199-Baro-Code-%C4nderungen&p=224135&viewfull=1#post224135
- Hier ist die "Final4" Version mit Autolandung:
http://fpv-community.de/showthread.php?14199-Baro-Code-%C4nderungen&p=266928&viewfull=1#post266928
-Hier gibt es die "Final4" Version, verheiratet mit der MultiWii_2_1_new_serial1 von Ronco (für Bluetooth) von merlin4: http://fpv-community.de/showthread.php?14199-Baro-Code-%C4nderungen&p=224710&viewfull=1#post224710
-Hier ist die aktuelle 32Bit - Naze32 Variante:
http://fpv-community.de/showthread....ative-Software&p=239813&viewfull=1#post239813
=======================================================================
Älter Version
-Hier gibt es die "Final3" Version:http://fpv-community.de/showthread....o-vern%FCnftig&p=200133&viewfull=1#post200133
-Hier gibt es die "Final3" Version, verheiratet mit der MultiWii_2_1_new_serial1 von Ronco (für Bluetooth) von merlin4: http://fpv-community.de/showthread....o-vern%FCnftig&p=203335&viewfull=1#post203335
=======================================================================
- Wer Ärger mit der Programmgrösse auf ATmega32u4 (Pro Micro, z.B "Microwii") basierten FC hat, sollte sich den Tip von JinGej anschauen: http://fpv-community.de/showthread.php?14199-Baro-Code-%C4nderungen&p=210431&viewfull=1#post210431
Aber Vorsicht, das bringt auch Risiken mit sich: http://fpv-community.de/showthread.php?14199-Baro-Code-%C4nderungen&p=210486&viewfull=1#post210486
Codeänderungen MultiWii_2_1_NewBaroPIDVario3Final:
========================================
Änderungen im Hauptprogramm (Changes in mainprogram):
=====================================================
Zusätzliche Variablen / Additional variables:
---------------------------------------------
Code:
static uint8_t newbaroalt=0; //Crashpilotmod
static int32_t GroundAlt=0;
static int16_t BaroClimbRate = 0; // in cm/s
static uint32_t AltHoldBlindTimer=0,PosHoldBlindTimer=0;
static int16_t LastThrottle;
static uint32_t ThrTime;
static uint8_t HightChange=0,PSholdChange=0;
static int16_t ThrottleRate; // Ticks/sec
static float accVelScale;
Gelöschte Variable / Deleted variable:
--------------------------------------
Code:
static int16_t errorAltitudeI = 0;
-----------------------
In setup() nach "initSensors();" einfügen:
Insert this in setup() after "initSensors();"
Code:
#if BARO
getGroundAlt();
#endif
Bei Zeile 795 das löschen / Delete this at line 795:
----------------------------------------------------
Code:
#if BARO
if (rcOptions[BOXBARO]) {
if (!f.BARO_MODE) {
f.BARO_MODE = 1;
AltHold = EstAlt;
initialThrottleHold = rcCommand[THROTTLE];
errorAltitudeI = 0;
BaroPID=0;
}
} else {
f.BARO_MODE = 0;
}
#endif
Code:
#if BARO
if (rcOptions[BOXBARO]) {
if (!f.BARO_MODE) {
f.BARO_MODE = 1;
AltHold = EstAlt;
HightChange=0;
BaroPID=0;
AltHoldBlindTimer=0;
initialThrottleHold = rcCommand[THROTTLE];
}
} else {
f.BARO_MODE = 0;
}
#endif
----------------------------------------------------
Code:
if (rcOptions[BOXGPSHOLD]) {
if (!f.GPS_HOLD_MODE & !f.GPS_HOME_MODE) {
f.GPS_HOLD_MODE = 1;
GPSNavReset = 0;
GPS_I2C_command(I2C_GPS_COMMAND_POSHOLD,0);
}
} else {
f.GPS_HOLD_MODE = 0;
}
Code:
if (rcOptions[BOXGPSHOLD] && PSholdChange == 0)
{
if (!f.GPS_HOLD_MODE & !f.GPS_HOME_MODE) {
f.GPS_HOLD_MODE = 1;
GPSNavReset = 0;
GPS_I2C_command(I2C_GPS_COMMAND_POSHOLD,0);
}
} else {
f.GPS_HOLD_MODE = 0;
}
Bei Zeile 871 das löschen / Delete this at line 871:
----------------------------------------------------
Code:
if (rcOptions[BOXGPSHOLD]) {
if (!f.GPS_HOLD_MODE) {
f.GPS_HOLD_MODE = 1;
GPS_hold[LAT] = GPS_coord[LAT];
GPS_hold[LON] = GPS_coord[LON];
GPS_set_next_wp(&GPS_hold[LAT],&GPS_hold[LON]);
nav_mode = NAV_MODE_POSHOLD;
}
} else {
f.GPS_HOLD_MODE = 0;
}
Code:
if (rcOptions[BOXGPSHOLD] && PSholdChange == 0)
{
if (!f.GPS_HOLD_MODE) {
f.GPS_HOLD_MODE = 1;
GPS_hold[LAT] = GPS_coord[LAT];
GPS_hold[LON] = GPS_coord[LON];
GPS_set_next_wp(&GPS_hold[LAT],&GPS_hold[LON]);
nav_mode = NAV_MODE_POSHOLD;
}
} else {
f.GPS_HOLD_MODE = 0;
}
Das einfügen vor / Insert this before "if (rcOptions[BOXPASSTHRU]) {f.PASSTHRU_MODE = 1;}
-----------------------------------------------------------------------------------------
Code:
#if GPS
#if defined(PositionHoldOverride)
if (rcOptions[BOXGPSHOLD]){
if (abs(rcData[PITCH]-MIDRC) > BlindZonePitch || abs(rcData[ROLL]-MIDRC) > BlindZoneRoll){
PosHoldBlindTimer = 0;
PSholdChange = 1;}
else {if (PSholdChange==1 && PosHoldBlindTimer==0) PosHoldBlindTimer = currentTime+PosHoldBlindTime;} // Ph is off and Stick back to neutralzone
if (currentTime >= PosHoldBlindTimer && PosHoldBlindTimer !=0){
PosHoldBlindTimer = 0;
PSholdChange = 0;}
}
else{PosHoldBlindTimer = 0; PSholdChange = 0;}
#endif
#endif
Bei Zeile 892 das löschen / Delete this at line 892:
----------------------------------------------------
Code:
} else { // not in rc loop
static uint8_t taskOrder=0; // never call all functions in the same loop, to avoid high delay spikes
switch (taskOrder++ % 5) {
case 0:
#if MAG
Mag_getADC();
#endif
break;
case 1:
#if BARO
Baro_update();
#endif
break;
case 2:
#if BARO
getEstimatedAltitude();
#endif
break;
case 3:
#if GPS
if(GPS_Enable) GPS_NewData();
#endif
break;
case 4:
#if SONAR
Sonar_update();debug[2] = sonarAlt;
#endif
#ifdef LANDING_LIGHTS_DDR
auto_switch_landing_lights();
#endif
break;
}
}
Code:
} else { // not in rc loop
static uint8_t taskOrder=0; // never call all functions in the same loop, to avoid high delay spikes
switch (taskOrder++ % 3) {
case 0:
#if MAG
Mag_getADC();
#endif
break;
case 1:
#if GPS
if(GPS_Enable) GPS_NewData();
#endif
break;
case 2:
#if SONAR
Sonar_update();debug[2] = sonarAlt;
#endif
#ifdef LANDING_LIGHTS_DDR
auto_switch_landing_lights();
#endif
break;
}
}
Bei Zeile 941 das löschen / Delete this at line 941:
----------------------------------------------------
Code:
#if BARO
if (f.BARO_MODE) {
if (abs(rcCommand[THROTTLE]-initialThrottleHold)>ALT_HOLD_THROTTLE_NEUTRAL_ZONE) {
f.BARO_MODE = 0; // so that a new althold reference is defined
}
rcCommand[THROTTLE] = initialThrottleHold + BaroPID;
}
#endif
Code:
#if BARO
Baro_update(); // Do Baro every time!
getEstimatedAltitude();
if (currentTime >= ThrTime){ // Get ThrottleRate in Ticks/sec Upmovement=+ Polling at 10Hz
ThrTime = currentTime+100000;
ThrottleRate = (rcCommand[THROTTLE]-LastThrottle)*10;
if (abs(ThrottleRate) < 150) ThrottleRate = 0;
LastThrottle=rcCommand[THROTTLE];}
if (rcOptions[BOXBARO]){ // New Logic: When User exceeds neutral zone and stops fiddeling with throttle, then after 1 second a new Althold is defined
if (abs(rcCommand[THROTTLE] - initialThrottleHold)<ALT_HOLD_THROTTLE_NEUTRAL_ZONE && HightChange==0){
rcCommand[THROTTLE] = initialThrottleHold + BaroPID;
rcCommand[THROTTLE] = constrain(rcCommand[THROTTLE],MINTHROTTLE+1,MAXTHROTTLE-50);}
else {
HightChange=1;
if (ThrottleRate==0 && AltHoldBlindTimer==0) AltHoldBlindTimer = currentTime+AltHoldBlindTime;}
if (ThrottleRate !=0) AltHoldBlindTimer = 0;
if (currentTime >= AltHoldBlindTimer && AltHoldBlindTimer !=0) f.BARO_MODE = 0; // Set new ref hight
}
#endif
Änderungen unter "IMU" (Changes in "IMU"):
==========================================
In Zeile 172 das hier/ Change this in line 172:
-----------------------------------------------
Code:
void getEstimatedAttitude(){
uint8_t axis;
int32_t accMag = 0;
static t_fp_vector EstG;
#if MAG
...
Code:
static t_fp_vector EstG;
void getEstimatedAttitude(){
uint8_t axis;
int32_t accMag = 0;
#if MAG
Bei Zeile 254 das löschen / Delete this at line 254:
----------------------------------------------------
Code:
#define UPDATE_INTERVAL 25000 // 40hz update rate (20hz LPF on acc)
#define INIT_DELAY 4000000 // 4 sec initialization delay
#define BARO_TAB_SIZE 40
void getEstimatedAltitude(){
uint8_t index;
static uint32_t deadLine = INIT_DELAY;
static int16_t BaroHistTab[BARO_TAB_SIZE];
static int8_t BaroHistIdx;
static int32_t BaroHigh,BaroLow;
int32_t temp32;
int16_t last;
if (abs(currentTime - deadLine) < UPDATE_INTERVAL) return;
deadLine = currentTime;
//**** Alt. Set Point stabilization PID ****
//calculate speed for D calculation
last = BaroHistTab[BaroHistIdx];
BaroHistTab[BaroHistIdx] = BaroAlt/10;
BaroHigh += BaroHistTab[BaroHistIdx];
index = (BaroHistIdx + (BARO_TAB_SIZE/2))%BARO_TAB_SIZE;
BaroHigh -= BaroHistTab[index];
BaroLow += BaroHistTab[index];
BaroLow -= last;
BaroHistIdx++;
if (BaroHistIdx == BARO_TAB_SIZE) BaroHistIdx = 0;
BaroPID = 0;
//D
temp32 = conf.D8[PIDALT]*(BaroHigh - BaroLow) / 40;
BaroPID-=temp32;
EstAlt = BaroHigh*10/(BARO_TAB_SIZE/2);
temp32 = AltHold - EstAlt;
if (abs(temp32) < 10 && abs(BaroPID) < 10) BaroPID = 0; //remove small D parametr to reduce noise near zero position
//P
BaroPID += conf.P8[PIDALT]*constrain(temp32,(-2)*conf.P8[PIDALT],2*conf.P8[PIDALT])/100;
BaroPID = constrain(BaroPID,-150,+150); //sum of P and D should be in range 150
//I
errorAltitudeI += temp32*conf.I8[PIDALT]/50;
errorAltitudeI = constrain(errorAltitudeI,-30000,30000);
temp32 = errorAltitudeI / 500; //I in range +/-60
BaroPID+=temp32;
}
Code:
void getGroundAlt() // Executed in Setup takes approx 4.5 sec
{
uint8_t gacnt=0;
while(gacnt < 150){
while(newbaroalt ==0){ // Wait for new Baroval
Baro_update();
}
newbaroalt = 0; // Reset Boolean
GroundAlt=GroundAlt+BaroAlt;
gacnt++;
}
GroundAlt=GroundAlt/150;
accVelScale = 9.80665f/acc_1G/10000.0f;
}
///////////////////////////////////////////////
//Crashpilot1000 Mod getEstimatedAltitude ACC//
///////////////////////////////////////////////
#define VarioTabsize 8
#define BaroTabsize 5
void getEstimatedAltitude()
{
static uint8_t Vidx=0,Bidx=0;
static int32_t LastEstAlt=0;
static int16_t BaroP;
static int8_t VarioTab[VarioTabsize];
static int32_t BaroTab[BaroTabsize];
static float velz = 0.0f;
int8_t IdxCnt,ThrAngle;
int16_t AltI,ThrD,BaroDiff;
int32_t tmp32;
int16_t accZ = (accADC[ROLL]*EstG.V.X+accADC[PITCH]*EstG.V.Y+accADC[YAW]*EstG.V.Z)*InvSqrt(fsq(EstG.V.X)+fsq(EstG.V.Y)+fsq(EstG.V.Z)) - acc_1G; //if (abs(accZ)<acc_1G/25) accZ=0;
velz = velz+accZ*accVelScale*cycleTime;
ThrAngle = EstG.V.Z/acc_1G * 100.0f;
if (BaroPID==0) BaroP=0; // Reset BaroP if necessary, so I and D can be done before first Barovalue
if (newbaroalt!=0)
{
newbaroalt = 0; // Reset Boolean
// Get EstAlt
BaroTab[Bidx] = BaroAlt-GroundAlt; Bidx++;
if (Bidx==BaroTabsize) Bidx=0;
tmp32=0; IdxCnt = 0;
while(IdxCnt<BaroTabsize){tmp32=tmp32+BaroTab[IdxCnt]; IdxCnt++;}// EstAlt = (EstAlt+(tmp32/BaroTabsize))/2;
EstAlt = tmp32/BaroTabsize;
// Baro Climbrate
VarioTab[Vidx] = constrain(EstAlt-LastEstAlt,-126,126); Vidx++;
if (Vidx==VarioTabsize) Vidx=0;
LastEstAlt = EstAlt;
tmp32 = 0; IdxCnt = 0;
while(IdxCnt<VarioTabsize){tmp32=tmp32+VarioTab[IdxCnt]; IdxCnt++;}// BaroClimbRate = (BaroClimbRate+((tmp32*33)/VarioTabsize))/2;//BaroClimbRate in cm/sec // + is up // 30ms * 33 = 990ms
BaroClimbRate = (tmp32*33)/VarioTabsize; //BaroClimbRate in cm/sec // + is up // 30ms * 33 = 990ms
velz = velz * 0.982f + BaroClimbRate * 0.018f; //velz= Baro&Acc Climbrate
// Baro P
BaroDiff = constrain(AltHold-EstAlt,-200,200); // BaroDiff = Difference to locked hight neg if risen
BaroP = constrain(((int16_t)conf.P8[PIDALT]*BaroDiff)/200,-200,200); // Limit Baro P to +/- 200
}
if (ThrAngle < 40){BaroPID=0; return;} // Don't do BaroPID if copter too tilted// EstAlt & Baroclimbrate are always done :)
AltI = constrain((((int32_t)conf.I8[PIDALT]*velz)/50),-150,150); // Baro I
ThrD = (((int16_t)conf.D8[PIDALT]) * (100 - ThrAngle))/25; // "D"
BaroPID = (BaroPID+constrain(BaroP-AltI+ThrD,-250,250))/2;
}
float InvSqrt (float x){
union{
int32_t i;
float f;
} conv;
conv.f = x;
conv.i = 0x5f3759df - (conv.i >> 1);
return 0.5f * conv.f * (3.0f - x * conv.f * conv.f);
}
float fsq(float x){return x * x;} // no benefit from integer! Code gets longer
Hier die Änderung in def.h / Changes in def.h:
==============================================
Hinzugefügt /Added:
-------------------
Code:
/**************************************************************************************/
/*************** CRASHPILOT1000 MOD ********************/
/**************************************************************************************/
#if !defined(AltHoldBlindTime)
#define AltHoldBlindTime 800000
#endif
#if defined(PositionHoldOverride)
#if !defined(PosHoldBlindTime)
#define PosHoldBlindTime 300000
#endif
#if !defined(BlindZonePitch)
#define BlindZonePitch 30
#endif
#if !defined(BlindZoneRoll)
#define BlindZoneRoll 30
#endif
#endif
====================================================
Entsprechend geändert/hinzugefügt // Accordingly changed/added:
Code:
/* ALT_HOLD_THROTTLE_NEUTRAL_ZONE: Defines the neutral zone of throttle stick during altitude hold, default setting is
+/-40 uncommend and change the value below if you want to change it.
AltHoldBlindTime defines the time in micro seconds (def 0.8s) after wich a new Altitude for AltHold is defined
when throttlestickmovement stops. You see here the default values. Uncomment and change if you want.*/
//#define ALT_HOLD_THROTTLE_NEUTRAL_ZONE 40
//#define AltHoldBlindTime 800000
/**************************************************************************************/
/*********************** GPS **************************/
/**************************************************************************************/
/* PositionHoldOverride Info: http://fpv-community.de/showthread.php?14199-Baro-Code-%C4nderungen&p=189821&viewfull=1#post189821
Purpose: You can fly in position hold and override it with nick(pitch) and roll movements (defined in Blindzones below). When you return
those sticks to center a new position for pos.Hold is defined after a timeinterval defined in PosHoldBlindTime.*/
//#define PositionHoldOverride // Uncomment to activate
/*Parameters for Position hold Override You see here the default values. Uncomment and change if you want */
//#define PosHoldBlindTime 300000 // Time in microseconds (def. 0.3 sec) before PH is re-engaged after returning to Stickcenter
//#define BlindZonePitch 30 // Defines the Blindzone around Pitchaxiscenter
//#define BlindZoneRoll 30 // Defines the Blindzone around Rollaxiscenter
Das wars ! / That was it!
So long
Rob
Zuletzt bearbeitet: