Jump to content

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


Dunbaratu

Recommended Posts

2 minutes ago, fitemesquirrel said:

 

Ahhhhh. Okay, that makes a lot of sense considering what I was seeing. I didn't notice anything in the docs saying that so I didn't realize. I'll work with the raw and pilot control systems then. Thanks!

The most important command to remember - get used to typing it fast, is this:

set ship:control:neutralize to true.

Because unlike with lock steering, with raw control the controls don't unlock when the program ends.  If your program crashes, the controls are still set where you left them and it can be hard to recover manually.  Typing that line gets you the manual controls back.

 

Link to comment
Share on other sites

I am trying to write a script for a landing near a target on the ground. I want to make it so the ship changes inclination slightly in order to be (almost) directly over the target when the de-orbit burn starts. To do this in the way I am currently thinking of I would need to use something like positionat(ship,time), but for the target vehicle (because planet rotation). If I replace "ship" with "target", it returns a vector consisting of NaN. 

Anyway, on to the question. Is there something that will let me predict the position of a target vehicle after a certain amount of time? Or am I going to have to do loads of math to figure it out?

I really don't want to do any more math because I already did some calculus to derive the altitude for the (almost) perfect suicide burn.

Any info is appreciated. Thank you!

EDIT: Figured something out. Was able to 99% automatically land a ship within 1 km of its target on the Mun. The 1% being actually getting into a munar orbit in the first place! Further testing is required to see how versatile it is, but in theory it should work for any target anywhere on the moon (except if the target is directly on either pole) from any circular orbit that passes over the target with reasonable accuracy (the script fine tunes it) in a total of three burns. Changing some constants should allow it to work on any other non-atmospheric body as well. 

Edited by dafidge9898
Link to comment
Share on other sites

20 hours ago, infinite_monkey said:

I'm still trying to optimize my landing script. I want to limit my steering vector angle, so that VANG(vSteering, vRetrograde) is below a certain threshold. How can I achieve that? 

Use the abs function. Let's say you want to limit steering angle to (-20 deg, +20 deg). And lets call your steering angle ANG. So,

if (abs(ANG) < 20) then {steer as per ANG} else {steer with -20 or +20}

Link to comment
Share on other sites

23 hours ago, scimas said:

Use the abs function. Let's say you want to limit steering angle to (-20 deg, +20 deg). And lets call your steering angle ANG. So,

if (abs(ANG) < 20) then {steer as per ANG} else {steer with -20 or +20}

Yeah, but how do I say "steer x deg from vector va to vector vb"? I guess that's possible with the rotate functions somehow?

Link to comment
Share on other sites

3 hours ago, infinite_monkey said:

Yeah, but how do I say "steer x deg from vector va to vector vb"? I guess that's possible with the rotate functions somehow?

So you want to rotate one vector towards another by some angle? Yeah, the rotate functions probably can do it, I personally find them hard to understand sometimes. So you can figure them out for yourself and in the meantime use https://en.m.wikipedia.org/wiki/Rodrigues'_rotation_formula , which I find easier to use. 

Link to comment
Share on other sites

7 hours ago, infinite_monkey said:

Yeah, but how do I say "steer x deg from vector va to vector vb"? I guess that's possible with the rotate functions somehow?

