Jump to content

KOS script not working


Recommended Posts

Not to sure were to put this but i'm pretty sure this is were I should.

I have a problem with my Kos script where it wont launch my falcon 9. I'm using the tundra mod and the script should be able to run it. What it's supposed to do it launch the rocket get the other stages to orbit while the first stage does a boost back and lands back on the launch pad. When I press 2 (the action group to toggle the control thingy for KOS) nothing happens. BTW I did not make this script I watched a tutorial for space x landings here are the scripts

Script 1: 

// Ah yes
// Mission Setup


wait until ag6.

missionSetup(

    // Will change depending on mission

    "ASDS",  // ["ASDS"] | ["RTLS"] | ["AOTL"] | ["EEHL"]
    500000,  // Target Orbit (Meters) (Station Freedom - 210000)
    28.6,       // Target Inclination (Degrees)
    "Cargo",  // ["Cargo"]
    false // Wait for launch window? (true / false)

).

function missionSetup {

    parameter lMode, tOrbit, tInc, pType, window.

    clearscreen.

    // LandingMode Setup
    print "Landing Mode: " + lMode.
    if (lMode = "ASDS" or lMode = "AOTL") {global a is 120. global fuelToLand is 5000.} // 80
    else {set a to 130. set fuelToLand to 5800.}

    // TargetOrbit Setup
    if (tOrbit < 100000) {print "Target Orbit too low: " + tOrbit. abort on.}
    else {print "Target Orbit: " + tOrbit.}
    global atmosphericAlt is body:atm:height.
    global targetOrbit is tOrbit.

    // TargetInclination Setup
    if (tInc > 90) {print "Target Inclination too high: " + tInc. abort on.}
    else if (tInc < -90) {print "Target Inclination too low: " + tInc. abort on.}
    else {print "Target Inclination: " + tInc.}
    global targetInclination is tInc.

    lights on.

    // PayloadType Setup
    print "Payload Type: " + pType.
    if (pType = "Cargo") {global hasFairings is true. global fairingSepAlt is 80000. cargoFlight().} // 90 timer

}

// Other Variables

function pitchOfVector {

    parameter vecT.
    return 90 - vang(ship:up:vector, vecT).

}

// Cargo Ascent Functions

function cargoFlight {

    // Steeringmanager Setup
    set steeringmanager:rollts to 25.
    set steeringmanager:maxstoppingtime to 10.

    set orbitalInsertionBurnLock to true.

    // Script Setup

    runOncePath("0:/lib_lazcalc").

    // Liftoff  

    toggle ag2.
    wait 10.
    stage.
    lock throttle to 1.
    wait 2.
    stage.
    lock steering to up.
    wait 8.

    print "Liftoff".

    wait 1.5.
    if verticalSpeed > 1 {
        print "Nominal liftoff".
    } else {
        print "Abort activated".
        abort on.
        shutdown.
    }

    // Functions

    cargoAscent().
    cargoMeco().
    cargoSecondStage().
    cargoOrbitalBurn().

}

function cargoAscent {

    local azimuth_data is LAZcalc_init(targetOrbit, targetInclination).

    local slope is (0-90) / (1000 * (a - 10 - a * 0.05) - 0).

    until (ship:liquidfuel <= fuelToLand + 100) {

        local pitch is slope * ship:apoapsis + 90.

        if pitch < 0 {

            set pitch to 0.

        }

        if pitch > pitchOfVector(velocity:surface) + 5 {

            set pitch to pitchOfVector(velocity:surface) + 5.

        } else if pitch < pitchOfVector(velocity:surface) - 5 {

            set pitch to pitchOfVector(velocity:surface) -5.

        }

        local azimuth is LAZcalc(azimuth_data).

        lock steering to heading(azimuth, pitch).

    }

}

function cargoMeco {

    wait until (ship:liquidfuel <= fuelToLand + 100).
        rcs on.
        set currentFacing to facing.
        lock steering to currentFacing.
        wait until (ship:oxidizer <= fuelToLand).
            lock throttle to 0.
            lock steering to currentFacing.
            wait 0.5.
            print "MECO".
            rcs on.
            toggle ag8.
            stage.
            print "STAGE SEP".
            wait 3.5.
            lock throttle to 1.
            print "SSI1".

}

function cargoSecondStage {

    lock steering to currentFacing.
    wait 5.
    lock steering to prograde.

    when (ship:altitude >= fairingSepAlt and hasFairings = true) then {

        stage.
        print "Fairing sep".

    }

    when missionTime >= 280 then {
        print "Signal Kermuda, Stage 2 FTS Safed".
    }

    wait until (ship:apoapsis >= targetOrbit).
        lock throttle to 0.
        print "SECO1".

    wait until (ship:altitude >= atmosphericAlt).
        set orbitalInsertionBurnLock to false.
        print "Atmospheric Exit".
        print eta:apoapsis.

}

