Steven Mading

[1.7.3] kOS v1.1.9.0 : kOS Scriptable Autopilot System

Recommended Posts

Posted (edited)

ok here's what more testing has shown. I added the following code to my ascent.ks script:

function pitchErrMonitor {
  if steeringManager:pitcherror > 1 {
    unlock steering.
    set ship:control:pitch to 0.9.
    output("Bumping pitch controls").
    operations:remove("pitchErrMonitor").
    sleep("resetSteering", resetSteering@, 1, true, false).
  }
}

function resetSteering {
  operations:remove("resetSteering").
  set ship:control:pitch to 0.
  unlock steering.
  steeringManager:resetpids.
  lock steering to heading(hdgHold, pitch).
  output("Steering reset. Pitch locked to " + round(pitch, 3) + ", current pitch " + round(pitch_for(ship), 3)).
  sleep("pitchErrMonitor", pitchErrMonitor@, 5, true, false).
}

so pitchErrMonitor() runs every tick and checks if the steering has deviated by an error greater than 1. When it does, it unlocks the cooked steering, sets the pitch to 0.9 and holds that for one second before resetSteering() is called, which sets the pitch controls back to 0, unlocks the steering, resets the PID controller and then relocks the cooked steering to the pitch profile. After 5 seconds if the steering error is still not fixed it tries again. Here's what that looks like:

wEq2feRl.png

So you can see it deviating as normal and then first bump hits once it moves far enough off the red line. The change to 0.9 pitch instead of 1 raises the nose but then a second later when the steering kicks back in the nose drops again as the pitch returns to max downwards, bobbing a bit due to aero forces. Later pitch bump attempts have little to no effect as air thins. This is a sample of what is output to the flight log:

[15:59:03.30] Bumping pitch controls
[15:59:04.38] Steering reset. Pitch locked to 67.473, current pitch 65.52
[15:59:09.52] Bumping pitch controls
[15:59:10.60] Steering reset. Pitch locked to 64.4, current pitch 61.915
[15:59:15.74] Bumping pitch controls
[15:59:16.82] Steering reset. Pitch locked to 61.452, current pitch 58.463
[15:59:21.96] Bumping pitch controls
[15:59:23.04] Steering reset. Pitch locked to 58.678, current pitch 54.979

So you see the formula is still calculating the proper pitch angle the rocket should be aiming for, but you can also see the rocket is currently below that pitch angle. For some reason the rocket still wants to steer downwards even after I reset the PID and the steering relocks with the nose already lower than it should be.

Edited by Drew Kerman

Share this post


Link to post
Share on other sites
Posted (edited)

also here's a video of the ascent with debug info visible, doing the 1.65 TWR throttle lock

can also really see something getting reset or something during that 2.6km pass that I've mentioned previously - still not sure what's up with that either...

Edited by Drew Kerman

Share this post


Link to post
Share on other sites

I just setup a barebones KSP v1.7.3 install because it's been something I've been meaning to get around to anyways. Put in the mods needed to fly the rocket and with the latest everything I still get the same results, which I expected but good to know for sure

Share this post


Link to post
Share on other sites

I can tell only as much as I can recall from convefrsations in the past when @hvacengi talked about new (at that time) steering manager PID behaviour. It use some method (I can't recall exact name of method) to autocalculate Kp, Ki and Kd by meassuring ocilation period and settling time. PID also reset's itself after some amount of time (can be set trough kOS PID suffixes).

So, while steering manager works quite well in most situations, it is quite possible that it does not work properly in some specific cases. At first, you got more-less steady and almost linear desired planed profile and disturbances in PID loop system from outside forces (mostly aerodynamic). Steering manager have calculated Kp, Ki and Kd values for those conditions. Then at some point you got rapid changes in PID loop from outside forces in both, time of duration of outside forces and magnitude and direction of outside forces.

At that point, steering manager using Kp, Ki and Kd values that simply does not react properly (fast enough) to new situation. This is kind of "normal" behaviour when comes to PID controlers. From wikipedia PID page loop tuning paragraph:

Quote

Some processes have a degree of nonlinearity and so parameters that work well at full-load conditions don't work when the process is starting up from no-load; this can be corrected by gain scheduling (using different parameters in different operating regions).

In my opinion, there is nothing wrong with kOS and steering manager. There is bunch of things you can do to improve steering manager if it does not behave as desired in some situations. Some are described in kOS documentation page: https://pgoddkos.readthedocs.io/en/latest/commands/flight/cooked.html

Most simple thing you can do is to call STEERINGMANAGER:RESETPIDS() function just before you expect new flight regime. And as shown on posts above it works reasonable well.

Share this post


Link to post
Share on other sites
Posted (edited)

Oh hey - important bit of info: the fins that the control surfaces are attached to are angled 5 degrees to give the rocket a natural tendency to want to pitch down. Without enough speed, the controls don't have enough authority to overcome this. I've flown the rocket several times so far no problem with the fins angled, I actually forgot that it was built that way /headdesk

everyone just point and laugh please

Edited by Drew Kerman

Share this post


Link to post
Share on other sites
4 hours ago, Drew Kerman said:

everyone just point and laugh please

No need for that. Everyone makes silly mistake trough any kind of work. Realising and admiting own mistake is one of most positive personal qualities.

And it is good to know for kOS developers that nothing is buged in that area. Although not perfect, kOS steering manager works way much better than stock SAS.

Share this post


Link to post
Share on other sites

@kcs123 what's even more embarrassing is that if you read my posts again I'm telling people - "hey the rocket is supposed to be trying to nose up instead it's forcing the nose down!" and even posted a pic of the control indicator pinned at max upwards saying that was it trying to nose down. In fact the indicator is showing the rocket is trying to pull up! I tend to make this mistake often, because when I look at the control indicators I most often see it as a "top down" view, meaning the indicator moving up is going "forward" so like a flight joystick that would mean the nose goes down. Arrrrggghghghhghg

Share this post


Link to post
Share on other sites

Hi all! I've written my very first launch script and I'm having an issue where setting the throttle doesn't work...only in ONE place in my script. 

https://pastebin.com/rdRycdYB

The offending line is 162, where I set the throttle to 0. Just doesn't work. My program is still running, but the throttle value is not changing. Everywhere else in my script, I can change the throttle just fine. I can't seem to figure out what is going wrong. My script is not crashing (up until that point, anyway). 

Share this post


Link to post
Share on other sites
5 hours ago, subyng said:

Hi all! I've written my very first launch script and I'm having an issue where setting the throttle doesn't work...only in ONE place in my script. 

https://pastebin.com/rdRycdYB

The offending line is 162, where I set the throttle to 0. Just doesn't work. My program is still running, but the throttle value is not changing. Everywhere else in my script, I can change the throttle just fine. I can't seem to figure out what is going wrong. My script is not crashing (up until that point, anyway). 

Your function writes to currentThrottle, which isn't declared as GLOBAL. I'm not entirely sure, but I guess you're actually writing to a different (function-local) variable than the one THROTTLE is locked to.

Share this post


Link to post
Share on other sites
Just now, Lookerksy said:

Can anyone recommend me an IDE to write kOS codes? Thanks.

npp (notepad++) (multiple language files available)

kode

visual studio code (language files available)

 

all free.

Share this post


Link to post
Share on other sites
58 minutes ago, Lookerksy said:

Can anyone recommend me an IDE to write kOS codes? Thanks.

 

xh3zyuL.png

I use notepad++

I personally activated the "C++ Language Code" and I use the files with that extension.

KOS will process them.

Cheers and good code!

Share this post


Link to post
Share on other sites
9 hours ago, Lookerksy said:

Can anyone recommend me an IDE to write kOS codes? Thanks.

If you're on Linux and don't want to dive straight into vi or EMACS, Mousepad and Geany are two fairly lightweight packages your distro might have available. Geany is available for Windows and Mac PCs, too (as are vi and EMACS, afaik ; ) )

Share this post


Link to post
Share on other sites
On 8/2/2019 at 3:20 PM, Drew Kerman said:

sounds good - I'm also interested in opinions from @kcs123 and @FloppyRocket since they chimed in with some wisdom last I posted about PID issues

I'll be back later with some more ascent testing

I haven't been actively investigating this.

Early on I tried some simple experiments to duplicate the issue from the original topic (i.e. sudden shifts away from the intended pitch curve), but I wasn't able to observe any abrupt departures from the planned pitch.

The only curious thing I observed was that the rocket I designed also had pitch control saturation, but I chalked that up to the pitch curve being aerodynamically difficult for my specific rocket design to fly.