A vector cross of the two vectors will give you an axis (as it'll be at 90 degrees to both input vectors) vector around which you can rotate (ANGLEAXIS function) va by X degrees towards vb. I have an example of this somewhere in my ascent code (to avoid straying too far from surface prograde) if you'd like code to look at. The hard part is working out which way around things are to avoid going the wrong way... partly as KSP/Unity's coordinates are left-handed.

 

Edit to add a link: https://github.com/ElWanderer/kOS_scripts/blob/f5e22ce98925976497ee9acc5216c56c4f7d8372/scripts/lib_launch_common.ks#L345

Edited by ElWanderer
Link to comment
Share on other sites

Yep, it's done!
Well, pretty much. Everything I want the autopilot to be able to do is now working properly. Features right now are:
- Hold altitude, pitch or heading
- land at any given airport, no matter the runways heading
- create and fly custom flight routes with different waypoints

I might look into creating a custom GUI for it, and I'll think about releasing the script.

Don't know why the sound is offset from the video though :/

Edited by Kartoffelkuchen
Link to comment
Share on other sites

2 hours ago, Kartoffelkuchen said:

Yep, it's done!
Well, pretty much. Everything I want the autopilot to be able to do is now working properly. Features right now are:
- Hold altitude, pitch or heading
- land at any given airport, no matter the runways heading
- create and fly custom flight routes with different waypoints

I might look into creating a custom GUI for it, and I'll think about releasing the script.

Don't know why the sound is offset from the video though :/

 

I for one would be interested in seeing this script, for reference on how you did certain things here.

Link to comment
Share on other sites

  • 3 weeks later...

Getting back into kOS after, I dunno maybe 4 years. I'm playing on a 10+ year old laptop, and have a 1+ y/o daughter now, and on several occasions due to the lag of the laptop and my attention being on my daughter I look back at the laptop to realize my rocket is still going straight up with 2 or 4 empty boosters still attached...lol

Once upon a time I had a script that would launch 3 comm sats into orbit while managing throttle to make best use of fuel/oxidizer. I had the script so I could set the desired altitude when I ran the script, the number of paired asparagus stages etc and it would calculate the needed PE to get equally spaced sat deployments. I think I had it deploy each sat as the carrier ship came around to the AP each time. Of course the limitation of the game made it so I had to manually switch to the deployed sat and run the circulation program, but other than that it was all automated.

Of course now I don't know where that script went. Checked backups on my network drive and found some older, not so useful scripts. It may be on my desktop (older linux build, have been to lazy to backup and update it) or maybe on my old  laptop hard drive. If i can't find it I guess I'll have to start from scratch, which may not be such a bad idea considering the changes since the last time I used it. :)

 

[EDIT]

Pretty sure I found my old scripts, they were for KSP 1.0.4. Just for fun I think I'll try it out and see if it still works at all. Though I highly doubt it. :)

 

Amazingly my old scripts still work. Well, I've only tried one that puts things in orbit, not the one for deploying sats equally spaced. It needed a little editing, and its not entirely efficient or accurate, but it gets the job done.

Edited by Sma
Found my old scripts. :)
Link to comment
Share on other sites

6 hours ago, Sma said:

Pretty sure I found my old scripts, they were for KSP 1.0.4. Just for fun I think I'll try it out and see if it still works at all. Though I highly doubt it. :)

 

Amazingly my old scripts still work. Well, I've only tried one that puts things in orbit, not the one for deploying sats equally spaced. It needed a little editing, and its not entirely efficient or accurate, but it gets the job done.

What a great piece of software that changes from time to time under the hood, but doesn't break 'saves' :)

Stellar work kOS team.  Thank you for your ongoing work!

Peace.

Link to comment
Share on other sites

12 hours ago, garwel said:

