Jump to content

Sensor Reporter for kOS


woodywood245

Recommended Posts

Sensor Reporter 1.4 for kOS 0.9 Now Available

LICENSE

Hi guys,

So I finally decided to write my own mod. Now that kOS allows mod developers to register plugin functions with it, I decided to write a plugin that filled a hole that I thought really needed to be filled.

The Sensor Reporter for kOS mod can be used to grab sensor information and use it in kOS scripts. This mod can also be used to toggle sensors on and off programatically through kOS scripts. http://kerbalspaceprogram.com/sensor-reporter-kos/

The mod uses ModuleManager to modify stock sensor parts. Sensor Reporter does not work with the Hot Beverage Inc. sensor mod. (Thanks for letting me know, Camacha)

Sensors have to be attached to the same craft as the kOS computer, otherwise the functions will not become exposed. Also, in order to get valid data, the sensors must be powered and turned on.

I took a few hours out of the day to make this, so it's probably not perfect, though it's not complicated.

Update!

As of version 1.4, kOS 0.7 is no longer being supported. All single-precision returning functions have been removed. Do not use sensor!____f() functions anymore; they won't work.

On the upside, I've added four new math functions, and a new vessel function:

math!log(number) - returns the base-10 logarithm of the given number.

math!logb(number, base) - returns the logarithm of the given number of the given base.

math!ln(number) - returns the natural logarithm of the given number.

math!e() - returns the natural log base constant e.

vessel!isp() - returns the sum of specific impulse of all active engines.

Also, I've moved all non-sensor functions to a PartModule called kOSExtensions. These functions are available regardless of whether you have any sensors on the spacecraft. Sensor functions are still only available if you add the appropriate sensors.

Update!

As of version 1.3.2, function names no longer use colons. Colons are replaced with exclamation points. Therefore:

print sensor:grav().

Becomes

print sensor!grav().

Also, the toggle functions now return a boolean value, the result of which is the result of the toggle. You MUST use SET or LOCK with toggle functions as of the latest version, otherwise they will not work.

These changes have been made in response to the new expressions evaluation system in kOS 0.9, which stops the original system from working correctly. Be sure you adjust your existing code accordingly.

Update!

As of version 1.3.x, there are 8 new functions:

- math!pi() and math!pif() return representations of pi in double-precision and single-precision floats, respectively. Use the latter in kOS 0.7.

- physics!gravconst() and physics!gravconstf() return representations of the Gravitational Constant in double-precision and single-precision floats, respectively. Use the latter in kOS 0.7.

- vessel!velocity() and vessel!velocityf() return the current orbital velocity of the vessel in double-precision and single-precision floats, respectively. Use the latter in kOS 0.7.

- eta!apoapsis() - returns the seconds to apoapsis as a double-precision float.

- eta!periapsis() - returns the seconds to periapsis as a double-precision float.

The last two are intended as a "fix" to the current problem in kOS, where eta!apoapsis and eta!periapsis do not return values that work with math or comparison operators.

1274761_569461936447646_59745055_o.jpg

1274621_569461929780980_1253898775_o.jpg

1243603_569461933114313_901345925_o.jpg

Edited by woodywood245
Added information for Sensor Reporter 1.4
Link to comment
Share on other sites

I'm getting values fine, but the toggle function doesn't seem to turn the sensors on. Using an action group gets the job done, though.

I wonder if there's a viable strategy for addressing two or more temperature sensors on the same craft. Parts in sunlight, or facing prograde with deadly re-entry will be different temperatures.

Link to comment
Share on other sites

I'm getting values fine, but the toggle function doesn't seem to turn the sensors on. Using an action group gets the job done, though.

I wonder if there's a viable strategy for addressing two or more temperature sensors on the same craft. Parts in sunlight, or facing prograde with deadly re-entry will be different temperatures.

To turn sensors on using toggle, try printing the result (which is always null).

print sensor:temp:toggle().
NULL

It's a crappy answer, I know, but it's a limitation of kOS. Void functions don't work well with kOS at the moment.

As far as addressing multiple sensors, it's something I've been thinking about for a while, but I have yet to come up with a solution. If I think of anything, I will definitely do something about it.

EDIT: This exact method no longer works in Sensor Reporter 1.3.2. Toggle functions now return a value, and you MUST use SET for toggle to work. Again, it's another quirk with kOS. The return value of the toggle method is the result of the toggle. If the sensor is turned on by the toggle, the result is true. If the sensor is turned off by the toggle, the result is false. If you don't use SET with the toggle, the toggle function will do nothing and return the current setting. I'm not sure why.


