+#include <ostream>
+
#include <simgear/debug/logstream.hxx>
#include "Math.hpp"
#include <stdio.h>
#include <string.h>
namespace yasim {
+using std::endl;
+
const float pi=3.14159;
float _help = 0;
Rotorpart::Rotorpart()
_rel_len_blade_start=0;
_torque=0;
_rotor_correction_factor=0.6;
+ _direction=0;
+ _balance=1;
}
void Rotorpart::inititeration(float dt,float *rot)
a=Math::dot3(rot,dir);
_alphaalt -= a;
_alphaalt= Math::clamp(_alphaalt,_alphamin,_alphamax);
+
+ //unbalance
+ float b;
+ b=_rotor->getBalance();
+ float s =Math::sin(_phi+_direction);
+ //float c =Math::cos(_phi+_direction);
+ if (s>0)
+ _balance=(b>0)?(1.-s*(1.-b)):(1.-s)*(1.+b);
+ else
+ _balance=(b>0)?1.:1.+b;
}
void Rotorpart::setRotor(Rotor *rotor)
_rotor=rotor;
}
-void Rotorpart::setParameter(char *parametername, float value)
+void Rotorpart::setParameter(const char *parametername, float value)
{
#define p(a) if (strcmp(parametername,#a)==0) _##a = value; else
void Rotorpart::setPosition(float* p)
{
- int i;
- for(i=0; i<3; i++) _pos[i] = p[i];
+ for(int i=0; i<3; i++) _pos[i] = p[i];
}
float Rotorpart::getIncidence()
void Rotorpart::getPosition(float* out)
{
- int i;
- for(i=0; i<3; i++) out[i] = _pos[i];
+ for(int i=0; i<3; i++) out[i] = _pos[i];
}
void Rotorpart::setPositionForceAttac(float* p)
{
- int i;
- for(i=0; i<3; i++) _posforceattac[i] = p[i];
+ for(int i=0; i<3; i++) _posforceattac[i] = p[i];
}
void Rotorpart::getPositionForceAttac(float* out)
{
- int i;
- for(i=0; i<3; i++) out[i] = _posforceattac[i];
+ for(int i=0; i<3; i++) out[i] = _posforceattac[i];
}
void Rotorpart::setSpeed(float* p)
{
- int i;
- for(i=0; i<3; i++) _speed[i] = p[i];
+ for(int i=0; i<3; i++) _speed[i] = p[i];
Math::unit3(_speed,_direction_of_movement);
}
void Rotorpart::setDirectionofZentipetalforce(float* p)
{
- int i;
- for(i=0; i<3; i++) _directionofcentripetalforce[i] = p[i];
+ for(int i=0; i<3; i++) _directionofcentripetalforce[i] = p[i];
}
void Rotorpart::setDirectionofRotorPart(float* p)
{
- int i;
- for(i=0; i<3; i++) _directionofrotorpart[i] = p[i];
+ for(int i=0; i<3; i++) _directionofrotorpart[i] = p[i];
+}
+
+void Rotorpart::setDirection(float direction)
+{
+ _direction=direction;
}
void Rotorpart::setOmega(float value)
void Rotorpart::setNormal(float* p)
{
- int i;
- for(i=0; i<3; i++) _normal[i] = p[i];
+ for(int i=0; i<3; i++) _normal[i] = p[i];
}
void Rotorpart::getNormal(float* out)
{
- int i;
- for(i=0; i<3; i++) out[i] = _normal[i];
+ for(int i=0; i<3; i++) out[i] = _normal[i];
}
void Rotorpart::setCollective(float pos)
float incidence, float cyc, float alphaalt, float *torque,
float *returnlift)
{
- float moment[3],v_local[3],v_local_scalar,lift_moment,v_flap[3],v_help[3];
- float ias;//nur f. dgb
- int i,n;
- for (i=0;i<3;i++)
- moment[i]=0;
- lift_moment=-_mass*_len*9.81; //*cos yaw * cos roll
+ float v_local[3],v_local_scalar,lift_moment,v_flap[3],v_help[3];
+ float relgrav = Math::dot3(_normal,_rotor->getGravDirection());
+ lift_moment=-_mass*_len*9.81*relgrav;
*torque=0;//
if((_nextrp==NULL)||(_lastrp==NULL)||(_rotor==NULL))
- return 0.0;//not initialized. Can happen during startupt of flightgear
+ return 0.0;//not initialized. Can happen during startup of flightgear
if (returnlift!=NULL) *returnlift=0;
float flap_omega=(_next90rp->getrealAlpha()-_last90rp->getrealAlpha())
*_omega / pi;
float local_width=_diameter*(1-_rel_len_blade_start)/2.
/(float (_number_of_segments));
- for (n=0;n<_number_of_segments;n++)
+ for (int n=0;n<_number_of_segments;n++)
{
float rel = (n+.5)/(float (_number_of_segments));
float r= _diameter *0.5 *(rel*(1-_rel_len_blade_start)
Math::mul3(1/v_local_scalar,v_local,v_help);
float incidence_of_airspeed = Math::asin(Math::clamp(
Math::dot3(v_help,_normal),-1,1)) + local_incidence;
- ias = incidence_of_airspeed;
+ //ias = incidence_of_airspeed;
//reduce the ias (Prantl factor)
float prantl_factor=2/pi*Math::acos(Math::exp(
incidence_of_airspeed = (incidence_of_airspeed+
_rotor->getAirfoilIncidenceNoLift())*prantl_factor
*_rotor_correction_factor-_rotor->getAirfoilIncidenceNoLift();
- ias = incidence_of_airspeed;
+ //ias = incidence_of_airspeed;
float lift_wo_cyc = _rotor->getLiftCoef(incidence_of_airspeed
-cyc*_rotor_correction_factor*prantl_factor,v_local_scalar)
* v_local_scalar * v_local_scalar * A *rho *0.5;
//angle between blade movement caused by rotor-rotation and the
//total movement of the blade
- /* the next shold look like this, but this is the inner loop of
- the rotor simulation. For small angles (and we hav only small
- angles) the first order approximation works well
lift_moment += r*(lift * Math::cos(angle)
- drag * Math::sin(angle));
*torque += r*(drag * Math::cos(angle)
+ lift * Math::sin(angle));
- */
- lift_moment += r*(lift * (1-angle*angle)
- - drag * angle);
- *torque += r*(drag * (1-angle*angle)
- + lift * angle);
-
if (returnlift!=NULL) *returnlift+=lift;
}
- //as above, use 1st order approximation
+ //use 1st order approximation for alpha
//float alpha=Math::atan2(lift_moment,_centripetalforce * _len);
float alpha;
if (_shared_flap_hinge)
{
float div=0;
if (Math::abs(_alphaalt) >1e-6)
- div=(_centripetalforce * _len - _mass * _len * 9.81 /_alpha0*(_alphaalt+_oppositerp->getAlphaAlt())/(2.0*_alphaalt));
+ div=(_centripetalforce * _len - _mass * _len * 9.81 * relgrav /_alpha0*(_alphaalt+_oppositerp->getAlphaAlt())/(2.0*_alphaalt));
if (Math::abs(div)>1e-6)
+ {
alpha=lift_moment/div;
+ }
else if(Math::abs(_alphaalt+_oppositerp->getAlphaAlt())>1e-6)
{
- float div=(_centripetalforce * _len - _mass * _len * 9.81 *0.5)*(_alphaalt+_oppositerp->getAlphaAlt());
+ float div=(_centripetalforce * _len - _mass * _len * 9.81 *0.5 * relgrav)*(_alphaalt+_oppositerp->getAlphaAlt());
if (Math::abs(div)>1e-6)
+ {
alpha=_oppositerp->getAlphaAlt()+lift_moment/div*_alphaalt;
+ }
+ else
+ alpha=_alphaalt;
}
else
alpha=_alphaalt;
+ if (_omega/_omegan<0.2)
+ {
+ float frac = 0.001+_omega/_omegan*4.995;
+ alpha=Math::clamp(alpha,_alphamin,_alphamax);
+ alpha=_alphaalt*(1-frac)+frac*alpha;
+ }
}
else
{
float dirblade[3];
Math::cross3(_normal,_directionofcentripetalforce,dirblade);
- float vblade=Math::abs(Math::dot3(dirblade,v));
+ //float vblade=Math::abs(Math::dot3(dirblade,v));
alpha=_alphaalt+(alpha-_alphaalt)*factor;
_alpha=alpha;
float schwenkfactor=1-(Math::cos(_lastrp->getrealAlpha())-meancosalpha)*_rotor->getNumberOfParts()/4;
//missing: consideration of rellenhinge
+
+ //add the unbalance
+ _centripetalforce*=_balance;
+ scalar_torque*=_balance;
+
float xforce = Math::cos(alpha)*_centripetalforce;
float zforce = schwenkfactor*Math::sin(alpha)*_centripetalforce;
*torque_scalar=scalar_torque;
scalar_torque+= 0*_ddt_omega*_torque_of_inertia;
float thetorque = scalar_torque;
- int i;
float f=_rotor->getCcw()?1:-1;
- for(i=0; i<3; i++) {
+ for(int i=0; i<3; i++) {
_last_torque[i]=torque[i] = f*_normal[i]*thetorque;
out[i] = _normal[i]*zforce*_rotor->getLiftFactor()
+_directionofcentripetalforce[i]*xforce;
void Rotorpart::getAccelTorque(float relaccel,float *t)
{
- int i;
float f=_rotor->getCcw()?1:-1;
- for(i=0; i<3; i++) {
+ for(int i=0; i<3; i++) {
t[i]=f*-1* _normal[i]*relaccel*_omegan* _torque_of_inertia;// *_omeagan ?
_rotor->addTorque(-relaccel*_omegan* _torque_of_inertia);
}
}
+
std::ostream & operator<<(std::ostream & out, const Rotorpart& rp)
{
#define i(x) << #x << ":" << rp.x << endl