IUS 1.0 Development

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,728
Reaction score
2,692
Points
203
Location
Dallas, TX
Got a question. Since this is a double stage rocket. Both stages would be attached. To fly it switch to first stage and fire thrust. Then at a time press a key to dettach the first stage and switch to 2nd stage and fly away?
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,627
Reaction score
2,345
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
Got a question. Since this is a double stage rocket. Both stages would be attached. To fly it switch to first stage and fire thrust. Then at a time press a key to dettach the first stage and switch to 2nd stage and fly away?

You could also just switch directly to the second stage... or not attach the two stages, etc... Or not all receiving focus and make all automatic (what would be more realistic, since it is an unmanned vessel)
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,728
Reaction score
2,692
Points
203
Location
Dallas, TX
You could also just switch directly to the second stage... or not attach the two stages, etc... Or not all receiving focus and make all automatic (what would be more realistic, since it is an unmanned vessel)
If you are in the 2nd stage how would you fly it? Would you have rcs and main thrust from the 2nd stage just show up in the 1st stage if attached?
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,627
Reaction score
2,345
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
If you are in the 2nd stage how would you fly it? Would you have rcs and main thrust from the 2nd stage just show up in the 1st stage if attached?

Second stage RCS is always on, it is the only RCS of the IUS anyway. The only good reason for using attachments is a smoother separation sequence. Which isn't too critical for a IUS.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,728
Reaction score
2,692
Points
203
Location
Dallas, TX
oh. But then show the main thrust coming from 1st stage if attached? Flying from 2nd stage that is
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,627
Reaction score
2,345
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
oh. But then show the main thrust coming from 1st stage if attached? Flying from 2nd stage that is

of course. That is the goal. How you reach this goal is your freedom. You just can't use the RCS of the IUS without the second stage, while you can easily fake the first stage as plain dumb child attachment
 

DaveS

Addon Developer
Addon Developer
Donator
Beta Tester
Joined
Feb 4, 2008
Messages
9,435
Reaction score
689
Points
203
oh. But then show the main thrust coming from 1st stage if attached? Flying from 2nd stage that is
You could make it a proper multistage vessel instead of using attachments. The only two attachment points would be child to ASE and parent to payload.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,728
Reaction score
2,692
Points
203
Location
Dallas, TX
It would seem the way to go is make the 2nd stage the main ship. IF the 1st stage is attached then the empty mass = empty mass of 2 + empty mass of 1. Also propellant load. Fire the thrust from SRM2 but if srm1 is attached then show the thrust where it should be.
The mass and isp change depending on the attachment condition. But Haven't got it to create a thruster/exhaust for when attach and when not attached.
Code:
void IUS1::clbkPostStep(double simt, double simdt, double mjd)
{
	if (GetAttachmentStatus(RM1))//ATTACHED
	{
		newmass = 1134 + 1170;
			SetEmptyMass  (newmass);
		attached = 1;
		//SetISP(2898);
		MAX_MAIN_THRUST = 184752.84;
		MAX_MAIN_FUEL = 9631;
		SetEXHAUST();
		SetThrusterIsp(th_main[0], 2898);
	}
	if (!GetAttachmentStatus(RM1))//DEATACHED
	{
		
		SetEmptyMass(1170);
		attached = 0;
		//SetISP(2977.335);
		MAX_MAIN_THRUST = 78272.76;
		MAX_MAIN_FUEL = 2727.45;
		SetEXHAUST();
		SetThrusterIsp(th_main[0], 2977.335);
	}
}

...
void IUS1::SetEXHAUST()
//
{

	if (attached == 1)
	{
		//AddExhaust(th_main, 10.1,1, _V(0, 0, -1.5), _V(0, 0, -1));
		if (stage != 2){
		th_main[0] = CreateThruster(_V(0, 0, 0), _V(0, 0, -1.5), 184752, ph_main, 2898);
		thg_main = CreateThrusterGroup(th_main, 1, THGROUP_MAIN);
		AddExhaust(th_main[0], 10, 1, _V(0, 0, -1.5), _V(0, 0, -1));
		stage = 2;
	}

	}

if (attached == 0)
{
	if (stage != 1){
		th_main[0] = CreateThruster(_V(0, 0, 0), _V(0, 0, -1.5), 78272.76, ph_main, 2977.335);
		thg_main = CreateThrusterGroup(th_main, 1, THGROUP_MAIN);
		AddExhaust(th_main[0], 10, 1, _V(0, 0, .841), _V(0, 0, -1));
		stage = 1;

	}
}
}
 
Last edited:

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,627
Reaction score
2,345
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
Can I put a veto on that code? I don't think this source code is acceptable.

  • It is using cryptic and unreadable identifiers.
  • It has no comments at all to explain what the code is doing. Also no doxygen comments to help documenting the source code.
  • It contains copy and paste code, right down to the lines disabled by turning them into comments. That degrades code quality.
  • It fails to use "if...else..." for a yes/no decision.
  • It performs these state changes every timestep - that is a bug according to your description of what the code should do. Maybe it works now. But it will cause nasty surprises later.
  • It is not the solution of the least surprise. It is overly complicated for a very simple problem.

I think, for the sake of simplicity: Make the IUS one vessel. The first stage isn't that smart that it requires a DLL right now, we can make a DLL for possible outgassing effects later.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,728
Reaction score
2,692
Points
203
Location
Dallas, TX
Sure you can veto. Well the code is not finish so comments have not been added.

Right now the IUS is one vessel. The 1st stage is attached. It is just a CFG.

So if the first stage is attached make the changes to the mass, fuels, thruster location,....
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,627
Reaction score
2,345
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
Sure you can veto. Well the code is not finish so comments have not been added.

That's not how you do it. Comment before, while AND after you develop the code. Its an accompanying process and you do that for making your own life easier.

Especially, you have many decisions already finished at this stage (why this variable, etc), that you can comment in a final version.

And still, a lot of problems remain from just a very short excerpt of code and a quick review. Keep it clean from the start. You also don't want a surgeon to disinfect his hands after performing the surgery on you, do you?
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,728
Reaction score
2,692
Points
203
Location
Dallas, TX
Is this better?
Code:
void IUS1::clbkPostStep(double simt, double simdt, double mjd)
{
	if (GetAttachmentStatus(RM1))//2ND STAGE IS ATTACHED TO 1ST STAGE
	{
		newmass = STAGE1MASS+STAGE2MASS;  //MASS OF STAGE 1 AND STAGE 2 ARE ADDED
		SetEmptyMass  (newmass);    //NEW MASS OF STAGE 2 AND STAGE 1
		ATTACH_status=YES;         //2ND STAGE IS ATTACHED TO 1ST STAGE
		MAX_MAIN_THRUST = 184752.84;  // THRUST OF STAGE 1
		MAX_MAIN_FUEL = 9631;           // FUEL OF STAGE1
		SetThrusterIsp(th_main, 2898);  //SETS ISP OF STAGE 1
		SetThrusterMax0(th_main, 184752.84); //THRUST OF STAGE 1
		AddExhaust(th_main, 10, 1, _V(0, 0, -1.5), _V(0, 0, -1)); //EXHAUST location OF 1ST STAGE
	}
	if (!GetAttachmentStatus(RM1))//2ND STAGE IS NOT ATTACHED TO 1ST STAGE
	{
		
		SetEmptyMass(1170);  //EMPTY MASS OF STAGE 2 ALONE
		ATTACH_status = NO;  //2ND STAGE IS NOT ATTACHED TO 1ST STAGE
		MAX_MAIN_THRUST = 78272.76;  //THRUST OF STAGE 2 ALONE
		MAX_MAIN_FUEL = 2727.45;     //FUEL OF STAGE 2 ALONE
		SetThrusterIsp(th_main, 2977.335);  //SET ISP OF STAGE 2
		SetThrusterMax0(th_main, 78272.76);  //SET MAX THRUST OF STAGE 2 ALONE
		AddExhaust(th_main, 1, 1, _V(0, 0, -1.5), _V(0, 0, -1)); //EXHAUST location OF 2ND STAGE

	}
}
Now thrust and exhaust, mass, isp all change depending on attach status.

but I get this effect.
http://i373.photobucket.com/albums/oo179/gattispilot/iusexhaust_zpsec480f11.jpg
 
Last edited:

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,627
Reaction score
2,345
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
No. The comments are nice - but you fail to see the big issue:

