Jump to content

[1.3] kOS Scriptable Autopilot System v1.1.3.0


erendrake

Recommended Posts

  On 12/3/2016 at 6:10 AM, Waz said:

So, for consistency, STRING:ISNUMBER?

Expand  

Yeah I had that idea as I was editing my previous response.

I was reluctant because it means pointlessly doing the work of parsing the string to a number twice.  (That's also one of my arguments for why nulls are superior to having all these HASwhatever suffixes all over... grumble grumble.... doing the work to find out *if* a value is obtainable usually means doing the work to attempt to obtain the value and then noticing it failed, so testing first with HASwhatever, followed by then getting the value, ends up repeating that work pointlessly).  But it's now such a deeply embedded design decision that I'm reluctant to go back and change it.

But at any rate, efficiency isn't exactly a big deal with kOS.  We're so many layers removed from the raw hardware anyway  that parsing a string to number twice instead of once is probably not that big a deal, so we can probably add ISNUMBER.

 

Link to comment
Share on other sites

Alpha8 of the GUI is up. I've been slowly tweaking the API for best usability, but still keen to here anything you feel is awkward or strange.

Specifically, STYLE:BG_FOCUSED is now STYLE:FOCUSED:BG and there is also STYLE:FOCUSED:TEXTCOLOR (and the same for ACTIVE, NORMAL, HOVER, etc.).

This release also includes a tutorial on making a self-contained TabWidget (see the GameData/kOS/html directory), and minor bugfixes for radiobuttons over comm delay.

https://github.com/WazWaz/KOS/releases/

Edited by Waz
Link to comment
Share on other sites

  On 12/3/2016 at 6:13 AM, hvacengi said:

Or we could expose a way to get a "max scalar", since you can probably reliably know that you won't overflow the double precision floating point number, and if you do you'll break all the math in kOS anyways.

Expand  

Exposing max and min numbers probably isn't such a bad idea.  They make good sentinel values for other purposes.

 

Link to comment
Share on other sites

  On 12/3/2016 at 6:07 AM, Steven Mading said:

 

I suppose we could extend the HASwhatever model and introduce a means to query if the string *would* be translatable to a number without actually returning that number.  String:ISNUMBER or something like that.

Expand  

I proposed additional suffix to check if string have valid number or not in first post where I discovered need for conversion of string to number.

It was possible for me to change kOS function for conversion string to scalar because kOS accept any kind of data to be assigned to varable.
Doing that trough C# is probably bad idea, so additional suffix ISNUMBER or HASNUMBER, whatever you think is better to call it to fit with other keywords used in kOS, would be much better. Simple true/false value is sufficient with it.

It is not absolutely need, but it will be good if such thing can be extended to expressions. Probably a lot harder than with string conversion, but once it is included in string we could use something like this:

set MyScalar to 0.
if MyScalar:ISNUMBER(1/0) = true then
{
	print "Expression is valid number".
}
else
{
	print "Expression does not return number".
}.

That could possibly cover all needs to check out does it something NaN or not. User than can use that info in code to deal something in one way or another.

defaultError value to return from Mystring:TONUMBER(defaultError) can stay like it is, it could be useful in some situations to "reset" values to some defaults in cases of error.

Link to comment
Share on other sites

  On 12/3/2016 at 10:49 PM, TK-421 said:

In Galileo's planet pack, there is a moon named Eta. This makes the eta alias unusable.

Expand  

This was noticed just the other day, and there is already a fix in the works.  There is no work around however until that gets merged.  But it should be in the next release (which we keep saying will be "soon", but I think it really be soon). https://github.com/KSP-KOS/KOS/issues/1887

Link to comment
Share on other sites

I have what is probably a stupid question....

Using 1.0.2-pre2, I did the traditional "copy scriptname from 0." and while this worked, I got a warning saying the syntax had changed.  Now I'm supposed to do this:

"copypath(0:/"scriptname")

Egad, that's difficult to type quickly, requiring actual thought, which breaks the mood when I'm "in the zone" coding.  Not a fan but I guess I'll have to live with it.

HOWEVER, next time I ran kOS, I tried doing it the new way to get in the habit, and then I tried all permutations of quotes or not and their positions, and all sorts of other variations on the above theme, and NONE of them worked.  

So what am I doing wrong?  Has this change not really taken effect yet?  Or is there some trick to getting the proper syntax?  Do you really need the quotes?

Thanks.

 

Link to comment
Share on other sites

  On 12/4/2016 at 4:29 PM, Geschosskopf said:

I have what is probably a stupid question....

Using 1.0.2-pre2, I did the traditional "copy scriptname from 0." and while this worked, I got a warning saying the syntax had changed.  Now I'm supposed to do this:

"copypath(0:/"scriptname")

HOWEVER, next time I ran kOS, I tried doing it the new way to get in the habit, and then I tried all permutations of quotes or not and their positions, and all sorts of other variations on the above theme, and NONE of them worked.  

So what am I doing wrong? 

 

Expand  

I was wandering by myself too with new stuff. Asked same thing here. Found answer by myself on page 185 of this thread.

Anyhow, you missing destination parameter. Assuming you have opened desired kOS CPU and you have switched archive to local kOS CPU you need to do this:

 

copypath("0:/scriptname","").

That will copy desired script from permanent archive to local CPU. Of course, if you have more than one kOS CPU, you can be more specific and add full path to destination archive like this:

copypath("0:/scriptname","2:/script_changed_name").

In your example you have missplaced begining doublequote.

I ended up creating task specific bootscripts that copy desired files on launch and when in flight, you only need to run desired script if it is not already set to autorun. Like this:

// Example 1
runpath("MyScript_with_parameters",90,20000).

// Example 2
runpath("MyScript_no_parameters").

// Example 3 - legacy command when no parameters required

run MyScript_no_parameters.

 

Edited by kcs123
Link to comment
Share on other sites

@hvacengi and @Waz,  I was able to create another kOS interpretrer breaking script. Alpha8 with GUI fork is used. I don't think that is releated with GUI stuff as I was having similar even without usage of GUI

Here is how script look like:

  Reveal hidden contents

"lib_navball" and "lib_circle_nav" were taken from kOS library on github. I was just started to build Rover autopilot script with GUI.
Current state work just fine, for debug purposes I added commands on AG4 to start rover. It holds throttle properly, but steering is not locked at all.

As soon as I unlock one "ON AutopilotRB_Drive:PRESSED" block ore any other, or even put some more commands on AG4 event, kOS interpreter breaks with same error as previously reported - not enough parameters.

I can't figure out what I wrote inside script that breaks kOS interpreter. I was using notepad++ for script writing, file is saved as UTF8 without BOM. If any of those info is relevant. This script is realy most simple as it could be, I just started to build GUI and possible rover driving modes when it started to break, so it is almost impossible to continue with it.

Edited by kcs123
Link to comment
Share on other sites

  On 12/4/2016 at 8:41 PM, kcs123 said:

I can't figure out what I wrote inside script that breaks kOS interpreter. I was using notepad++ for script writing, file is saved as UTF8 without BOM. If any of those info is relevant. This script is realy most simple as it could be, I just started to build GUI and possible rover driving modes when it started to break, so it is almost impossible to continue with it.

Expand  

You really can't simplify it any further than that? The first step to tracking down problems is to remove stuff which doesn't matter to the error. It's far better that you do that than me, because it might turn out to be a problem in your code, or in kOS (I'm sure in this case it is in kOS, but a simpler example of the problem is a lot easier to process). You should also show the actual error message you are getting, and logs (especially if you submit it as an Issue on the github).

