Class: Orbit::Tle

Inherits:
Object
  • Object
show all
Defined in:
lib/orbit/tle.rb

Constant Summary collapse

FIELD_COLUMNS =

ISS (ZARYA) 1 25544U 98067A 08264.51782528 −.00002182 00000-0 -11606-4 0 2927 2 25544 51.6416 247.4627 0006703 130.5360 325.0288 15.72125391563537

{
  norad_num:       [1, 3,7],
  classification:  [1, 8,8],
  launch_year:     [1, 10,11],
  launch_num:      [1, 12,14],
  launch_piece:    [1, 15,17],
  epoch_year:      [1, 19,20],
  epoch_day:       [1, 21,32],
  mean_motion_dt:  [1, 34,43],
  mean_motion_dt2: [1, 45,52],
  bstar_drag:      [1, 54,61],
  number_zero:     [1, 63,63],
  element_num:     [1, 65,68],
  checksum_1:      [1, 69,69],
  inclination:     [2, 9,16],
  raan:            [2, 18,25],
  eccentricity:    [2, 27,33],
  arg_perigee:     [2, 35,42],
  mean_anomaly:    [2, 44,51],
  mean_motion:     [2, 53,63],
  revolution_num:  [2, 64,68],
  checksum_2:      [2, 69,69]
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(s) ⇒ Tle

Returns a new instance of Tle.



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/orbit/tle.rb', line 52

def initialize( s )
  @tle_string      = s

  # puts @tle_string

  @norad_num       = get_field( :norad_num )
  @classification  = get_field( :classification )
  @launch_year     = get_field( :launch_year )
  @launch_num      = get_field( :launch_num )
  @launch_piece    = get_field( :launch_piece )
  @mean_motion_dt  = get_field( :mean_motion_dt ).to_f
  @mean_motion_dt2 = exp_to_float( "0." + get_field( :mean_motion_dt2 ) ).to_f
  @bstar_drag      = exp_to_float( "0." + get_field( :bstar_drag ) ).to_f
  @element_num     = get_field( :element_num ).to_f
  @inclination     = get_field( :inclination ).to_f
  @raan            = get_field( :raan ).to_f
  @eccentricity    = exp_to_float( "0." + get_field( :eccentricity ) ).to_f
  @arg_perigee     = get_field( :arg_perigee ).to_f
  @mean_anomaly    = get_field( :mean_anomaly ).to_f
  @mean_motion     = get_field( :mean_motion ).to_f
  @revolution_num  = get_field( :revolution_num ).to_f
end

Instance Attribute Details

#arg_perigeeObject

Argument of perigee



15
16
17
# File 'lib/orbit/tle.rb', line 15

def arg_perigee
  @arg_perigee
end

#bstar_dragObject

BSTAR Drag



20
21
22
# File 'lib/orbit/tle.rb', line 20

def bstar_drag
  @bstar_drag
end

#eccentricityObject

Eccentricity



14
15
16
# File 'lib/orbit/tle.rb', line 14

def eccentricity
  @eccentricity
end

#epoch_dayObject

Epoch: Fractional Julian Day of year



10
11
12
# File 'lib/orbit/tle.rb', line 10

def epoch_day
  @epoch_day
end

#epoch_yearObject

Epoch: Last two digits of year



9
10
11
# File 'lib/orbit/tle.rb', line 9

def epoch_year
  @epoch_year
end

#inclinationObject

Inclination



12
13
14
# File 'lib/orbit/tle.rb', line 12

def inclination
  @inclination
end

#intl_descObject

Returns the value of attribute intl_desc.



7
8
9
# File 'lib/orbit/tle.rb', line 7

def intl_desc
  @intl_desc
end

#mean_anomalyObject

Mean anomaly



16
17
18
# File 'lib/orbit/tle.rb', line 16

def mean_anomaly
  @mean_anomaly
end

#mean_motionObject

Mean motion



17
18
19
# File 'lib/orbit/tle.rb', line 17

def mean_motion
  @mean_motion
end

#mean_motion_dtObject

First time derivative of mean motion



18
19
20
# File 'lib/orbit/tle.rb', line 18

def mean_motion_dt
  @mean_motion_dt
end

#mean_motion_dt2Object

Second time derivative of mean motion



19
20
21
# File 'lib/orbit/tle.rb', line 19

def mean_motion_dt2
  @mean_motion_dt2
end

#norad_numObject

Returns the value of attribute norad_num.



6
7
8
# File 'lib/orbit/tle.rb', line 6

def norad_num
  @norad_num
end

#orbit_at_epochObject

Orbit at epoch



11
12
13
# File 'lib/orbit/tle.rb', line 11

def orbit_at_epoch
  @orbit_at_epoch
end

#raanObject

R.A. ascending node



13
14
15
# File 'lib/orbit/tle.rb', line 13

def raan
  @raan
end

#set_numberObject

TLE set number



8
9
10
# File 'lib/orbit/tle.rb', line 8

def set_number
  @set_number
end

#tle_stringObject

Returns the value of attribute tle_string.



5
6
7
# File 'lib/orbit/tle.rb', line 5

def tle_string
  @tle_string
end

Instance Method Details

#epochObject



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/orbit/tle.rb', line 105

def epoch
  epoch_year     = get_field( :epoch_year ).to_f
  epoch_day      = get_field( :epoch_day ).to_f

  epoch_year = epoch_year < 57 ? ( epoch_year + 2000 ) : ( epoch_year + 1900 )

  epoch = Time.at( Time.utc( epoch_year ).to_i + ( ( epoch_day - 1 ) * OrbitGlobals::SEC_PER_DAY ) )

  epoch = epoch.utc

  # puts "epoch_year: #{epoch_year}"
  # puts "epoch_day: #{epoch_day}"
  # puts "epoch: #{epoch}"

  epoch
end

#exp_to_float(exp) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/orbit/tle.rb', line 75

def exp_to_float( exp )
  # puts "exp: #{exp}"
  parts = exp.split( "-" )
  exp_part = -0.1

  if parts.count < 2
    parts = exp.split( " " )
    exp_part = 0.1
  end

  float = parts[0].to_f * ( exp_part ** parts[1].to_f )
end

#get_field(field) ⇒ Object



88
89
90
91
92
93
94
95
96
# File 'lib/orbit/tle.rb', line 88

def get_field( field )
  lines = @tle_string.split( "\n" )

  line_num        = FIELD_COLUMNS[field][0]
  substring_start = FIELD_COLUMNS[field][1] - 1 # Convert to zero-base
  substring_end   = FIELD_COLUMNS[field][2] - 1 # Convert to zero-base

  lines[line_num][substring_start..substring_end].strip
end

#to_sObject



98
99
100
101
102
103
# File 'lib/orbit/tle.rb', line 98

def to_s
  hash = {}
  instance_variables.each {|var| hash[var.to_s.delete("@")] = instance_variable_get(var) }

  hash.to_s
end