Jump to content

kOS: calculating spacecraft weight


Recommended Posts

I'm trying to calculate my spacecraft's weight, so I can keep my TWR constant. I've managed to get my thrust-to-MASS constant, but I'm having a lot of trouble trying to calculate my weight.

From what I understand, weight = gravity * mass, and gravity = G * (mass[craft] * mass[kerbin])/distance^2. However, I can't get correct results out of kOS.

Here's what I'm trying so far:


lock distance to SHIP:ALTITUDE + BODY("Kerbin"):RADIUS.

lock gravity to CONSTANT():G * ((SHIP:MASS* BODY("Kerbin"):MASS * 1000) / ( distance * distance )).

lock weight to (SHIP:MASS) * gravity.

print "distance:" + distance.
print "grav:" + gravity.
print "weight:" + weight.

kOS returns SHIP:MASS in metric tons, not kilograms, so I have multiplied by 1000 to get kg.

The craft has a mass of 2,779kg, however this gives the weight as 75,723kg! That's likely because it has gravity as 27,251 when, as far as I understand, it should be just 9.8.

What am I doing wrong? I figure I have units crossed somewhere. Or does Kerbin have fixed gravity that differs from what it should have for its mass and size?

Edited by Hyperlynx
Link to comment
Share on other sites

You have an extra SHIP:MASS term.

if your 'gravity' variable is meant to be the acceleration due to gravity, then the equation should be CONSTANT():G * ((BODY("Kerbin"):MASS * 1000) / ( distance * distance )).

(remove the ship's mass)

If your gravity variable is meant to be the force due to gravity, then the equation to calculate gravity is correct and is equal to the weight.

Link to comment
Share on other sites

FancyMouse: I was under the impression that the formula for gravity was the acceleration under gravity, not the weight due to gravity. Not so?

Reddeyfish: the force of gravity is based on the mass of both bodies, though. Granted my ship's mass is infintesimal compared to Kerbin, but it still contributes. Have I got my formula for gravity wrong?

Link to comment
Share on other sites

a = G*M/r^2 (1)

F = m*a (2)

F = G*M*m/r^2 (3)

You mixed up two different equations, one for gravitational force and for gravitational acceleration.

(1) is the acceleration. Applying Newton's second law (2) you obtain gravitational force (3), also called "weight".

What you did was taking (3) and multiplying it through all over m again - obtaining something... I think without a physical interpretation.

Link to comment
Share on other sites

Also, in addition to what the others said above, be aware of this:

You'll have a much easier time if you leave the 1000 multiplier out and just store your weight variable as weight in kilonewtons rather than weight in newtons. This is because all the other forces and masses are returned in the *1000 scale already. This is the way the game "thinks" under the hood all the time. To help reduce floating point error it's better to work with smaller magnitude numbers. When the stock panel shows a value like "mass: 0.2 tonnes". that's not just how it displays to the user. That's really how it's doing the math itself too. The PART:MASS for that part will be returned as 0.2, not as 200.

Edited by Steven Mading
Link to comment
Share on other sites

Thanks guys! It works perfectly.

The finished code:


set stageTwoTWR to 1.3.

//...

set targetTWR to stageTwoTWR.

lock distance to SHIP:ALTITUDE + BODY("Kerbin"):RADIUS.
lock weight to CONSTANT():G * ((SHIP:MASS* BODY("Kerbin"):MASS) / ( distance * distance )).

lock THROTTLE to (targetTWR * weight) / (SHIP:MAXTHRUST + 0.001).

Edited by Hyperlynx
Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...