I have seen PID integral windup before professionally. It was not a happy experience.

 

 

Share this post


Link to post
Share on other sites
20 minutes ago, FloppyRocket said:

I haven't been actively investigating this.

Early on I tried some simple experiments to duplicate the issue from the original topic (i.e. sudden shifts away from the intended pitch curve), but I wasn't able to observe any abrupt departures from the planned pitch.

The only curious thing I observed was that the rocket I designed also had pitch control saturation, but I chalked that up to the pitch curve being aerodynamically difficult for my specific rocket design to fly.

I have seen PID integral windup before professionally. It was not a happy experience.

 

When I was performing dynamic stability analysis for an rc plane I used zeigler-nichols tuning for the pid loops in the simulation.

 

Share this post


Link to post
Share on other sites
Posted (edited)
3 hours ago, Xt007 said:

 

@Xt007, you quoted my message, but didn't add any reply.

16 hours ago, Lookerksy said:

Can anyone recommend me an IDE to write kOS codes? Thanks.

Notepad++ here also. I don't use it as an IDE, but it is a very good code editor.

Edited by FloppyRocket

Share this post


Link to post
Share on other sites
4 hours ago, FloppyRocket said:

@Xt007, you quoted my message, but didn't add any reply.

He did, but ended up inside your qoute. Happens often when people use smartphones in forum.

7 hours ago, Xt007 said:

When I was performing dynamic stability analysis for an rc plane I used zeigler-nichols tuning for the pid loops in the simulation.

 

Share this post


Link to post
Share on other sites

Not sure if I should even post here, but is there a way I can control the robotics from the Breaking Ground Expansion via kOS?

The situation is as follows: Built a large airplane, so large that standard control surfaces aren't enough, so I made custom large elevators, which are moved via a hinge which is bound to the Pitch control input from the pilot. This works fine for manual flying, however problems already occur when using trim, since apparently these parts don't react to trim input, only to "actual" input from the pilot as in 'W' or 'S' being pushed.

However when I try to let kOS steer the plane, which works just fine with normal elevators, things don't work out. Neither raw control seems to work (set ship:control:pitch to 1) nor does "direct" control (lock steering to up). Maybe both issues are somehow related? It's also possible that this is a problem with the game itself, but thought I'd post it here anyways since I'd be really cool if this actually worked!

Share this post


Link to post
Share on other sites
4 hours ago, Kartoffelkuchen said:

Not sure if I should even post here, but is there a way I can control the robotics from the Breaking Ground Expansion via kOS?

The situation is as follows: Built a large airplane, so large that standard control surfaces aren't enough, so I made custom large elevators, which are moved via a hinge which is bound to the Pitch control input from the pilot. This works fine for manual flying, however problems already occur when using trim, since apparently these parts don't react to trim input, only to "actual" input from the pilot as in 'W' or 'S' being pushed.

However when I try to let kOS steer the plane, which works just fine with normal elevators, things don't work out. Neither raw control seems to work (set ship:control:pitch to 1) nor does "direct" control (lock steering to up). Maybe both issues are somehow related? It's also possible that this is a problem with the game itself, but thought I'd post it here anyways since I'd be really cool if this actually worked!

Can you try ship:control:pilotpitch ?

It represents the actual pilot's control rather than kOS's control.  Maybe the Breaking Ground DLC can read that.

Share this post


Link to post
Share on other sites
4 minutes ago, Steven Mading said:

Can you try ship:control:pilotpitch ?

Aren't ship:control:pilotXXX Get only, except for pilotmainthrottle?

Share this post


Link to post
Share on other sites
4 hours ago, Steven Mading said:

Can you try ship:control:pilotpitch ?

It represents the actual pilot's control rather than kOS's control.  Maybe the Breaking Ground DLC can read that.

Yeah what @scimas said, it's get only and the DLC seems to be able to only read pilotcontrol. :/

 

Share this post


Link to post
Share on other sites

Hi guys i need help with KOS please getting errors, undefined variable print "Launch Time:             T" + round(missionT - launchcht) if anyone could help please.

 

Here is my code for KOS:

 

//Print data to screen
@lazyglobal off.

set terminal:width to 60.
set terminal:height to 50.