Link to comment
Share on other sites

  On 12/4/2016 at 9:39 PM, Waz said:

You really can't simplify it any further than that? The first step to tracking down problems is to remove stuff which doesn't matter to the error. It's far better that you do that than me, because it might turn out to be a problem in your code, or in kOS (I'm sure in this case it is in kOS, but a simpler example of the problem is a lot easier to process). You should also show the actual error message you are getting, and logs (especially if you submit it as an Issue on the github).

Expand  

Troubleshooting as well as reporting. Managed to create even more simple script, without GUI at all. I was just about to create more convinient outputlog. Starting game, loading savegame point, switching to rover on Mun and try to run script.

Here is more simple script that produce described error as before:

  Reveal hidden contents

And give me couple of more minutes to upload log, script and savegame file.

EDIT:

Here is link for required archive with log, script and savegame file. Under spoiler is relevant part of log.

  Reveal hidden contents

 

Edited by kcs123
Link to comment
Share on other sites

  On 12/4/2016 at 10:04 PM, kcs123 said:

Troubleshooting as well as reporting. Managed to create even more simple script, without GUI at all. I was just about to create more convinient outputlog. Starting game, loading savegame point, switching to rover on Mun and try to run script.

 

 

Expand  

There's some bugs we just found just a couple of weeks ago with using one of the four cooked steering locks (throttle, steering, wheelthrottle, wheelsteering) from inside a trigger like ON or WHEN, if those locks exactly match the same expression used elsewhere for the same variable.

