From d0cc0477366a15d5bea3798692f92a932610cfcf Mon Sep 17 00:00:00 2001 From: Petruchio96 <44350446+Petruchio96@users.noreply.github.com> Date: Tue, 22 Jan 2019 10:29:16 -0600 Subject: [PATCH] Improved charge calculations in CalcChargeTime and modified TransmitAllScience to use the better time to warp. Signed-off-by: Petruchio96 <44350446+Petruchio96@users.noreply.github.com> --- README.md | 4 ++-- Standard_Lib.ks | 20 ++++++++++++++------ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 093aec7..99c0506 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Kos-Scripts General Functions and programs to use with the Kerbal Operating System - KOS -Updated 1/21/19 +Updated 1/22/19 ## SyncLong.ks(longitude, altitude) @@ -66,7 +66,7 @@ _**Optional Parameters:** none_ ### Function TransmitAllScience(_Optional SensorList, Optional WarpTime, Optional Verbose, Optional ChargePerMit_, Optional TransSpeed) -**Description:** Transmits all science data available on the ship, or only a list of science parts that is passed to the function as a parameter. The ship must have an external antenna part with a connection to the KSC to transmit; otherwise, the function will abort. This will not use the data transmitter in a command module. For each science experiment it will check to see if there is enough charge. If not, it will check to see if the ship is charging and calculate the time required to charge. The function will warp by default unless the optional parameter WarpTime is passed in as "false." The fuction aborts if the ship's total charge capacity isn't enough to transmit the data, or if the ship is not charging and there's not enough charge to transmit. Has a reserve charge variable set at 5%; this stops the function from dropping the total charge of the ship to below this percentage of it's total charge capacity. +**Description:** Transmits all science data available on the ship, or only a list of science parts that is passed to the function as a parameter. The ship must have an external antenna part with a connection to the KSC to transmit; otherwise, the function will abort. This will not use the data transmitter in a command module. For each science experiment it will check to see if there is enough charge. If not, it will check to see if the ship is charging and calculate the time required to charge. The function will warp by default unless the optional parameter WarpTime is passed in as "false." The fuction aborts if the ship's total charge capacity isn't enough to transmit the data, or if the ship is not charging and there's not enough charge to transmit. Has a reserve charge variable set at 5%; this stops the function from dropping the total charge of the ship to below this percentage of it's total charge capacity. Highly encouraged to use optional parameters ChargePerMit and TransSpeed to make sure the ship has just enough charge to transmit and accurate warping. **Required functions called:** * GetDeployableAntList() diff --git a/Standard_Lib.ks b/Standard_Lib.ks index a60e0d3..78e6f0c 100644 --- a/Standard_Lib.ks +++ b/Standard_Lib.ks @@ -55,13 +55,21 @@ function CalcChargeTime { Declare Parameter ChargeNeeded. //Required parameter - the amount of charge needed to increase Declare Local Charge1 to 0.0. + Declare Local Charge1Time to 0.0. Declare Local Charge2 to 0.0. + Declare Local Charge2Time to 0.0. set Charge1 to ship:electriccharge. - wait 0.5. + set Charge1Time to Time:Seconds. + wait 0.25. set Charge2 to ship:electriccharge. + set Charge2Time to Time:Seconds. - return ChargeNeeded / ((Charge2 - Charge1) / 0.5). + if Charge1 = Charge2 { + return 0. + } else { + return ChargeNeeded / ((Charge2 - Charge1) / (Charge2Time - Charge1Time)). + } }. function ShipMaxCharge { @@ -336,7 +344,7 @@ function TransmitAllScience { //Check if electric charge capacity of ship is enough to transmit this science set ChargeCapacity to ShipMaxCharge(). if Verbose {print " Current Charge: " + round(ship:electriccharge, 1).} - if Verbose {print " Needed Charge: " + ChargePerMit * DataSize.} + if Verbose {print " Needed Charge: " + (ChargePerMit * DataSize + Round(ReserveCharge * ChargeCapacity, 1)).} if ChargeCapacity < (ChargePerMit * DataSize) + (ChargeCapacity * ReserveCharge) { if Verbose {print (" Vessel Electric Charge capacity not sufficient to transmit").} if Verbose {print (" ****Aborting Transmission****").} @@ -357,14 +365,14 @@ function TransmitAllScience { if Verbose {print (" Not enough charge.").} set IsCharging to CheckCharging(). //add 0.005 or to make sure the Charge time gets the ship charged slightly above the ReserveCharge - set ChargeTime to CalcChargeTime((DataSize * ChargePerMit) + (ChargeCapacity * (ReserveCharge + 0.005)) - Charge). + set ChargeTime to CalcChargeTime((DataSize * ChargePerMit) + (ChargeCapacity * ReserveCharge) - Charge). if Verbose {print " Charging time is " + round(ChargeTime,1) + " seconds".} // //wait until there is enough charge, exit function if not charging until Charge > ((ChargePerMit * DataSize) + ChargeCapacity * ReserveCharge) or not (IsCharging) { WarpTo(time:seconds + ChargeTime). - wait ChargeTime + 1. - set ChargeTime to CalcChargeTime((DataSize * ChargePerMit) + (ChargeCapacity * (ReserveCharge + 0.005)) - Charge). + wait ChargeTime. + set ChargeTime to CalcChargeTime((DataSize * ChargePerMit) + (ChargeCapacity * ReserveCharge) - Charge + 1). set IsCharging to CheckCharging(). set Charge to ship:electriccharge. }