function cargoOrbitalBurn {

    set targetVel to sqrt(ship:body:mu / (ship:orbit:body:radius + ship:orbit:apoapsis)).
    set apVel to sqrt(((1 - ship:orbit:eccentricity) * ship:orbit:body:mu) / ((1 + ship:orbit:eccentricity) * ship:orbit:semimajoraxis)).
    set dv to targetVel - apVel.
    set myNode to node(time:seconds + eta:apoapsis, 0, 0, dv).
    add myNode.

    lock steering to lookdirup(ship:prograde:vector, heading(180, 0):vector).

    set nd to nextNode.
    set max_acc to ship:maxthrust / ship:mass.
    set burn_duration to nd:deltav:mag / max_acc.
    wait until nd:eta <= (burn_duration / 2 + 60).

    set np to nd:deltav.
    lock steering to np.
    wait until vang(np, ship:facing:vector) < 0.33.

    wait until nd:eta <= (burn_duration / 2).

    set dv0 to nd:deltav.
    set done to false.

    until done {

        wait 0.
        set max_acc to ship:maxthrust / ship:mass.

        lock throttle to min(nd:deltav:mag / max_acc, 1).

        print "SSI2".

        if vdot(dv0, nd:deltav) < 0 {

            lock throttle to 0.
            print "SECO2".
            break.

        }

        if nd:deltav:mag < 0.1 {

            wait until vdot(dv0, nd:deltav) < 0.5.
            lock throttle to 0.
            print "SECO2".
            shutdown.
            sas on.

        }

    }

}

 

Script 2:

// Elixer Space Company - ASDS Script [version 0.3.1]


// Landing Parameters


parameter landingZone is latlng(-0.0972081051142032, -74.5576756827403).


// Initialization


wait until ag8.
rcs on.
set currentFacing to facing.
lock steering to currentFacing.
wait 3.


// ASDS & AOTL Functions


    clearscreen.
    print "Elixer Landing Software".
    print "-".

    set steeringManager:maxstoppingtime to 5.
    set steeringManager:rollts to 20.


    // Landing Variables


    set radarOffset to 21.15. // This must be changed to the height of the landing vehicle (on gear)
    lock trueRadar to alt:radar - radarOffset.
    lock g to constant:g * body:mass / body:radius^2.
    lock maxDecel to (ship:availablethrust / ship:mass) - g.
    lock stopDist to ship:verticalspeed^2 / (2 * maxDecel).
    lock idealThrottle to stopDist / trueRadar.
    lock impactTime to trueRadar / abs(ship:verticalspeed).
    lock aoa to 30.
    lock errorScaling to 1.


    // Guidance Functions


    function getImpact {
        if addons:tr:hasimpact { return addons:tr:impactpos. }
            return ship:geoposition.
        }

    function lngError {
        return getImpact():lng - landingZone:lng.
        }

    function latError {
        return getImpact():lat - landingZone:lat.
        }

    function errorVector {
        return getImpact():position - landingZone:position.
        }

    function getSteering {
        local errorVector is errorVector().
        local velVector is -ship:velocity:surface.
        local result is velVector + errorVector*errorScaling.

        if vang(result, velVector) > aoa
        {
            set result to velVector:normalized
                        + tan(aoa)*errorVector:normalized.
        }

        return lookdirup(result, facing:topvector).
    }

rcs on.
lock steering to srfretrograde. 
brakes on.
wait until ship:verticalspeed <-700.
    lock throttle to 1.
    lock aoa to -5.
    lock steering to getSteering().
    toggle ag1.
    toggle ag7.
    rcs off.

wait until ship:verticalspeed > -200.
    lock throttle to 0.
    lock aoa to 17.5. 
    lock steering to getSteering().
    steeringManager:resettodefault().
    rcs on.

wait until alt:radar < 12000.
    lock aoa to 10.

wait until alt:radar < 7000.
    lock aoa to 5.

WAIT UNTIL ship:verticalspeed < -10. 
    rcs on.
    when impactTime < 2.75 then {gear on.} 

WAIT UNTIL trueRadar < stopDist. 
    lock throttle to 1.
    lock aoa to -3.
    lock steering to getSteering().

wait until ship:verticalspeed > -45.
    toggle ag1.
    lock throttle to idealThrottle.
    lock aoa to -2.
    lock steering to getSteering().

