class KerbalDyn::OrbitalManeuver::Base

The base-class for all orbital maneuvers.

Attributes

final_orbit[RW]

The orbit you are going to maneuver into.

initial_orbit[RW]

The orbit you are starting at.

Public Class Methods

new(initial_orbit, final_orbit, options={}) click to toggle source
# File lib/kerbaldyn/orbital_maneuver/base.rb, line 9
def initialize(initial_orbit, final_orbit, options={})
  # For now this is a safe thing to do, *way* in the future we may have to differentiate
  # between complex maneuvers to other systems and maneuvers within the system.
  raise ArgumentError, "Expected the initial and final orbit to orbit the same body." unless initial_orbit.primary_body == final_orbit.primary_body
  self.initial_orbit = initial_orbit
  self.final_orbit = final_orbit

  process_options(options)
end

Public Instance Methods

burn_events() click to toggle source

Returns the array of burn events.

Subclasses should override this method, as most other values are derived from it.

# File lib/kerbaldyn/orbital_maneuver/base.rb, line 37
def burn_events
  return @burn_events ||= []
end
delta_mean_anomaly() click to toggle source

Calculates the total mean anomaly covered during the maneuver.

# File lib/kerbaldyn/orbital_maneuver/base.rb, line 101
def delta_mean_anomaly
  return self.mean_anomalies.last - self.mean_anomalies.first
end
delta_t() click to toggle source

An alias to delta_time.

# File lib/kerbaldyn/orbital_maneuver/base.rb, line 96
def delta_t
  return self.delta_time
end
delta_time() click to toggle source

Calculates the total time for completion.

For some kinds of idealized maneuvers this may be meaningless, in which case nil is returned.

Subclasses should override this.

# File lib/kerbaldyn/orbital_maneuver/base.rb, line 91
def delta_time
  return self.times.last - self.times.first
end
delta_v()
Alias for: delta_velocity
delta_velocities() click to toggle source

Returns an array of the velocity changes for each burn event.

# File lib/kerbaldyn/orbital_maneuver/base.rb, line 53
def delta_velocities
  return self.burn_events.map {|be| be.delta_velocity}
end
delta_velocity() click to toggle source

Calculates the total delta-v for this maneuver.

This is always a positive quantity that relates the total amount of velocity change necessary, and hence a sense of the total amount of fuel used during the maneuver.

The baseclass implementation is to sum the absolute values of the deltas in the velocity list delta_velocities.

# File lib/kerbaldyn/orbital_maneuver/base.rb, line 80
def delta_velocity
  return self.delta_velocities.reduce(0) {|a,b| a.abs + b.abs}
end
Also aliased as: delta_v
mean_anomalies() click to toggle source

Returns an array of the mean anomaly at each maneuver.

# File lib/kerbaldyn/orbital_maneuver/base.rb, line 68
def  mean_anomalies
  return self.burn_events.map {|be| be.mean_anomaly}
end
mean_lead_angle() click to toggle source

Calculates the mean lead-angle for a given maneuver.

For a target in a higher orbit, this is the mean anomaly ahead of you that the target should be located at.

# File lib/kerbaldyn/orbital_maneuver/base.rb, line 109
def mean_lead_angle
  target_delta_mean_anomaly = self.delta_time * self.final_orbit.mean_angular_velocity
  return self.delta_mean_anomaly - target_delta_mean_anomaly
end
mean_lead_time() click to toggle source

The time elapsed such that–if started when the target is directly radial from you (same true anomaly)–you would start your transfer orbit in order to intercept.

# File lib/kerbaldyn/orbital_maneuver/base.rb, line 117
def mean_lead_time
  # theta_f1 = theta_01 + omega_1*t
  # theta_f2 = theta_02 + omega_2*t
  # theta_f2 - theta_f1 = theta_lead  (After time t, we want to achieve lead angle)
  # theta_02 - theta_01 = 0           (When we start the clock, we want no separation)
  #
  # Thefefore: theta_lead = (omega_2 - omega_1) * t
  #
  # We also have to find the offset (n*2*pi) to the lead angle that will lead to the
  # first positive time.  This depends on wether delta_omega is positive or
  # negative.
  delta_omega = self.final_orbit.mean_angular_velocity - self.initial_orbit.mean_angular_velocity

  two_pi = 2.0*Math::PI
  theta_lead = (self.mean_lead_angle % two_pi)
  theta_lead = (delta_omega>0.0) ? theta_lead : (theta_lead-two_pi)

  return theta_lead / delta_omega
end
moving_to_higher_orbit?() click to toggle source

Returns true if the final orbit has a larger semimajor axis than the initial orbit.

# File lib/kerbaldyn/orbital_maneuver/base.rb, line 43
def moving_to_higher_orbit?
  return final_orbit.semimajor_axis > initial_orbit.semimajor_axis
end
orbital_radii() click to toggle source

Returns an array of the orbital radii for the burn events.

# File lib/kerbaldyn/orbital_maneuver/base.rb, line 63
def orbital_radii
  return self.burn_events.map {|be| be.orbital_radius}
end
orbits() click to toggle source

Returns an array of the orbits, including the initial and final orbit.

Subclasses should override this method.

# File lib/kerbaldyn/orbital_maneuver/base.rb, line 29
def orbits
  return [initial_orbit, final_orbit]
end
relative_anomaly_delta() click to toggle source

For every full cycle of the initial orbit (2pi radians), the final orbit covers either less than 2pi radians (if it is bigger) or more than 2pi radians (if it is smaller) in the same amount of time. The relative_delta_anomaly is the change difference covered.

If it is positive, then the initial orbit is slower, If it is zero, then they are in lock-step, If it is negative, then the initial orbit is faster.

Note that for a large orbit ratio, going from the lower to higher orbit will have a very negative anomaly close to -2pi (the target didn't move much much , while you did your rotation), while going from a higher to lower orbit has a high positive number (the target did a lot of laps while you were waiting for it.

# File lib/kerbaldyn/orbital_maneuver/base.rb, line 151
def relative_anomaly_delta
  initial_orbit_anomaly = 2.0 * Math::PI
  final_orbit_anomaly = 2.0 * Math::PI * (self.initial_orbit.period / self.final_orbit.period)
  return final_orbit_anomaly - initial_orbit_anomaly
end
times() click to toggle source

Returns an array of the effective impulse times of each maneuver.

# File lib/kerbaldyn/orbital_maneuver/base.rb, line 58
def times
  return self.burn_events.map {|be| be.time}
end
velocities() click to toggle source

Returns an array of the before/after burn even velocity pairs for each burn event.

# File lib/kerbaldyn/orbital_maneuver/base.rb, line 48
def velocities
  return self.burn_events.map {|be| [be.initial_velocity, be.final_velocity]}
end