Jump to content

[KSP 1.12.x] kOS v1.4.0.0: kOS Scriptable Autopilot System


Dunbaratu

Recommended Posts

Yeah I do need to have a major tidy up of the code.  First time I've ever used RCS in KOS so I'm calculating distances and speeds in Fore/Top/Star directions and then looping through all 6 directions to apply corrections, with each of those loops doing all the vector calculations as I shoved them all in one function to make my life easy... paperbag.gif

I should be able to simplify that a fair bit now I've got a vague idea what I'm doing.  I'm hoping i can do all directions at once with ship:control:translation.  Presumably if I can do the loop within a physics tick should have no problem?  approach could also be a bit slower, think it's hitting at about 0.5m/s at the moment, I'd probably be slower than that if I was docking manually.

 

Link to comment
Share on other sites

To check if the ship has docked, I use ship:parts:length.  When the count goes up, that it docked with the other ship and added new parts to itself.

When using RCS with a PID loop, be aware of this fact that I discovered the hard way:

KSP imposes a 5% null zone on RCS translation.  If you do:
 

set ship:control:top to 0.05.

it will have the same effect as:

set ship:control:top to 0.0.

you have to set it to at least 0.050001 for it to do anything.

This is something KSP is imposing that we didn't know about before.  And it can confuse a PID controller that doesn't realize it's requested controls aren't being obeyed when it tells you "please set control to 0.04" and it's actually getting a zero.

 

Link to comment
Share on other sites

10 hours ago, Steven Mading said:

When using RCS with a PID loop, be aware of this fact that I discovered the hard way:

KSP imposes a 5% null zone on RCS translation.

That's a weird "feature"

At the moment I'm using RCS on full power and controlling the thrust by how long it burns, ie the same way I would if controlling it manually, so not run in that, yet, but thrust based rather than time based might result in tidier code so I'll bear it in mind.

Link to comment
Share on other sites

Is there anything else weird with this 200m parts and targeting thing?  I seem to be getting the target in the wrong place even when targeting the ship rather than the port.

Relevantly section of scrip, which is in a loop so constantly updating:

	set target to "Agena".
	set TgtVector to vecdrawargs(V(0,0,0),target:position,blue,"Target",1,true).

Which I would expect to draw a line direct to the target ship.  Instead it does this beyond 200m, but changes to the expected location inside 200m.

IlTwN4C.png

I am on my old PC using ksp 1.4.5 and I think KOS 1.1.5.2, so possible it's an old problem that's been fixed, or a KSP issue with known workaround.

Edited by RizzoTheRat
Link to comment
Share on other sites

34 minutes ago, RizzoTheRat said:

IlTwN4C.png

Test where center of mass is on the target ship.  One way is to take control of the target ship and rotate it to see where the pivot point of rotation is (that will be CoM).

When targetting the whole ship, the game's UI highlights where the control point is.  When picking the position of the ship, kOS uses its CoM.  If you have a really long part, the center of mass could be quite far from the control point.

This is one of those things that if we had the luxury of redesigning kOS from the ground up without any legacy backward compatibility support to deal with, I'd probably have liked to see changed.  I'd choose the control part as the ship's position, and make the ship's CoM be an optional suffix call you can make if you want to know that.

Link to comment
Share on other sites

The target ship is only 3 or 4 meters long,  while the offset looks to be 200 or so.   I wondered if it gives an approximate location when you're further away,  but it draws the target in the right place and updates when 200m away so must know where it is. 

Link to comment
Share on other sites

1 hour ago, RizzoTheRat said:

The target ship is only 3 or 4 meters long,  while the offset looks to be 200 or so.   I wondered if it gives an approximate location when you're further away,  but it draws the target in the right place and updates when 200m away so must know where it is. 

This weirdness rings a bell, but I may be thinking of something else. I could've sworn I read once that the other ships' positions are not calculated super-accurately until you get close enough to them, which can cause them to appear to jump. Will have to Google it.

Edit: first Google result:

Are you using time warp?

Edited by ElWanderer
Link to comment
Share on other sites

3 hours ago, RizzoTheRat said:

The target ship is only 3 or 4 meters long,  while the offset looks to be 200 or so.   I wondered if it gives an approximate location when you're further away,  but it draws the target in the right place and updates when 200m away so must know where it is. 

You can target a port only wen its closer then 200m in vanilla ksp

This can be a limiting factor for kos

Link to comment
Share on other sites

Well this is odd.  Fired it up on my other machine with KOS 1.1.6.2 and  KSP 1.6.1 and  I have the following code as the only thing that's running

clearscreen.
set target to "Agena".
until target:position:mag < 20{
	print "distance : " + target:position:mag + "   " at (0,20).
}

Save game loads with the active vessel a little way away from from Agena, with a relative velocity of 0.3m/s.  Both vessels are shorter than an FL-T800 tank and I'm not in time warp.

The yellow target marker is showing 524.9m, the terminal display is showing  495.9.

Close to 200 on the target marker and the terminal display jumps from 180 to 200, so it's getting slightly more accurate as I get closer and then jumping when I get inside 200m. Still a slight error, I've paused it at 197.9 on the target marker and 200.5 on the terminal but I assume that's the difference between CoM and Command module measurement.

Go past the target and back out beyond the 200m distance and the terminal is still reporting the correct distance.

 

SeMNbv7.png

Target ship is a similar to the active one in the foreground.

Link to comment
Share on other sites

1 hour ago, scimas said:

@Steven Mading see if this is relevant to the problem being described https://github.com/mockingbirdnest/Principia/issues/1416 ? It probably isn't, considering kos doesn't make direct changes to ship's position or velocity, but that is what immediately came to mind when I read the discussion. 

Actually that sounds like exactly the problem.  Probably the reason the targeting is only allowed within 200m is that this is the "pack" distance the game uses for parts to become fully functional.  There's probably lots of other things the this 200m distance effects since its the range at which the ship changes from packed to unpacked.

New release:

The only difference in this release is an update to Folder Protection (keeping scripts from escaping the Ships/Script folder).

# v1.1.6.3 Folder Path Protection                                                                                                                                 

Built for KSP 1.6.1                                                                                                                                               

This is a patch for protecting against some kinds of file folder access that concerned us for those people using kOS to set up "Twitch Plays kOS" streams.                                                                                                                                       

Although we try to block a kerboscript's ability to access files outside the ``Ships/Script/`` folder, we cannot (and *will not*) guarantee to have thought of every trick a clever person might come up with to fool the system into allowing access.  As always, be wary that if you allow any random arbitrary person to run scripts (in any system, in any language, really) on your own computer that you have not read through and vetted yourself, that you are doing this at your own risk.

### BUG FIX:

If you currently have a "Twitch Plays kOS" stream, or plan to set up one in the future, PLEASE see this writeup:                                                                                                                     

* https://github.com/KSP-KOS/KOS/issues/2439

Get it at the usual places (see first post of the thread).

Many thanks to @lucaelinfor doing the majority of the legwork on this problem.

Edited by Steven Mading
Link to comment
Share on other sites

2 hours ago, Steven Mading said:

Built for KSP 1.6.1                                                                                                                                               

This is a patch for protecting against some kinds of file folder access that concerned us for those people using kOS to set up "Twitch Plays kOS" streams.                                                                                                                                       

Although we try to block a kerboscript's ability to access files outside the ``Ships/Script/`` folder, we cannot (and *will not*) guarantee to have thought of every trick a clever person might come up with to fool the system into allowing access.  As always, be wary that if you allow any random arbitrary person to run scripts (in any system, in any language, really) on your own computer that you have not read through and vetted yourself, that you are doing this at your own risk.

### BUG FIX:

If you currently have a "Twitch Plays kOS" stream, or plan to set up one in the future, PLEASE see this writeup:                                                                                                                     

* https://github.com/KSP-KOS/KOS/issues/2439

This is important. You should add a line or two about it in the first post.

I was naive enough to think that kOS would not be able to do any harm outside of KSP. There are potentially a lot of people like me who thought the worst thing that could happen with a kOS script was a the game crashing. Perhaps a link to, or an explanation, how people can set up a VM to do "Twitch Plays kOS" stream safely would be nice to add in the docs or the first post.