In other words, if you do a Lock Steering To 0 in two places, one of which is in a trigger, that's the sort of thing that makes the bug occur.

It works as long as the expressions differ.

It's confusing the mechanism the compiler uses to identify unique functions by their compile hash signature. 

There's a fix in the works, but in the meantime just do Lock [whatever] to MyVariable once up at the top, and then use Set MyVariable to whatever in the trigger code (don't re-run the lock statement there).

Link to comment
Share on other sites

  On 12/4/2016 at 8:41 PM, kcs123 said:

As soon as I unlock one "ON AutopilotRB_Drive:PRESSED" block ore any other, or even put some more commands on AG4 event, kOS interpreter breaks with same error as previously reported - not enough parameters.

Expand  
  On 12/4/2016 at 11:16 PM, Steven Mading said:

In other words, if you do a Lock Steering To 0 in two places, one of which is in a trigger, that's the sort of thing that makes the bug occur.

Expand  

I ran the attached scripts with the debugger, and there is indeed a different error in this instance.  1st, the notable error isn't the "declare parameter" error, instead it's a "replace label" error.  2nd, it isn't a problem with steering locks but rather with an attempt to "unlock all", which is trying to set the user function "dislplay_block" to a default value (which doesn't exist, because functions don't have default value and they should be unlocked).  I'll try to find some additional detail and post to github.  I honestly didn't know that unlock all was still valid.

 

Link to comment
Share on other sites

Thanks for clarification, I will try to change whole script in different manner to make workaround of this until proper fix is provided.
How (un)lucky I am, I will probably brake something else :)

 

Link to comment
Share on other sites

  On 12/5/2016 at 3:31 PM, kcs123 said:

Thanks for clarification, I will try to change whole script in different manner to make workaround of this until proper fix is provided.
How (un)lucky I am, I will probably brake something else :)

Expand  

As long as you don't call "unlock" of any kind from within a trigger ("on" or "when") you should be fine.

Link to comment
Share on other sites

  On 12/5/2016 at 4:08 PM, hvacengi said:

As long as you don't call "unlock" of any kind from within a trigger ("on" or "when") you should be fine.

Expand  

I just thinking of creating workaround with additional variable in ON / WHEN events. For example, like this:

set terminate to false.
set done to false.
set MyHeading to 270.
  
ON AG4 {
  if done = false {
    set done to true.
    // unlock will be done inside until loop
  } else
  {
    set done to false.
    lock wheelsteering to MyHeading.
  }.
  preserve.
}.
  
ON AG5 {
  set MyHeading to SomeOtherValue.
  preserve.
}.

// main part of script to run in endless loop
until terminate = true {
  // main part of script to do something here
  
  if done = true {
    // part of code outside of trigger that will return command to pilot
    unlock wheelsteering.
  }.
}.

Have yet to try iin game to see how it will work or it will break something. Or I will just have to break script with CTRL +C and run another script to unlock pilot commands on demand.

Link to comment
Share on other sites

  On 12/5/2016 at 5:51 PM, kcs123 said:

Have yet to try iin game to see how it will work or it will break something. Or I will just have to break script with CTRL +C and run another script to unlock pilot commands on demand.

Expand  

In theory, as long as the unlock statement isn't within the triger's "{ }" braces, it should work fine.  So you should be able to use a user function to call unlock instead.

Link to comment
Share on other sites

  On 12/6/2016 at 10:40 AM, danielboro said:

