Skip to content

Commit

Permalink
correctly consider stall- and max-speed when speed units is knots
Browse files Browse the repository at this point in the history
  • Loading branch information
iltis42 committed Sep 30, 2024
1 parent 019aaf4 commit 2f5ae3f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 38 deletions.
8 changes: 4 additions & 4 deletions main/Flap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,19 +200,19 @@ void Flap::speeds_setup_menu_create(MenuEntry*top){
plus2->setHelp("Speed for transition from +2 to +1 flap setting");
top->addEntry( plus2 );

SetupMenuValFloat *plus1 = new SetupMenuValFloat("Speed +1 to 0", "", 20, Units::Airspeed2Kmh(v_max.get()), 1, flap_speed_act, false, &flap_0 );
SetupMenuValFloat *plus1 = new SetupMenuValFloat("Speed +1 to 0", "", 20, v_max.get(), 1, flap_speed_act, false, &flap_0 );
plus1->setHelp("Speed for transition from +1 to 0 flap setting");
top->addEntry( plus1 );

SetupMenuValFloat *min1 = new SetupMenuValFloat("Speed 0 to -1", "", 20, Units::Airspeed2Kmh(v_max.get()), 1, flap_speed_act, false, &flap_minus_1 );
SetupMenuValFloat *min1 = new SetupMenuValFloat("Speed 0 to -1", "", 20, v_max.get(), 1, flap_speed_act, false, &flap_minus_1 );
min1->setHelp("Speed for transition from 0 to -1 flap setting");
top->addEntry( min1 );

SetupMenuValFloat *min2 = new SetupMenuValFloat("Speed -1 to -2", "", 50, Units::Airspeed2Kmh(v_max.get()), 1, flap_speed_act, false, &flap_minus_2 );
SetupMenuValFloat *min2 = new SetupMenuValFloat("Speed -1 to -2", "", 50, v_max.get(), 1, flap_speed_act, false, &flap_minus_2 );
min2->setHelp("Speed for transition from -1 to -2 flap setting");
top->addEntry( min2 );

SetupMenuValFloat *min3 = new SetupMenuValFloat("Speed -2 to -3", "", 50, Units::Airspeed2Kmh(v_max.get()), 1, flap_speed_act, false, &flap_minus_3 );
SetupMenuValFloat *min3 = new SetupMenuValFloat("Speed -2 to -3", "", 50, v_max.get(), 1, flap_speed_act, false, &flap_minus_3 );
min3->setHelp("Speed for transition from -2 to -3 flap setting");
top->addEntry( min3 );
}
Expand Down
2 changes: 1 addition & 1 deletion main/Protocols.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ void Protocols::sendNMEA( proto_t proto, char* str, float baro, float dp, float
sprintf(str, "$PTAS1,%d,%d,%d,%d", int((Units::ms2knots(te)*10)+200), 0, int(Units::meters2feet(alt)+2000), int(Units::kmh2knots(tas)+0.5) );
}
else {
ESP_LOGW(FNAME,"Not supported protocol %d", nmea_protocol.get() );
ESP_LOGW(FNAME,"Not supported protocol %d", proto );
}
int cs = calcNMEACheckSum(&str[1]);
int i = strlen(str);
Expand Down
62 changes: 30 additions & 32 deletions main/S2F.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
#include "KalmanMPU6050.h"

