This is a lot of code that "should" work.

This commit is contained in:
Kenwood 2021-04-09 02:52:55 -04:00
parent 7cbd00f241
commit c6d965e473
4 changed files with 65 additions and 108 deletions

3
RadarrSeries/README.md Normal file
View File

@ -0,0 +1,3 @@
A collection of software scrips, for the RADARR series of scanning satelights!
Lots of stuff to do here :3

View File

@ -0,0 +1,42 @@
CLEARSCREEN. // Clear the screen
NOTIFY("Ascent software ready.").
// Lock throttle to 1, (throttle up)
LOCK THROTTLE TO 1.0. // 1.0 is the max, 0.0 is idle.
// Countdown from 10!
NOTIFY("Counting down:").
FROM {local countdown is 10.} UNTIL countdown = 0 STEP {SET countdown to countdown - 1.} DO {
NOTIFY(countdown, 1). // Notify the countdown number and keep the number for 1 second.
WAIT 1. // pauses the script here for 1 second.
}
// First goal should be to get into space,
// I found this rule of thumb expression "
// (altitude*23.3/body:atm:height)^0.7*15.
// on reddit. It looks good enough!
CLEARSCREEN. // Clear the screen.
SET MYSTEER TO HEADING(90,90). // Default to up
LOCK STEERING TO MYSTEER. // Set steering to the value of MYSTEER, when it updates so will our steering.
UNTIL false { // Run forever
SET MYSTEER TO HEADING(90,(altitude*23.3/body:atm:height)^0.7*15).
// One of these conditions must be met to call a break in this ascent!
IF SHIP:APOAPSIS > 100000 // This is good! We made it to space!
OR SHIP:VERTICALSPEED > 0 // This is bad, we've started to fall down.
{
BREAK.
}
WAIT 0.5. // Run this loop every half second.
}
NOTIFY("We broke out of the ascent loop! If thats a good thing you'ld know.").
LOCK THROTTLE TO 0. // Throttle back
SET SHIP:CONTROL:PILOTMAINTHROTTLE TO 0. // Protects the throttle from "jumping" when we hand control back to the pilot

View File

@ -4,22 +4,36 @@
// This script is the boot script for the Radarr
// series of surface scanning probes.
// This section from latest docs.
wait until ship:unpacked.
clearscreen.
// This method prints in big letters something on the screen.
FUNCTION NOTIFY {
PARAMETER message.
PARAMETER duration IS 5.
PARAMETER color IS WHITE.
HUDTEXT("kOS: " + message, 5, 2, 50, WHITE, false).
PRINT message.
}
NOTIFY("Program booted!").
// This section from latest docs.
wait until ship:unpacked.
clearscreen.
NOTIFY("Boot sequence complete, prepare to load and compile the flight scripts.").
IF true { // Set this to false to avoid compiling ascent code.
SWITCH TO 0.
COPYPATH("0:/RadarrSeries/radarr.kerbin.ks", ""). // Copy over our launch script from the archive at ksc
COMPILE "radarr.kerbin.ks" to "ascent.ksm". // Compile the flight code into a ksm object.
} ELSE {
COPYPATH("0:/RadarrSeries/radarr.kerbin.ks", "1:/ascent.ks"). // Copy over our launch script from the archive at ksc
}
NOTIFY("Program compiled and ready to run.").
IF ALT:RADAR < 100 { // If our radar alt is lower than 10
WAIT 5.
COPY radarr.kerbin.ks FROM 0. // Copy in a prototyping script
RUN radarr.kerbin.ks. // Run the script we coppied over
run ascent.ks. // Run the ascent stage!
} else {
NOTIFY("System booted but did not pass pre-flight checks, aborting excecution!").
}

View File