i get a black screen and wait forever on KAC jump to ship

https://www.dropbox.com/s/620ivaeiv0gr1j4/kspKACjumpfreez.log?dl=0

this is the last lines of the ksp.log i see KOS there alot so i mentioning it hir

Expand  

I would need to see the full log in order to tell anything.  From the portion you have shown, I don't see any errors with kOS.  You're right, there are a large number of kOS messages, but that should be normal if you have a large number of vessels in flight (KSP is set up so that it destroys and re-creates vessel modules on every scene change, our logging is there for tracking the life cycle of the vessel module).  If KSP is hanging though, it is possible that the last few log messages are not getting written to the log file.  I'll see if I can find some time to install KAC and check out the feature myself.

Link to comment
Share on other sites

Hey everyone, while writing a script I noticed that it's not possible to take the output of the steering manager's Torque PID (does not change ship:control:pitch and directly controls the steering). So I attempted to write one myself based on the output of the Rotational Velocity PID. According to this the output should be the desired rotational velocity. However this only gives me an extremely low number (~10^-17). Am I misinterpreting it or is that just what it does and it has to be multiplied by 10^17 before it can be used?

Link to comment
Share on other sites

  On 12/6/2016 at 3:02 PM, EmbersArc said:

Hey everyone, while writing a script I noticed that it's not possible to take the output of the steering manager's Torque PID (does not change ship:control:pitch and directly controls the steering). So I attempted to write one myself based on the output of the Rotational Velocity PID. According to this the output should be the desired rotational velocity. However this only gives me an extremely low number (~10^-17). Am I misinterpreting it or is that just what it does and it has to be multiplied by 10^17 before it can be used?

Expand  

I'm not sure if I understand properly, but you want to create your own custom pair of PIDs for raw control, right ?

If that is case, then you can't use readings from cooked control steeringmanager. Cooked controled steering manager need to be active (PID that it use) so readings from steering manager can provide sane values.

What you need is readings from vesel properties and based on that use data to feed input of nested PID that set final raw control.

You probably want to use angular momentum or angular velocity for intermediate data. You have to put in consideration that those are vcectors, so you should need to do some math, relative to ship facing vector to get desired values for each axis: pitch, yaw,roll. Might be even enough to use vector X,Y,Z data. I have also to remind myself of orientation of vectors used in KSP, does that represent absolute vector in KSP universe, or it is relative to ship facing, so I can't give you exact answer on that.

I did similar thing for altitude based hovering script. First PID use desired Altitude setpoint and gives output in vertical velocity in range -10,+10. Output for that one is used to feed throttle PID that set engine trottle between ranges 0,+1.

 

Link to comment
Share on other sites

  On 12/6/2016 at 3:02 PM, EmbersArc said:

Hey everyone, while writing a script I noticed that it's not possible to take the output of the steering manager's Torque PID (does not change ship:control:pitch and directly controls the steering). So I attempted to write one myself based on the output of the Rotational Velocity PID. According to this the output should be the desired rotational velocity. However this only gives me an extremely low number (~10^-17). Am I misinterpreting it or is that just what it does and it has to be multiplied by 10^17 before it can be used?

Expand  

What are you trying to do with the output from the Torque PID?  I have a suffix for "actuation" on the structure, but it's only enabled for debugging mode.  It simply returns a vector of the [-1...1] control output of the steering manager.  I don't see why we couldn't move that to be user accessible if you need it for something.  I didn't expose it initially because I can't think of a reason outside of debugging that it would be needed.

@kcs123 is right, the rotational velocity PID won't update unless steering is locked.  Even then, you can't get a good idea of the torque applied because it depends on available torque and moment of inertia, neither of which are exposed to the user.

Link to comment
Share on other sites

@kcs123, @hvacengi thanks! I'm trying to make a script to use differential throttling to control a Dragon v2 capsule for a point landing. I thought there might be a way to just tune the steering manager and use its output to adjust the thrust limit on the individual engines. Access to the output might or might not be helpful for that, just thought I'd try that first. It even somewhat works with the output from the rotational velocity PID but it's not very elegant. It looks like the best way is to make it from scratch after all.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...