示例#1
0
// Basically NAVMODE_KILLROT in a single dimension.  Returns true when the rate has been nulled
// out, otherwise it returns false.
bool NullRate(AXIS Axis)
{
	VESSEL *Vessel = oapiGetFocusInterface();
	VESSELSTATUS Status;
	Vessel->GetStatus(Status);

	double RateDeadband = Radians(0.001), Thrust, Level, Rate = Status.vrot.data[Axis],
			Mass = Vessel->GetMass(),
			MaxThrust = Vessel->GetMaxThrust(ENGINE_ATTITUDE),
			Size = Vessel->GetSize();

	VECTOR3 PMI;
	Vessel->GetPMI(PMI);

	if (fabs(Rate) < RATE_NULL) {
		Vessel->SetAttitudeRotLevel(Axis, 0.0);
		return true;
	}

	Thrust = -(Mass * PMI.data[Axis] * Rate) / (Size);
	Level = min((Thrust/MaxThrust), 1);
	Vessel->SetAttitudeRotLevel(Axis, Level);

	return false;
}
示例#2
0
// Wrapper for the above function that assumes that the rotation rate is vrot.
// Calling the function directly allows more control but will probably be used less
bool SetAttitude(double TargetAttitude, double CurrentAttitude, AXIS Axis, DEADBAND DeadbandLow)
{
	VESSEL *Vessel;			// Spacecraft interface
	VESSELSTATUS Status;	// Spacecraft status

	Vessel = oapiGetFocusInterface();
	Vessel->GetStatus(Status);

	return SetAttitude(TargetAttitude, CurrentAttitude, Status.vrot.data[Axis], Axis, DeadbandLow);
}
示例#3
0
DLLCLBK void opcPreStep(double simt, double simdt, double mjd)
{
	if (Init==FALSE)
	{
		if (ConfigLoaded==FALSE)
			g_UFA.init();
		LoadOptions();
		Init=TRUE;
		srand(time(NULL));
		return;
	}
	g_UFA.TimeStep();
	HUD.TimeStep();
	VOBJ * v = g_UFA.GetFocus();
	if (v==NULL)
		return;
	char cbuf[255];
	if (Ejection==TRUE)
	{
		if (lEjectionTime>oapiGetSimTime())
			return;
		lEjectionTime=oapiGetSimTime()+1;
		int crewcount = v->crew.GetCrewTotalNumber();
		if (!crewcount){
			Ejection=FALSE;
			return;
		}
		double eVel = 0;
		VESSEL * vessel = NULL;
		VESSEL * focus = oapiGetFocusInterface();
		VESSELSTATUS vs; 
		OBJHANDLE hVes=NULL;
		if (VESSEL(v->hook).GetAtmPressure() < 2.5)
		{
			eVel=5;
			v->crew.SetEjectPosRotRelSpeed(_V(0, 0, 0),_V(0,1,0),
					_V(eVel,eVel, 0));
			v->crew.EjectCrewMember(v->crew.GetCrewNameBySlotNumber(0));
		}else
		{
			v->crew.SetEjectPosRotRelSpeed(_V(0, 0, 0),_V(0,1,0),
					_V(0,0, 0));
			v->crew.EjectCrewMember(v->crew.GetCrewNameBySlotNumber(0));
		}
		hVes = v->crew.GetObjHandleOfLastEVACrew();
		if (!oapiIsVessel(hVes))
			return;
		vessel = oapiGetVesselInterface(hVes);
		sprintf(cbuf,"%s-pack",vessel->GetName());
		vessel->GetStatus(vs);
		oapiCreateVessel(cbuf,"Ummuturbopack",vs);
	}
	double yofs = Y_OFS_START;
	for (int i = 0; i < v->hudprint.m.size(); i++)
	{
		sprintf(cbuf,"%s",v->hudprint.m[i].c_str());
		HUD.Add(0.0001,v->hook,HUD._D(X_OFS_START,1,yofs,1,Size,COLOR,cbuf));
		yofs+=LINE_SPACE;
	}
	HUD.TimeStep();
}
示例#4
0
文件: eva.cpp 项目: dseagrav/NASSP
void EVA::clbkPreStep (double simt, double SimDT, double mjd)

{
	char EVAName[256]="";
	char CSMName[256]="";
	char MSName[256]="";

	strcpy(EVAName,GetName());
	double VessCount;
	int i=0;
	VessCount=oapiGetVesselCount();
	hMaster=oapiGetVesselByIndex(i);
	while (i<VessCount)i++;{
	oapiGetObjectName(hMaster,MSName,256);
	strcpy(CSMName,MSName);strcat(CSMName,"-EVA");
		if (strcmp(CSMName,EVAName)==0)
		{
			i=int(VessCount);
		}
	}
	sprintf(oapiDebugString(), "EVA Cable Attached to %s", MSName);
	VESSELSTATUS csmV;
	VESSELSTATUS evaV;
	VESSEL *csmvessel;
	VECTOR3 rdist = {0,0,0};
	VECTOR3 posr  = {0,0,0};
	VECTOR3 rvel  = {0,0,0};
	VECTOR3 RelRot  = {0,0,0};
	double dist = 0.0;
	double Vel = 0.0;

	if (hMaster)
	{
		csmvessel = oapiGetVesselInterface(hMaster);
		oapiGetRelativePos (GetHandle() ,hMaster, &posr);
		oapiGetRelativeVel (GetHandle() ,hMaster , &rvel);
		GetStatus(evaV);
		csmvessel->GetStatus(csmV);
		GlobalRot (posr, RelRot);
		dist = sqrt(posr.x * posr.x + posr.y * posr.y + posr.z * posr.z);
		Vel = sqrt(rvel.x * rvel.x + rvel.y * rvel.y + rvel.z * rvel.z);
		if (dist >= 25)
		{
			rvel  = evaV.rvel-csmV.rvel;
			rvel.x = -rvel.x;
			rvel.y = -rvel.y;
			rvel.z = -rvel.z;
			GetStatus(evaV);
			csmvessel->GetStatus(csmV);
			evaV.rvel = csmV.rvel + rvel;
			DefSetState(&evaV);
		}
		if (GoDock1){
			sprintf(oapiDebugString(), "EVA Back CSM Mode Relative Distance M/s %f", dist);
			if (dist <= 0.55 && dist>=0.50 ){
				GoDock1 =false;
				oapiSetFocusObject(hMaster);
				oapiDeleteVessel(GetHandle());
			}
		}

	}
}