function displayFlightData {

//Title bar
print "------------------- Flight Display 1.0 --------------------"                                                                at (1,1).        
print "Launch Time:             T" + round(missionT - launchcht) + "               "                                                at (3,2).
// Body info
print "Current Body:            " + currentBody() + "               "                                                            at (3,3).
print "Atm Height:              " + atmHeight() + "               "                                                                at (3,4).
print "SL Gravity:              " + round(staticGravity(), 2) + "               "                                                at (3,5).
print "                                                           "                                                                at (1,6).
print "Current Gravity:         " + round(gravity(ship:altitude), 2) + "               "                                                        at (3,7).
print "TWR:                     " + round(shipCurrentTWR(), 2) + " / " + round(shipTWR(), 2) + "               "                at (3,8).
print "                                                           "                                                                at (1,9).
print "Heading:                 " + round(compass_for(ship), 2) + "               "                                                at (3,10).
print "Pitch:                   " + round(pitch_for(ship), 2) + "               "                                                at (3,11).
print "Roll:                    " + round(roll_for(ship), 2) + "               "                                                at (3,12).
print "                                                          "                                                                at (1,13).
print "Sea Level Altitude:      " + round(ship:altitude / 1000 , 1) + "km               "                                        at (3,14).
print "                                                           "                                                                at (1,15).
print "-----------------------------------------------------------"                                                                at (1,16).
print "                                                           "                                                                at (1,17).
}

function displayLaunchData {

print "Target Heading:          " + round(compass, 2) + "               "                                                        at (3,18).
print "Target Pitch:            " + round(pitch, 2) + "               "                                                            at (3,19).
print "Target Apoapsis:         " + round(orbAlt / 1000) + "km               "                                            at (3,20).
print "Current Apoapsis:        " + round(ship:apoapsis / 1000, 3) + "km               "                                        at (3,21).
print "                                                           "                                                                at (1,22).
print "-----------------------------------------------------------"                                                                at (1,23).
print "                                                           "                                                                at (1,24).
}

function displayManeuverData {
parameter node.

//print "Target Apoapsis:         " + round(targetAltitude / 1000) + "km               "                                            at (3,18).
print "Maneuver ETA:            " + round(node:eta - (nodeBurnTime(node) / 2), 1) + "s               "                            at (3,19).
//print "Orbital Velocity:        " + round(getOrbitalVelocity(ship:apoapsis), 1) + "m/s               "                            at (3,20).
//print "Velocity at Apoapsis:    " + round(getVelocityAtApoapsis(), 1) + "m/s               "                                    at (3,21).
print "Node DeltaV Reqired:     " + round(node:deltav:mag, 1) + "m/s               "                                            at (3,22).
print "Estimated Burn Time:     " + round(nodeBurnTime(node), 1) + "s               "                                            at (3,23).
print "                                                           "                                                                at (1,24).
print "-----------------------------------------------------------"                                                                at (1,25).
print "                                                           "                                                                at (1,26).
}
 

Share this post


Link to post
Share on other sites

Welcome to the forum @Martin911.

I've merged your post into this KOS thread as it is the best place to get KOS advice.

Share this post


Link to post
Share on other sites
10 hours ago, Martin911 said:

Hi guys i need help with KOS please getting errors, undefined variable print "Launch Time:             T" + round(missionT - launchcht) if anyone could help please.

Well, the simple response is: where is missionT defined?

However, the code you've printed is full of variables and function calls that aren't defined anywhere that we can see. missionT is just the first of many such problems and fixing them one-by-one would be quite painful. Is your code meant to be loading libraries that define those variables and functions? If so, those libraries need to be run at the top of your script, to load in all the bits you are dependent on.

Share this post


Link to post
Share on other sites
Posted (edited)

Injust installed kOS into a new game., using CKAN.  A dialog popped up about terminal fonts.

It doesnt go away.  I have it plastered on the screen.  It just sits there, clicks go through, etc.  and when on a new screen, it is still there.  Clicking the button doesnt do anything

Not sure what is going on, but its makes the game unplayable

Update: After selecting a font in the flight scene, it went away. IMHO this is terrible.  Im planning on starting an intense, difficult career, and I shouldnt have to go to the flight scene (which, because of KCT, will take a while) to dismiss the dialog

Log file here:  https://www.dropbox.com/s/lqi789862kqlk0c/kOSissue.zip?dl=0

Edited by linuxgurugamer

Share this post


Link to post
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.