Link to comment
Share on other sites

6 hours ago, scimas said:

@Steven Mading see if this is relevant to the problem being described https://github.com/mockingbirdnest/Principia/issues/1416 ? It probably isn't, considering kos doesn't make direct changes to ship's position or velocity, but that is what immediately came to mind when I read the discussion. 

Reading that and the other one it links to it does sound like its the issue (and the same thing El Wanderer suggested earlier, but wider than the just time warp).  I guess once it's unpacked it doesn't re-pack it until some distance well beyond the 200m mark so in theory I could increase the unpack distance so it draws in the right place, and then decrease it again, although this might be Kraken bait as I gather the further away you unpack the more chance you have or errors being big enough for parts to collide. 

Probably easier to just close to <200m and then manoeuvre rather than aiming for the docking port from further out.

Edited by RizzoTheRat
Link to comment
Share on other sites

9 hours ago, MaltYebisu said:

This is important. You should add a line or two about it in the first post.

I was naive enough to think that kOS would not be able to do any harm outside of KSP. There are potentially a lot of people like me who thought the worst thing that could happen with a kOS script was a the game crashing. Perhaps a link to, or an explanation, how people can set up a VM to do "Twitch Plays kOS" stream safely would be nice to add in the docs or the first post.

It's a kind of long involved admin thing.  Maybe if we can find a webpage that gives a summary we can link to that.  My concern with giving a step by step instruction is:

1 - It's different for each OS platform, multiplying the complexity of the documentation.

2 - Just like with assuming we sanitized every input perfectly to avoid the issue, if we assume we covered every problem in our setup instructions, once we declare "do these things and it protects you", we will open ourselves up to accusations its our fault if someone gets hacked because our instructions missed a step.  Giving out security instructions when you're not a security expert is like giving out legal advice when you're not a lawyer.  Generally it's better to say, "Don't take my word for it - the onus is on you."

Link to comment
Share on other sites

doesn't this have the  "this software is provided as is and if something happens not our fault" disclaimer? 

BTW is there a possibility of having something like apt-get for kos where you could have a repository of user submitted scripts or is that just a web page that already exists?

Link to comment
Share on other sites

1 hour ago, lunardog15 said:

BTW is there a possibility of having something like apt-get for kos where you could have a repository of user submitted scripts or is that just a web page that already exists?

That would be a lot of work.  It's not impossible - just that it's enough work to detract from time spent on the mod itself.  It's the sort of thing that would be better to take up by someone else not working on kOS itself.

Link to comment
Share on other sites

I'm trying to make use of CraftTemplate:FILEPATH but I get suffix not found?  I hadn't tried using it before.  Is this a new problem related to the latest release?

For my test vessel "aaa 3.1" which is in "aaa 3_1.craft" and also for "aaa" which is "aaa.craft"

This works:

PRINT KUNIVERSE:GETCRAFT(SHIP:NAME, KUNIVERSE:ORIGINEDITOR).

This doesn't:

PRINT KUNIVERSE:GETCRAFT(SHIP:NAME, KUNIVERSE:ORIGINEDITOR):FILEPATH.

In any event, I was just looking for an escaped name to save a log file as, so don't need the whole path.

Link to comment
Share on other sites

1 hour ago, Devoblue said:

I'm trying to make use of CraftTemplate:FILEPATH but I get suffix not found?  I hadn't tried using it before.  Is this a new problem related to the latest release?

For my test vessel "aaa 3.1" which is in "aaa 3_1.craft" and also for "aaa" which is "aaa.craft"

This works:

PRINT KUNIVERSE:GETCRAFT(SHIP:NAME, KUNIVERSE:ORIGINEDITOR).

This doesn't:

PRINT KUNIVERSE:GETCRAFT(SHIP:NAME, KUNIVERSE:ORIGINEDITOR):FILEPATH.

In any event, I was just looking for an escaped name to save a log file as, so don't need the whole path.

I don't see that suffix in the documentation for a craft template:

https://ksp-kos.github.io/KOS/structures/vessels/crafttemplate.html#structure:CRAFTTEMPLATE

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