Nivekk / KOS

Fully programmable autopilot mod for KSP.
Other
80 stars 30 forks source link

Added SENSOR to the script language #200

Closed palaslet closed 10 years ago

palaslet commented 10 years ago

Please consider adding this functionality to make it possible to read values from sensors attached to the vessel.

a1270 commented 10 years ago

If this gets in 'INLIGHT' can be merged into VesselSensors. Collect the sun exposure from all panels and return that instead. Adding that to the list of tasks i work on today.

palaslet commented 10 years ago

Sorry about the close/reopen action. Accidentally clicked...

a1270 commented 10 years ago

That seems better, the ksp "api" is very confusing and i tend to miss the best route. As a side note, how do you invoke it? I have tried SHIP:SENSORS:, SENSORS:, and SHIP:GRAV/etc with no luck.

palaslet commented 10 years ago

SENSOR:[TEMP|ACC|GRAV|PRES]. Ex: PRINT "SENSOR.TEMP: " + SENSOR:TEMP AT (0,0). PRINT "SENSOR.ACC : " + SENSOR:ACC AT (0,1). PRINT "SENSOR.GRAV: " + SENSOR:GRAV AT (0,2). PRINT "SENSOR.PRES: " + SENSOR:PRES AT (0,3).

TEMP and PRES returns float values while GRAV and ACC returns vectors.

palaslet commented 10 years ago

It should be possible to use them both with SHIP and TARGET

a1270 commented 10 years ago

Feel like a real idiot. Totally didn't see i added an extra 's' on it. I'll make a note of that when i writhe the docs for it.

a1270 commented 10 years ago

The one nitpick i have is it returns values if the sensor is active or not. Considering sensors take no power the time to implement a check would be wasted. I look forward to duct taping my light sensor to your code. hehe.

palaslet commented 10 years ago

Yes, it felt cumbersome to be forced to activate the sensor before launch. Maybe TOGGLE should be able to toggle the sensors as well?

a1270 commented 10 years ago

That seems reasonable.

Dunbaratu commented 10 years ago

I've been adding terminal velocity and air drag calculations to my lander script. The ability to query air pressure from the gauge will be really handy. Right now it just calculates it from known data for the SOI body.

palaslet commented 10 years ago

I've done the same in my script. :) I'll post a new change later adding AIRSPEED. But that's not for this pull.

a1270 commented 10 years ago

Is there a specific reason acceleration is a vector? target.geeForce returns a double. Also learned sensors do use power, just very little.

palaslet commented 10 years ago

In physics gravity is acceleration, and acceleration has both a direction and a magnitude so vector would be the only correct representation. geeForce probably returns the magnitude of the gravity vector. You can do the same by assigning GRAV to a variable and then use the MAG suffix to get the magnitude. Ex. SET vGrav TO SENSOR:GRAV. PRINT "geeForce: " + vGrav:MAG.

a1270 commented 10 years ago

Thanks for the info. I really should beef up my physics. Also gave me some good info for the docs.

Dunbaratu commented 10 years ago

If geeForce differs from the gravity vector only in the fact that it's not a vector then the terminology isn't quite right. If one thing is being called a "force" and the other thing is being called an "acceleration", then they should have different values (one should not merely be the scalar magnitude of the other) because a force has mass multiplied into it and an acceleration doesn't.

i.e. if "geeForce" is just an acceleration then it shouldn't be called a "force".

palaslet commented 10 years ago

I'm sorry for being inaccurate. Yes, G-force is a force. And force tries to accelerate the bodies it do work on (G-force is noted by the acceleration it does: 9.81 m/s2). Both force and acceleration has little meaning without direction (at least in motion-physics). And since magnitude can be derived from the vector I thought that would be the best and most usable representation.

a1270 commented 10 years ago

I am get odd results from ACC. On the ground the mag is returning 0.0xxx whereas the accelerate is saying it's 0.99. When the meter claims 4.50 the magnitude is returning upwards of 60. GRAV works as expected. http://i.imgur.com/4kE9pip.png http://i.imgur.com/w2S7RV8.png

set x to 0.
lock vAcc to sensor:acc.
lock vGrav to sensor:grav.
on ag5 break.
clearscreen.
until x > 1
{
  print "G-Force: " + vAcc:mag + "g" at (0,5).
  print "LocalGravity: " + round(vGrav:MAG, 2) + " m/s^2" at (0,6).
}
palaslet commented 10 years ago

It is corrected now. ACC reports the acceleration in m/s^2. So the value must be divided by the local g-force to get the actual G-value. What I did wrong was to report only the acceleration relative to the gravity body (Kerbin). I forgot the one G needed to not sink into the ground (Since 0 G is freefalling, and that means moving towards the gravity source).

a1270 commented 10 years ago

EDIT: misread your comment.

palaslet commented 10 years ago

Fixed a sign-bug. It's still a bit off. about 5% or so (or maybe it's a static error). The API isn't really well documented, so I don't know how to make it more accurate at this point. So tire now.. It's 00:32 here... I'll look into this again tomorrow.

a1270 commented 10 years ago

Was going to post again saying it wasn't working when your commit popped in.

set x to 0.
lock vAcc to sensor:acc.
lock vGrav to sensor:grav.
on ag5 break.
clearscreen.
until x > 1
{
  print "G-Force: " + round((vAcc:MAG / vGrav:MAG), 2) at (0,5).
  print "LocalGravity: " + round(vGrav:MAG, 2) + " m/s^2" at (0,7).
}

This seems to be working as intended. Sorry about bugging you so much, it's hard to play dota2 when you're editing text files. goodnight.

Nivekk commented 10 years ago

Looks good!

I did merge this but I think I did it wrong, github doesn't seem to see that I merged it.

Edit: Or maybe it does see it? hmm