S2F::S2F() {
a0=a1=a2=0;
w0=w1=w2=0;
_min_speed = 0;
_circling_speed = 0;
a0=a1=a2=0;
w0=w1=w2=0;
_min_speed = 0;
_circling_speed = 0;
_circling_sink = 0;
_min_sink = 0;
_stall_speed_ms = 0;
Expand Down Expand Up @@ -99,7 +99,7 @@ void S2F::setPolar()
polar_wingarea.set( p.wingarea, true, false );
empty_weight.set( (p.wingload * p.wingarea) - 80.0, true, false ); // Calculate default for emtpy mass
if( Protocols::getXcvProtocolVersion() > 1 ){
Protocols::sendNmeaXCVCmd( "empty-weight", empty_weight.get() );
Protocols::sendNmeaXCVCmd( "empty-weight", empty_weight.get() );
}
ESP_LOGI(FNAME,"Reference weight:%.1f, new empty_weight: %.1f", (p.wingload * p.wingarea), empty_weight.get() );
modifyPolar();
Expand Down Expand Up @@ -153,9 +153,9 @@ float S2F::getVn( float v ){

double S2F::sink( double v_in ) {
double v = v_in;
double v_stall = Units::Airspeed2Kmh( stall_speed.get() * 0.9 );
double v_stall = stall_speed.get() * 0.9;
if ( v_in < v_stall || !IsValid() ){
// ESP_LOGI(FNAME,"S2F::sink, warning, airspeed %.1f below minimum speed", v_in );
ESP_LOGI(FNAME,"S2F::sink, warning, airspeed %.1f below minimum speed %.1f km/h", v_in, v_stall );
return 0.0;
}
v = v/3.6; // airspeed in meters per second
Expand All @@ -179,38 +179,36 @@ float S2F::cw( float v ){ // in m/s

double S2F::speed( double netto_vario, bool circling )
{
double stf = 0;
if( circling ){ // Optimum speed for a load factor of 1.4 g what corresponds 45° angle of bank and factor 1.2 speed increase; 3.6*1.2 = 4.32
stf = _circling_speed;
}else{
if( s2f_blockspeed.get() )
stf = 3.6*sqrt( ((a0-MC.get())) / a2 ); // no netto vario, no G impact
else
stf = 3.6*sqrt( (a0-MC.get()+netto_vario) / a2 );
}
// ESP_LOGI(FNAME,"speed() S2F: %f netto_vario: %f circ: %d, a0: %f, MC %f", stf, netto_vario, circling, a0, MC.get() );
if( (stf < _min_speed) || isnan(stf) )
return _min_speed;
if( stf > Units::Airspeed2Kmh(v_max.get()) || isinf( stf) )
return Units::Airspeed2Kmh(v_max.get());
else
return stf;
double stf = 0;
if( circling ){ // Optimum speed for a load factor of 1.4 g what corresponds 45° angle of bank and factor 1.2 speed increase; 3.6*1.2 = 4.32
stf = _circling_speed;
}else{
if( s2f_blockspeed.get() )
stf = 3.6*sqrt( ((a0-MC.get())) / a2 ); // no netto vario, no G impact
else
stf = 3.6*sqrt( (a0-MC.get()+netto_vario) / a2 );
}
// ESP_LOGI(FNAME,"speed() S2F: %f netto_vario: %f circ: %d, a0: %f, MC %f", stf, netto_vario, circling, a0, MC.get() );
// ESP_LOGI(FNAME,"max speed %.1f km/h", v_max.get() );
if( (stf < _min_speed) || isnan(stf) )
return _min_speed;
if( stf > v_max.get() || isinf( stf) )
return v_max.get();
else
return stf;
}

// minimum sink, circling sink, best circling speed
void S2F::recalcSinkNSpeeds()
{
if (!IsValid()) {
_min_speed =
_min_sink =
_circling_speed =
_circling_sink = 0.;
_min_speed = _min_sink = _circling_speed = _circling_sink = 0.;
return;
}
// 2*a2*v + a1 = 0
_min_speed = (3.6*-a1)/(2*a2);
if ( _min_speed < Units::Airspeed2Kmh( stall_speed.get() ) )
_min_speed = Units::Airspeed2Kmh( stall_speed.get() );
// 2*a2*v + a1 = 0
_min_speed = (3.6*-a1)/(2*a2);
if ( _min_speed < stall_speed.get() )
_min_speed = stall_speed.get();
_min_sink = sink( _min_speed );
_circling_speed = 1.2*_min_speed;
_circling_sink = sink( _circling_speed );
Expand All @@ -232,7 +230,7 @@ void S2F::test( void )
ESP_LOGI(FNAME, "Sink %f @ %s km/h ", sink( 150.0 ), "150");
ESP_LOGI(FNAME, "Sink %f @ %s km/h ", sink( 180.0 ), "180");
ESP_LOGI(FNAME, "Sink %f @ %s km/h ", sink( 220.0 ), "220");
ESP_LOGI(FNAME,"MC %f Ballast %f", MC.get(), myballast );
ESP_LOGI(FNAME,"MC %f Ballast %f", MC.get(), myballast );
for( int st=20; st >= -20; st-=5 )
{
ESP_LOGI(FNAME, "S2F %g km/h vario %g m/s", speed( (double)st/10 ), (double)st/10 );
Expand Down
2 changes: 1 addition & 1 deletion main/S2F.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class S2F {
void recalcSinkNSpeeds();
static float getBallastPercent();
inline double circlingSink(double v) {
if( v > Units::Airspeed2Kmh( stall_speed.get())*0.6 )
if( v > stall_speed.get()*0.6 )
return _circling_sink;
else
return 0;
Expand Down

0 comments on commit 2f5ae3f

Please sign in to comment.