when impactTime < 0.75 then {lock steering to heading(90, 90).}
   
WAIT UNTIL ship:verticalspeed > -0.1.
    lock steering to up.
    set ship:control:pilotmainthrottle to 0.
    RCS off.

 

Script 3:

//This file is distributed under the terms of the MIT license, (c) the KSLib team
//=====LAUNCH AZIMUTH CALCULATOR=====
//~~LIB_LAZcalc.ks~~
//~~Version 2.2~~
//~~Created by space-is-hard~~
//~~Updated by TDW89~~
//~~Auto north/south switch by undercoveryankee~~

@LAZYGLOBAL OFF.

FUNCTION LAZcalc_init {
    PARAMETER
        desiredAlt, //Altitude of desired target orbit (in *meters*)
        desiredInc. //Inclination of desired target orbit

    PARAMETER autoNodeEpsilon IS 10. // How many m/s north or south
        // will be needed to cause a north/south switch. Pass zero to disable
        // the feature.
    SET autoNodeEpsilon to ABS(autoNodeEpsilon).
    
    //We'll pull the latitude now so we aren't sampling it multiple times
    LOCAL launchLatitude IS SHIP:LATITUDE.
    
    LOCAL data IS LIST().   // A list is used to store information used by LAZcalc
    
    //Orbital altitude can't be less than sea level
    IF desiredAlt <= 0 {
        PRINT "Target altitude cannot be below sea level".
        SET launchAzimuth TO 1/0.        //Throws error
    }.
    
    //Determines whether we're trying to launch from the ascending or descending node
    LOCAL launchNode TO "Ascending".
    IF desiredInc < 0 {
        SET launchNode TO "Descending".
        
        //We'll make it positive for now and convert to southerly heading later
        SET desiredInc TO ABS(desiredInc).
    }.
    
    //Orbital inclination can't be less than launch latitude or greater than 180 - launch latitude
    IF ABS(launchLatitude) > desiredInc {
        SET desiredInc TO ABS(launchLatitude).
        // HUDTEXT("Inclination impossible from current latitude, setting for lowest possible inclination.", 10, 2, 30, RED, FALSE).
    }.
    
    IF 180 - ABS(launchLatitude) < desiredInc {
        SET desiredInc TO 180 - ABS(launchLatitude).
        // HUDTEXT("Inclination impossible from current latitude, setting for highest possible inclination.", 10, 2, 30, RED, FALSE).
    }.
    
    //Does all the one time calculations and stores them in a list to help reduce the overhead or continuously updating
    LOCAL equatorialVel IS (2 * CONSTANT():Pi * BODY:RADIUS) / BODY:ROTATIONPERIOD.
    LOCAL targetOrbVel IS SQRT(BODY:MU/ (BODY:RADIUS + desiredAlt)).
    data:ADD(desiredInc).       //[0]
    data:ADD(launchLatitude).   //[1]
    data:ADD(equatorialVel).    //[2]
    data:ADD(targetOrbVel).     //[3]
    data:ADD(launchNode).       //[4]
    data:ADD(autoNodeEpsilon).  //[5]
    RETURN data.
}.

FUNCTION LAZcalc {
    PARAMETER
        data. //pointer to the list created by LAZcalc_init
    LOCAL inertialAzimuth IS ARCSIN(MAX(MIN(COS(data[0]) / COS(SHIP:LATITUDE), 1), -1)).
    LOCAL VXRot IS data[3] * SIN(inertialAzimuth) - data[2] * COS(data[1]).
    LOCAL VYRot IS data[3] * COS(inertialAzimuth).
    
    // This clamps the result to values between 0 and 360.
    LOCAL Azimuth IS MOD(ARCTAN2(VXRot, VYRot) + 360, 360).

    IF data[5] {
        LOCAL NorthComponent IS VDOT(SHIP:VELOCITY:ORBIT, SHIP:NORTH:VECTOR).
        IF NorthComponent > data[5] {
            SET data[4] TO "Ascending".
        } ELSE IF NorthComponent < -data[5] {
            SET data[4] to "Descending".
        }.
    }.
    
    //Returns northerly azimuth if launching from the ascending node
    IF data[4] = "Ascending" {
        RETURN Azimuth.
        
    //Returns southerly azimuth if launching from the descending node
    } ELSE IF data[4] = "Descending" {
        IF Azimuth <= 90 {
            RETURN 180 - Azimuth.
            
        } ELSE IF Azimuth >= 270 {
            RETURN 540 - Azimuth.
            
        }.
    }.
}.

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