if(a) {
}
if(!a) {
}

Notice it?

Next, you have exactly the same instructions except some parameters - you could let a function do that for you, for example by grouping the constants into a struct, define a constant struct in the definitions for your vessel in your header file, where you will quickly find it for editing, and passing this constant struct as parameter to an inline function. And why YES and NO instead of true and false?

This all just makes the code extremely terrible to maintain, what you are doing there - and the idea behind open-source software is not dumping bad source code into the public, but have a good public source code to work with.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,728
Reaction score
2,692
Points
203
Location
Dallas, TX
Thanks.

I guess I don't see what is wrong with if attach do something unless it is :
if (a) attach do something
else do something because not attached.

So make a function called "update info". Where it reads the struct data and applys it?
So make a struct of mass, thrust,..... Since I haven't done this before I can look at a sample and figure it out.

But the white exhaust circle is bugging me. I think it is because I am changing the exhaust location, right



http://i373.photobucket.com/albums/oo179/gattispilot/iusexhaust_zpsec480f11.jpg
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,627
Reaction score
2,345
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
Thanks.

I guess I don't see what is wrong with if attach do something unless it is :
if (a) attach do something
else do something because not attached.

Exactly - because otherwise, you call for the function to be evaluated a second time, despite you already knowing the result. Sometimes, this can be intentional - the compiler won't optimize it away for you in general. But usually, and since you are smarter than the compiler, you tell it have to understand the code properly.

Similar, you have to think about which objects, classes and functions you need for solving your problems. Copy and Paste code can work - but you make yourself more stupid than the compiler that way. Better is using the syntactic tools of the language for explaining the compiler semantic aspects of your program: This function is short and can be copied in place instead of calling it with all the stack frame voodoo around it (inline). Or this variable has to be treated volatile and must not be optimized into a register-only variable. Or this function does not change the attributes of the class (const). Or this function is purely virtual (virtual ... f(...) = 0; ), don't permit use of such an abstract class.

You have MANY ways to tell your compiler what you mean, instead of just what you want to do, and when you create a contradiction by using something differently than declared, the compiler can stop you from committing errors.

Same with writing many comments about your functions before you write a single line of code there. Yes, it stops your creative flow sometimes. But it helps you find errors before you program them. And tools like doxygen (which is used by Orbiter for the API Reference) make it very simple to navigate through the code.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,728
Reaction score
2,692
Points
203
Location
Dallas, TX
ok. Thanks. Never heard of doxygen. But looked it up.

One problem I see is if attach then set exhaust where it should be either at the nozzle of 1st or 2nd stage. I get that white circle.

So in summary:
If attached { get info from struct)
else (get info from struct}

But the set exhaust is the puzzle.
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,627
Reaction score
2,345
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
ok. Thanks. Never heard of doxygen. But looked it up.

One problem I see is if attach then set exhaust where it should be either at the nozzle of 1st or 2nd stage. I get that white circle.

So in summary:
If attached { get info from struct)
else (get info from struct}

But the set exhaust is the puzzle.

Well, what about simply creating two different thrusters, each with its own propellant resource... Oh wait, that's too easy.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,728
Reaction score
2,692
Points
203
Location
Dallas, TX
Well, what about simply creating two different thrusters, each with its own propellant resource... Oh wait, that's too easy.

Well yes. But you would need if attach then use thruster0 and if not attach use thruster1, right

The whole rcs is wierd. !2 nozzles and none facing forward/ up. Not sure how pitch would be achieved. Just by firing one side maybe?
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,627
Reaction score
2,345
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
Well yes. But you would need if attach then use thruster0 and if not attach use thruster1, right

The whole rcs is wierd. !2 nozzles and none facing forward/ up. Not sure how pitch would be achieved. Just by firing one side maybe?

Exactly. The RCS is not translation-neutral, since the IUS never needs to dock to a spacecraft. actually, you have 2x6 RCS thrusters there, two redundant systems, each enough for providing pointing and compensating SRM performance.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,728
Reaction score
2,692
Points
203
Location
Dallas, TX
On the mesh there are 2 manifolds that have 4 nozzles. And another set of manifolds that have 2 nozzles that are on the same side.

iusrcs_zps3b95fbe9.jpg
 
Top