SDK Question Canot turn off RCS Thrusters, not with SetAttitudeMode and not by a for loop

Inspired

New member
Joined
Jun 10, 2014
Messages
8
Reaction score
0
Points
0
Hey,
i'm new to the World of Orbiter and at the moment, i'm trying to code my first own vessel. It's a Vessel3 Class based ship.

This is where and how i set up my Thrusters.
I did it in clbkSetClassCaps

Code:
void MyVessel::clbkSetClassCaps(FILEHANDLE cfg)
{
...Stuff like Empty Mass, Mesh, Propellants....etc.

	// Thrusters
	thRCS[0]  = CreateThruster( _V( -3.15,  0   ,  -0.67 ),  _V(  0,  0,  1 ), 50000.0, hPropellant, 100000.0);
	thRCS[1]  = CreateThruster( _V(  3.15,  0   ,  -0.67 ),  _V(  0,  0,  1 ), 50000.0, hPropellant, 100000.0);
	thRCS[2]  = CreateThruster( _V( -3.15,  0   ,   0.67 ),  _V(  0,  0, -1 ), 50000.0, hPropellant, 100000.0);
	thRCS[3]  = CreateThruster( _V(  3.15,  0   ,   0.67 ),  _V(  0,  0, -1 ), 50000.0, hPropellant, 100000.0);
	thRCS[4]  = CreateThruster( _V( -4.25,  0   ,   0    ),  _V(  1,  0,  0 ), 50000.0, hPropellant, 100000.0);
	thRCS[5]  = CreateThruster( _V(  4.25,  0   ,   0    ),  _V( -1,  0,  0 ), 50000.0, hPropellant, 100000.0);
	thRCS[6]  = CreateThruster( _V( -3.15, -0.06,  -0.67 ),  _V(  0,  1,  0 ), 50000.0, hPropellant, 100000.0);
	thRCS[7]  = CreateThruster( _V(  3.15, -0.06,  -0.67 ),  _V(  0,  1,  0 ), 50000.0, hPropellant, 100000.0);
	thRCS[8]  = CreateThruster( _V( -3.15, -0.06,   0.67 ),  _V(  0,  1,  0 ), 50000.0, hPropellant, 100000.0);
	thRCS[9]  = CreateThruster( _V(  3.15, -0.06,   0.67 ),  _V(  0,  1,  0 ), 50000.0, hPropellant, 100000.0);
	thRCS[10] = CreateThruster( _V( -3.15,  0.06,  -0.67 ),  _V(  0, -1,  0 ), 50000.0, hPropellant, 100000.0);
	thRCS[11] = CreateThruster( _V(  3.15,  0.06,  -0.67 ),  _V(  0, -1,  0 ), 50000.0, hPropellant, 100000.0);
	thRCS[12] = CreateThruster( _V( -3.15, -0.06,   0.67 ),  _V(  0, -1,  0 ), 50000.0, hPropellant, 100000.0);
	thRCS[13] = CreateThruster( _V(  3.15, -0.06,   0.67 ),  _V(  0, -1,  0 ), 50000.0, hPropellant, 100000.0);

	// Main Engine
	thMain[0] = CreateThruster( _V( -1.1,  0   ,  -1.3 ),  _V(  0,  0,  1 ), 100000.0, hPropellant, 100000.0);
	thMain[1] = CreateThruster( _V(  1.1,  0   ,  -1.3 ),  _V(  0,  0,  1 ), 100000.0, hPropellant, 100000.0);

	THRUSTER_HANDLE thGrp[4];
	thGrp[0] = thRCS[8];
	thGrp[1] = thRCS[9];
	thGrp[2] = thRCS[10];
	thGrp[3] = thRCS[11];
	CreateThrusterGroup(thGrp, 4, THGROUP_ATT_PITCHUP);
	
	thGrp[0] = thRCS[6];
	thGrp[1] = thRCS[7];
	thGrp[2] = thRCS[12];
	thGrp[3] = thRCS[13];
	CreateThrusterGroup(thGrp, 4, THGROUP_ATT_PITCHDOWN);

	thGrp[0] = thRCS[1];
	thGrp[1] = thRCS[2];
	CreateThrusterGroup(thGrp, 2, THGROUP_ATT_YAWLEFT);

	thGrp[0] = thRCS[0];
	thGrp[1] = thRCS[3];
	CreateThrusterGroup(thGrp, 2, THGROUP_ATT_YAWRIGHT);

	thGrp[0] = thRCS[7];
	thGrp[1] = thRCS[9];
	thGrp[2] = thRCS[10];
	thGrp[3] = thRCS[12];
	CreateThrusterGroup(thGrp, 4, THGROUP_ATT_BANKLEFT);

	thGrp[0] = thRCS[6];
	thGrp[1] = thRCS[8];
	thGrp[2] = thRCS[11];
	thGrp[3] = thRCS[13];
	CreateThrusterGroup(thGrp, 4, THGROUP_ATT_BANKRIGHT);

	thGrp[0] = thRCS[4];
	CreateThrusterGroup(thGrp, 1, THGROUP_ATT_RIGHT);

	thGrp[0] = thRCS[5];
	CreateThrusterGroup(thGrp, 1, THGROUP_ATT_LEFT);

	thGrp[0] = thRCS[6];
	thGrp[1] = thRCS[7];
	thGrp[2] = thRCS[8];
	thGrp[3] = thRCS[9];
	CreateThrusterGroup(thGrp, 4, THGROUP_ATT_UP);

	thGrp[0] = thRCS[10];
	thGrp[1] = thRCS[11];
	thGrp[2] = thRCS[12];
	thGrp[3] = thRCS[13];
	CreateThrusterGroup(thGrp, 4, THGROUP_ATT_DOWN);

	thGrp[0] = thRCS[0];
	thGrp[1] = thRCS[1];
	CreateThrusterGroup(thGrp, 2, THGROUP_ATT_FORWARD);
	
	thGrp[0] = thRCS[2];
	thGrp[1] = thRCS[3];
	CreateThrusterGroup(thGrp, 2, THGROUP_ATT_BACK);

	// Kombination der Twin Ion Engines zur Haupttriebwerk
	thGrp[0] = thMain[0];
	thGrp[1] = thMain[1];
	CreateThrusterGroup(thGrp, 2, THGROUP_MAIN);

	for(int i = 0; i<14; i++)
		AddExhaust(thRCS[i], 0.4 , 0.02);

	for(int i = 0; i<2; i++)
		AddExhaust(thMain[i], 1.0 , 0.06);

Now, i got a calculation in clbkPreStep based on the Simulation time.
Its a calculation for fuel useage / fuel flow.
I took a fuel tank to simulate my life support system (called LSS). This is why i need the calculation based on the simulation time.
And if the LSS is down, the Pilot is "dead" so the control of the vessel is lost. I tried to implement this setting the thrusterlevel to 0.

Code:
void MyVessel::clbkPreStep(double simt, double simdt, double mjd)
{
	if(GetPropellantMass(LSS)>0)
	{
		....Calculate fuel flow and update mass in fueltank
	}
	else
	{
		SetAttitudeMode(RCS_NONE); [COLOR="Blue"]has no effect on RCS Thrusters[/COLOR]
                SetThrusterGroupLevel(THGROUP_MAIN, 0);

[COLOR="Blue"]next try, also has no effect on RCS Thrusters[/COLOR]
		for (int i=1; i<14; i++)
			{
				SetThrusterLevel(thRCS[i],0);
			}
		sprintf(oapiDebugString(),"Life Support System down! Lost control of Spaceship!");
	}

}


So all in all, the code disables the Main engine, but not all the other thrusters.
Whether SetAttitudeMode(RCS_NONE);, nor the for loop will work correctly.

I hope someone of you can help me with this. Already got many, many good workarounds and tips around here. :hailprobe::cheers:


Edit/ i tried it with eg.: SetThrusterGroupLevel(THGROUP_ATT_PITCHDOWN) etc. also, but this doesen't work either. Only THGROUP_Main can be shut down.
 
Last edited:

BrianJ

Addon Developer
Addon Developer
Joined
Apr 19, 2008
Messages
1,679
Reaction score
902
Points
128
Location
Code 347
One small error in clbkPreStep I can see......

for (int i=1; i<14; i++)

should be.....

for (int i=0; i<14; i++)

Good luck!
 

martins

Orbiter Founder
Orbiter Founder
Joined
Mar 31, 2008
Messages
2,448
Reaction score
462
Points
83
Website
orbit.medphys.ucl.ac.uk
Do you have any addons running which may be bypassing the

SetAttitudeMode(RCS_NONE);

command? For example, the fly-by-wire joystick controller plugin allows to assign axes to linear and rotational thruster groups simultaneously, so it ignores the SetAttitudeMode command.

A better way to achieve what you are after is probably by disconnecting the thrusters from their propellant resources. This only needs to be done once, so no need to clutter the clbkPreStep method.

But what is the thinking about cutting the thrusters when the pilot is dead? Wouldn't it make more sense to fix them at their current setting until you run out of fuel?
 

Inspired

New member
Joined
Jun 10, 2014
Messages
8
Reaction score
0
Points
0
Ah okay, so i have to think about an other way...
The thought behind it, is to deactivate the control of the space ship.
No Pilot, no control...and deactivating the thrusters looked like a pretty easy solution.
Your idea with the current setting sounds better than mine, i'll try this.
But, how do i set the RCS thrusters to another level of thrust, if the "SetThrusterLevel" command won't work with 'em?
So i'll still have the same problem that the MainEngine is set to a fixed level, but the RCS not.
 

Inspired

New member
Joined
Jun 10, 2014
Messages
8
Reaction score
0
Points
0
ah int i=0; thy!
Now the RCS Lin stops working. RCS Rot still works somehow...
 

Inspired

New member
Joined
Jun 10, 2014
Messages
8
Reaction score
0
Points
0
sry,just looked like it worked...doesn't work either with 0 instead of 1...
But anyway it was an mistake to set in to 1.
 

Hlynkacg

Aspiring rocket scientist
Addon Developer
Tutorial Publisher
Donator
Joined
Dec 27, 2010
Messages
1,870
Reaction score
3
Points
0
Location
San Diego
I use this simple function in many of my vessels, usually mapping it to the [*] key.

Code:
// --------------------------------------------------------------
// Shut down engines and autopilots
// --------------------------------------------------------------
void InspiredVessel9000::KillThrust ()
{
	// Scroll through all declared thrusters and deactivate them
	for (int i = 0; i < GetThrusterCount (); i++)
	{
		THRUSTERHANDLE th = GetThrusterHandleByIndex (i); // Get thruster handle
		SetThrusterLevel (th, 0.0); // Set thruster level to 0
	}

	// Deactivate Orbiter's default autopilots.
	for (int i = 0; i < 8; i++) DeactivateNavmode (i); 
}
 

Inspired

New member
Joined
Jun 10, 2014
Messages
8
Reaction score
0
Points
0
Thanks for that, but SetThrusterLevel didn't work for the RCS Thrusters. Don't know why....
But i already fixed it by disconnecting the thrusters from their fuel source, with:
Code:
for (int i = 0; i < 14; i++)
		{
			SetThrusterResource(thRCS[i],0);
		}
In this way, it works to disable also the RCS Thrusters...
 

Hlynkacg

Aspiring rocket scientist
Addon Developer
Tutorial Publisher
Donator
Joined
Dec 27, 2010
Messages
1,870
Reaction score
3
Points
0
Location
San Diego
Thanks for that, but SetThrusterLevel didn't work for the RCS Thrusters.

Note that I never actually referenced an RCS thruster.

You need to bypass what ever function it is you are using to manipulate "th_rcs[*]" and manipulate the thruster directly, that is probably why SetThrusterLevel was not working for you.

Code:
// --------------------------------------------------------------
// Shut down engines and autopilots
// --------------------------------------------------------------
void InspiredVessel9000::KillThrust ()
{
	// Scroll through all declared thrusters and deactivate them
	for (int i = 0; i < GetThrusterCount (); i++)
	{
		THRUSTERHANDLE th = [COLOR="Red"]GetThrusterHandleByIndex (i);[/COLOR] // Get thruster handle
		SetThrusterLevel (th, 0.0); // Set thruster level to 0
	}

	// Deactivate Orbiter's default autopilots.
	for (int i = 0; i < 8; i++) DeactivateNavmode (i); 
}
 
Top