@ -1,102 +0,0 @@
//First, we'll clear the terminal screen to make it look nice
CLEARSCREEN.
NOTIFY("Software loaded and ready to takeoff.").
//Next, we'll lock our throttle to 100%.
LOCK THROTTLE TO 1.0. // 1.0 is the max, 0.0 is idle.
//This is our countdown loop, which cycles from 10 to 0
PRINT "Counting down:".
FROM {local countdown is 10.} UNTIL countdown = 0 STEP {SET countdown to countdown - 1.} DO {
PRINT "..." + countdown.
WAIT 1. // pauses the script here for 1 second.
}
//This is a trigger that constantly checks to see if our thrust is zero.
//If it is, it will attempt to stage and then return to where the script
//left off. The PRESERVE keyword keeps the trigger active even after it
//has been triggered.
WHEN MAXTHRUST = 0 THEN {
NOTIFY("Staging").
STAGE.
PRESERVE.
}.
//This will be our main control loop for the ascent. It will
//cycle through continuously until our apoapsis is greater
//than 100km. Each cycle, it will check each of the IF
//statements inside and perform them if their conditions
//are met
SET MYSTEER TO HEADING(90,90).
LOCK STEERING TO MYSTEER. // from now on we'll be able to change steering by just assigning a new value to MYSTEER
UNTIL SHIP:APOAPSIS > 100000 { //Remember, all altitudes will be in meters, not kilometers
//For the initial ascent, we want our steering to be straight
//up and rolled due east
IF SHIP:VELOCITY:SURFACE:MAG < 100 {
//This sets our steering 90 degrees up and yawed to the compass
//heading of 90 degrees (east)
SET MYSTEER TO HEADING(90,90).
//Once we pass 100m/s, we want to pitch down ten degrees
} ELSE IF SHIP:VELOCITY:SURFACE:MAG >= 100 AND SHIP:VELOCITY:SURFACE:MAG < 200 {
SET MYSTEER TO HEADING(90,80).
NOTIFY("Pitching to 80 degrees").
PRINT ROUND(SHIP:APOAPSIS,0) AT (0,16).
//Each successive IF statement checks to see if our velocity
//is within a 100m/s block and adjusts our heading down another
//ten degrees if so
} ELSE IF SHIP:VELOCITY:SURFACE:MAG >= 200 AND SHIP:VELOCITY:SURFACE:MAG < 300 {
SET MYSTEER TO HEADING(90,70).
NOTIFY("Pitching to 70 degrees").
PRINT ROUND(SHIP:APOAPSIS,0) AT (0,16).
} ELSE IF SHIP:VELOCITY:SURFACE:MAG >= 300 AND SHIP:VELOCITY:SURFACE:MAG < 400 {
SET MYSTEER TO HEADING(90,60).
NOTIFY("Pitching to 60 degrees").
PRINT ROUND(SHIP:APOAPSIS,0) AT (0,16).
STAGE.
} ELSE IF SHIP:VELOCITY:SURFACE:MAG >= 400 AND SHIP:VELOCITY:SURFACE:MAG < 500 {
SET MYSTEER TO HEADING(90,50).
NOTIFY("Pitching to 50 degrees").
PRINT ROUND(SHIP:APOAPSIS,0) AT (0,16).
} ELSE IF SHIP:VELOCITY:SURFACE:MAG >= 500 AND SHIP:VELOCITY:SURFACE:MAG < 600 {
SET MYSTEER TO HEADING(90,40).
NOTIFY("Pitching to 40 degrees").
PRINT ROUND(SHIP:APOAPSIS,0) AT (0,16).
STAGE.
} ELSE IF SHIP:VELOCITY:SURFACE:MAG >= 600 AND SHIP:VELOCITY:SURFACE:MAG < 700 {
SET MYSTEER TO HEADING(90,30).
NOTIFY("Pitching to 30 degrees").
PRINT ROUND(SHIP:APOAPSIS,0) AT (0,16).
} ELSE IF SHIP:VELOCITY:SURFACE:MAG >= 700 AND SHIP:VELOCITY:SURFACE:MAG < 800 {
SET MYSTEER TO HEADING(90,11).
NOTIFY("Pitching to 20 degrees").
PRINT ROUND(SHIP:APOAPSIS,0) AT (0,16).
//Beyond 800m/s, we can keep facing towards 10 degrees above the horizon and wait
//for the main loop to recognize that our apoapsis is above 100km
} ELSE IF SHIP:VELOCITY:SURFACE:MAG >= 800 {
SET MYSTEER TO HEADING(90,10).
NOTIFY("Pitching to 10 degrees").
PRINT ROUND(SHIP:APOAPSIS,0) AT (0,16).
}.
}.
NOTIFY("100km apoapsis reached, cutting throttle").
//At this point, our apoapsis is above 100km and our main loop has ended. Next
//we'll make sure our throttle is zero and that we're pointed prograde
LOCK THROTTLE TO 0.
//This sets the user's throttle setting to zero to prevent the throttle
//from returning to the position it was at before the script was run.
SET SHIP:CONTROL:PILOTMAINTHROTTLE TO 0.