+#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()
float b;
b=_rotor->getBalance();
float s =Math::sin(_phi+_direction);
- float c =Math::cos(_phi+_direction);
+ //float c =Math::cos(_phi+_direction);
if (s>0)
_balance=(b>0)?(1.-s*(1.-b)):(1.-s)*(1.+b);
else
_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)
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;
+ 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 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;
*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