Advanced Question Adjusting Center of Gravity?

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,724
Reaction score
2,690
Points
203
Location
Dallas, TX
Ok. But how does the ship get to that rate if the target isn't the current rate
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,624
Reaction score
2,343
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
Ok. But how does the ship get to that rate if the target isn't the current rate

As said above: You use the PID function to calculate the desired pitch command value based on the difference between current rate and target rate.

In the simple example, you just need to use this pitch command value as gimbal angle (limited to minimum and maximum deflections of course)
 
Last edited:

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,724
Reaction score
2,690
Points
203
Location
Dallas, TX
So confused

So we need current pitch rate, target pitch rate. Target rate is set by user?

So the PID looks at target rate and compares to current, right
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,624
Reaction score
2,343
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
So confused

So we need current pitch rate, target pitch rate. Target rate is set by user?

So the PID looks at target rate and compares to current, right

Yes.

Error = target rate - current rate

P = error * factor
I = integrated_error * factor
D = rate_of_error * factor

gimbal_command = P + I + D

How you integrate or differentiate the error for I or D is up to you.

In the simplest case for example, you just calculate for integrated_error:

integrated_error += 0.5 * (last_error + error) * dt;

....

last_error = error;
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,724
Reaction score
2,690
Points
203
Location
Dallas, TX
And factor is what ever you want it to be.

Ok. so gimbal command is what tells the thrusters to do?

So for example target rate is 0 and current rate is 5
so error = 0-5
p=-5*factor
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,624
Reaction score
2,343
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
And factor is what ever you want it to be.

Ok. so gimbal command is what tells the thrusters to do?

So for example target rate is 0 and current rate is 5
so error = 0-5
p=-5*factor

Exactly. The gimbal command is the signal or variable that you use for rotating the engines. You can use it directly as angle or indirectly by limiting gimbal command to -1 ... +1 and then just multiply it by the maximum deflection angle.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,724
Reaction score
2,690
Points
203
Location
Dallas, TX
I didn't think I needed a guidance system. How to others deal with it?
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,624
Reaction score
2,343
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
I didn't think I needed a guidance system. How to others deal with it?

Many don't. Either they ignore docked spacecraft or let the player suffer for this.

But some also use such a code to stabilize the spacecraft.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,724
Reaction score
2,690
Points
203
Location
Dallas, TX
ok. So

looking back. PID

So for example:
current rate is 5

I set my target rate at 0
I get the pitch rate (current rate)
so the error is target-current (0-5)
P = -5* factor

Not sure what value factor should be?

I =integrated error*factor
integrated_error += 0.5 * (last_error + error) * dt;

D= rate of error* factor

P+I+D =GIMBAL.

So what is rate of error
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,624
Reaction score
2,343
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
Each factor is a coefficient that you can freely choose for tuning your guidance. You have one such coefficient for each P, I and D term.

For example, if you want to have a -5° gimbal response to 10°/s error, you could select a P-factor of -0.2.

Similar with I: If you want to have additionally -1° response by the gimbal for 10° accumulated error (for example by being off by 1°/s for 10 seconds), you select an I-factor of -0.1

And yes, with D the same.

Rate of error is the rate at which the error changes right now. In the simplest way, you can just use a linear calculation: Rate of Error = (current_error - last_error) / dt

if you measure error in °/s, the rate of error is in °/s²
 

Face

Well-known member
Orbiter Contributor
Addon Developer
Beta Tester
Joined
Mar 18, 2008
Messages
4,403
Reaction score
581
Points
153
Location
Vienna
I hope someone can help on this.

On the Endurance but other ships also. If I have 1 lander docked when I applied forward thrust I start to rotate left to right. It is due to docked vessel on one side.

So how can I either adjust the center of gravity or adjust the vector of thrust (Main,Rcs) to adjust for this?

What about this:

In every pre-step:

  • query the superstructure CoG (GetSuperstructureCG())
  • query the current thruster-force (GetThrustVector())
  • do as if that later force is from 0|0|0, then calculate the perpendicular force component w.r.t. the line between 0|0|0 and the superstructure CoG,
  • multiply this component with the line distance and you get the thruster-induced moment around the "new" CoG
  • compensate this by means of 2 AddForce() in opposite directions around the new CoG in such a magnitude that it nullifies the thruster-induced moment.
It would simulate a "high-performance balancing engine" in your vessel, if you really have to justify it :) . Not perfect, but I think it will get you there...
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,724
Reaction score
2,690
Points
203
Location
Dallas, TX
Thanks
So I get this for step1 and 2. I am lost past that
Code:
void ENDURANCE::clbkPreStep(double simtt, double simdt, double mjd)
{
    GetSuperstructureCG(superStructCG);
    GetThrustVector(thrustvector);
    

}
What about this:

In every pre-step:

  • query the superstructure CoG (GetSuperstructureCG())
  • query the current thruster-force (GetThrustVector())
  • do as if that later force is from 0|0|0, then calculate the perpendicular force component w.r.t. the line between 0|0|0 and the superstructure CoG,
  • multiply this component with the line distance and you get the thruster-induced moment around the "new" CoG
  • compensate this by means of 2 AddForce() in opposite directions around the new CoG in such a magnitude that it nullifies the thruster-induced moment.
It would simulate a "high-performance balancing engine" in your vessel, if you really have to justify it :) . Not perfect, but I think it will get you there...
 

Face

Well-known member
Orbiter Contributor
Addon Developer
Beta Tester
Joined
Mar 18, 2008
Messages
4,403
Reaction score
581
Points
153
Location
Vienna
Thanks
So I get this for step1 and 2. I am lost past that

I really don't like the back-and-forth of forum code-snippet exchanges, as it is very inefficient and prone to misunderstandings. Since I've worked with you in the past, I know how hard it would be for both of us. I'd prefer an open source project that I can send a pull-request or a patch to, but then again this is Orbiter :) .

Therefore, if you send me your work, I can draft something out for you and send it back. Ideally you would include a scenario showing the problem, so we have a system test.

Just an offer, of course. You are totally free to follow the advice here and implement a full-blown PID controlled guidance system to get the very realistic Endurance vessel out to the community. I guess it's the one with the sleep-chambers, chocolate-bar AI marine robots, SSTO landers and structural integrity surviving the event horizon of mini black-holes. :rofl:
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,724
Reaction score
2,690
Points
203
Location
Dallas, TX
Thanks. Yes, sir. The endurance from film Interstellar. Yes and thanks for all the help people have suggested.
 
Last edited:
Top