How do I use a quote mark (i.e. " symbol) in a string? I tried escaping it with a backslash or with doubling it, but it doesn't seem to work. I haven't found it in the documentation.

CHAR(34), but you'll need to append it to the string.

e.g. SET myString to "He said " + CHAR(34) + "no" + CHAR(34).

That'll set myString to 'He said "no"'

Link to comment
Share on other sites

Ok, I have another question. I'm trying to write a script for docking two kOS-controlled vessels and I need to look at the other vessel's parts, specifically its docking ports to find eligible one(s).

I tried this:

LIST DOCKINGPORTS FROM TARGET IN targetPorts.

and this:

LIST TARGET:DOCKINGPORTS IN targetPorts.

But both cause a syntax error for the FROM keyword (in the first case) or the colon character (in the seconds case). The same statement for the current vessel appears to work ok.

What am I doing wrong and how do I loop through target vessel's ports?

Link to comment
Share on other sites

52 minutes ago, garwel said:

Ok, I have another question. I'm trying to write a script for docking two kOS-controlled vessels and I need to look at the other vessel's parts, specifically its docking ports to find eligible one(s).

I tried this:


LIST DOCKINGPORTS FROM TARGET IN targetPorts.

and this:


LIST TARGET:DOCKINGPORTS IN targetPorts.

But both cause a syntax error for the FROM keyword (in the first case) or the colon character (in the seconds case). The same statement for the current vessel appears to work ok.

What am I doing wrong and how do I loop through target vessel's ports?

The LIST ... IN form only works for a few, pre-programmed cases. Any ship object has a DOCKINGPORTS suffix that returns a list of ports. To loop through them, do something like:

FOR p IN TARGET:DOCKINGPORTS { // do something with each p. }

Link to comment
Share on other sites

Great, thanks. I had this idea too, but haven't tested it yet.

It looks like the documentation is incorrect on this issue then. This page mentions DockingPorts as well as other suffixes as "listable keywords" that can be used with LIST ... IN command.

Link to comment
Share on other sites

10 hours ago, garwel said:

Great, thanks. I had this idea too, but haven't tested it yet.

It looks like the documentation is incorrect on this issue then. This page mentions DockingPorts as well as other suffixes as "listable keywords" that can be used with LIST ... IN command.

Does LIST DOCKINGPORTS IN someListVariable work? That's all that page is talking about, I think, and will only get you the ports for the active vessel. To get the ports for another vessel, you can't use that format.

Edited by ElWanderer
Link to comment
Share on other sites

I find the kOS_v.1.1.5.0_for_KSP_1.3.1 didn't work with InfernalRobotics_3.0.0_beta3_p7_for_KSP_1.3.1.
When I check ADDONS:IR:AVAILABLE, the result is FALSE.
Have you the plan to repair this problem in next kOS version?
Thanks.

Link to comment
Share on other sites

  • 2 weeks later...
  • 2 weeks later...

Hi.

Not sure where to post feedback/suggestions, but there's a really really simple thing that's bugging me a bit: For calculating certain aspects of spaceflight, most equations are written with "total distance to center of mass" variables, not "distance to surface" variables. So for example, if I'm using the Vis-Viva equation to calculate orbital speed at a point in my orbit, one of my variables is going to be the distance between that point and the center of mass/gravity" of whatever planet I'm orbiting. However there's no simple method in kOS scripts to invoke this number. For example, if I'm trying to calculate what the vessel speed will be at apoapsis, to obtain the true distance between apoapsis and the center of gravity of what I'm orbiting I need to get body:radius and either ship:apoapsis or orbit:apoapsis, add those two into a new variable, and THEN proceed with the calculations.

Implementing an item in one of the structures so you could do something like "orbit:trueapoapsis" to get the true distance from the center of gravity would be a tiny yet very noticeable improvement, allowing koders to save some lines of code and not have to get two values separately and then sum them into a new variable.

 

There are many possible ways this could be implemented. Off the top of my head I can think of two distinct ones:

 

- make it so orbit:apoapsis returns the actual total distance to the center of gravity of the currently orbited body, while ship:apoapsis returns distance from apoapsis to surface. It's probably the "cleanest" option but might break a lot of code for a lot of people, which brings me to option 2

 

- make a new suffix under the ORBIT structure called something like "trueapoapsis" or "total apoapsis", so that the total distance can be gotten directly from it. (I keep mentioning apoapsis, but the implication is that something similar would be done for periapsis)

 

 

Other than that, can't really think of anything else. Loving kOS despite being very new to it. Keep it up!

Edited by Deimos_F
Link to comment
Share on other sites

35 minutes ago, Deimos_F said:

"total distance to center of mass"

body:position:mag

Ok, it actually would be  (body:position-ship:position):mag , but the reference point typically is the active vessel

Edited by Alchemist
Link to comment
Share on other sites

1 minute ago, Alchemist said:

body:position:magnitude

Ok, it actually would be  (body:position-ship:position):magnitude , but the reference point typically is the active vessel

 

Do you mean body:geoposition? There's no "position" suffix for the "body" structure in the manual.

 

And either way, this solution still involves invoking two different values and performing an operation to get a third value out of them. Not to mention this only works for the current position, not the more useful Apoapsis or Periapsis positions, frequently used in orbital math.

Link to comment
Share on other sites

10 minutes ago, Deimos_F said:

Do you mean body:geoposition? There's no "position" suffix for the "body" structure in the manual.

There is such suffix, it's inherited from Orbitable. Ant it's the position of center of mass.

But yes, there is no such option for apoapsis or periapsis. So you'll have to add the radius if you need them this way

 

Edited by Alchemist
Link to comment
Share on other sites

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