set bitbucket to sensor!temp!toggle().

Edited by woodywood245
Added info related to version 1.3.2.
Link to comment
Share on other sites

Sometime today (10/10/2013) I will be releasing an update for Sensor Reporter that will include several new functions, and provide a temporary fix for the eta:apoapsis/eta:periapsis math bugs.

Functions will include:

math:pi() - Returns a value containing the constant PI.

physics:gravconst() - Returns a value containing the gravitational constant.

vessel:velocity() - Returns a value containing the vessel's orbital velocity magnitude. This is to fix a bug in kOS that is preventing me from getting the magnitude of the orbital velocity vector.

Each of the above functions return a double-precision float, and included a ____f() version that returns a single-precision float for those with kOS 0.71 or earlier.

Also included will be:

eta:apoapsis() and eta:periapsis(). These will return double-precision floats and will work for comparisons and math operations.

NOTE: eta:apoapsis() and eta:periapsis() may change names, depending on whether or not they conflict in any way with the existing built-in properties.

Link to comment
Share on other sites

Spoke too soon. The sensors aren't recognized by the action group window in the VAB with the mod installed.

That's bizarre but not unexpected, as I'm still very new to making mods for this game, and official documentation is non-existant. I am looking into fixing this, but it will probably won't be fixed by today's release.

Link to comment
Share on other sites

  • 4 weeks later...
I installed this and the newest kOS but I always get unrecognized term 'sensor' what am I missing ?

I am aware of the issue, and I am going to release a patch today.

The new version of kOS uses a rebuilt expression system, which apparently uses colons as namespace operators for internal values. As a result, my existing namespace scheme doesn't work on kOS 0.9.

I am still fleshing out exactly what I want to change the colon to. I'm thinking an exclamation mark, but I could also use a pipe, or anything else, as long as it isn't an existing operator.

Link to comment
Share on other sites

I am aware of the issue, and I am going to release a patch today.

The new version of kOS uses a rebuilt expression system, which apparently uses colons as namespace operators for internal values. As a result, my existing namespace scheme doesn't work on kOS 0.9.

I am still fleshing out exactly what I want to change the colon to. I'm thinking an exclamation mark, but I could also use a pipe, or anything else, as long as it isn't an existing operator.

The patch has been released.

Link to comment
Share on other sites

Love this plugin! :D

I was wondering, I had an issue where math!pi() wouldn't output a number before I realized I needed a sensor installed on the ship for any functions to be recognized. Would it make more sense to tie those to the command pod, or maybe the to terminal itself?

Link to comment
Share on other sites

Love this plugin! :D

I was wondering, I had an issue where math!pi() wouldn't output a number before I realized I needed a sensor installed on the ship for any functions to be recognized. Would it make more sense to tie those to the command pod, or maybe the to terminal itself?

That's a great idea. I will implement that on the next update. I will tie it to kOS parts.

Link to comment
Share on other sites

I have yet to test to see if it works on the Hot Beverage Inc. sensor mod. If someone finds out before I change this, let me know.

I tried it today. I could not get it working, which is a pity. I do love this mod however, for now I can use a proper measurement when it comes to the gravity constant instead of a guestimate. Nice!

That's a great idea. I will implement that on the next update. I will tie it to kOS parts.

I personally like the idea of having to select your sensors. I would actually like more sensors for kOS. The trend to put everything in one part kind of goes against the idea of building your own, unique custom ships.

How Kerbal is it to build a beautiful craft with some awesome software, only to realize too late you forgot you thermometer at home :)

Edit: oh, it's for the math functions. I think I would not mind that, as long as the discrete sensors remain seperate.

Edited by Camacha
Link to comment
Share on other sites

I tried it today. I could not get it working, which is a pity. I do love this mod however, for now I can use a proper measurement when it comes to the gravity constant instead of a guestimate. Nice!

I personally like the idea of having to select your sensors. I would actually like more sensors for kOS. The trend to put everything in one part kind of goes against the idea of building your own, unique custom ships.

How Kerbal is it to build a beautiful craft with some awesome software, only to realize too late you forgot you thermometer at home :)

Edit: oh, it's for the math functions. I think I would not mind that, as long as the discrete sensors remain seperate.

Yes, I am separating the non-sensor functions and tying them to the computer part. I'm also adding a few new functions, one of which needs some additional testing: math!log(), math!logb(), math!ln(), math!e(), and vessel!isp(). The math!log() function returns the base-10 logarithm of a number, whereas math!logb() returns the logarithm of a number using the base you specify.

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...