Created
September 2, 2020 12:40
-
-
Save vyznev/75d82a5069c044358820959b6e854660 to your computer and use it in GitHub Desktop.
kOS script for differential throttle augmented steering
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This script sets up a background trigger that automatically adjusts engine throttle according to the yaw / pitch / roll | |
// commands of the kOS built-in steering manager. This can allow a vessel to be controlled even without any reaction wheels, | |
// gimbals or control surfaces, and can also provide additional control authority and stability on top of normal steering | |
// especially for vessels with asymmetric thrust. | |
// | |
// The operation of the trigger is controlled by a number of global variables: | |
// | |
// * Setting dt_flag to false will terminate the trigger loop. | |
// * The loop will adjust throttle on any engines listed in dt_engines (by default, all engines on the vessel). | |
// * The baseline thrust limit on all controlled engines, in the absence of steering input, is set to dt_base percent. | |
// Setting this to a value less than 100 can improve steering response at the expense of total thrust. | |
// * The vector dt_ctrl controls the actual pitch, yaw and roll adjustments the trigger attempts to make. By default this | |
// vector is locked to the outputs of the corresponding steering manager PID controllers, scaled by constants that specify | |
// how much (in percent) the trigger is allowed to adjust engine thrust up or down from dt_base for each control axis. | |
// The default is up to 50% thrust adjustment for yaw control and 0% for pitch and roll control. | |
// | |
// Warning: This script will lock the gimbal, if present, on all controlled engines! Combining throttle and gimbal control | |
// on the same engine would require additional math that I haven't currently implemented. | |
// | |
// By default, the script will continually print some debugging information at the top of the terminal window. The print | |
// statements may be commented out if quiet operation is desired. | |
list engines in dt_engines. | |
for eng in dt_engines { if eng:hasgimbal { set eng:gimbal:lock to true. } } | |
lock dt_ctrl to v(0 * steeringmanager:pitchpid:output, 50 * steeringmanager:yawpid:output, 0 * steeringmanager:rollpid:output). | |
set dt_base to 100. | |
set dt_flag to true. | |
when true then { | |
print "DTC " + dt_ctrl + " " at (0,0). | |
local i is 1. | |
for eng in dt_engines { | |
local torque is vcrs(eng:position, eng:facing:vector) * -ship:facing. | |
set eng:thrustlimit to max(0, min(100, dt_base + dt_ctrl * torque:normalized)). | |
print "E" + i + ": " + eng:thrustlimit + "% at " + torque + " " at (0,i). | |
set i to i + 1. | |
} | |
return dt_flag. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment