Skip to content

Commit

Permalink
Improved charge calculations in CalcChargeTime and modified TransmitA…
Browse files Browse the repository at this point in the history
…llScience to use the better time to warp.

Signed-off-by: Petruchio96 <44350446+Petruchio96@users.noreply.github.com>
  • Loading branch information
Petruchio96 committed Jan 22, 2019
1 parent 3519ceb commit d0cc047
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down Expand Up @@ -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()
Expand Down
20 changes: 14 additions & 6 deletions Standard_Lib.ks
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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****").}
Expand All @@ -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.
}
Expand Down

0 comments on commit d0cc047

Please sign in to comment.